Wednesday, June 29, 2022
HomeGame Developmentjava - Tile system Meta knowledge

java – Tile system Meta knowledge


I’m creating a method recreation in LibGDX with a tile system and destructible tiles. I’m utilizing an array of enums to characterize the various kinds of tile, eg:

public enum TileType {AIR, DIRT, STONE, and so on.};

after which:

non-public ultimate TileType[] tiles = new TileType[maxTiles];

to get a tile 4 throughout and a pair of down i can simply use:

targetTile = tiles[2 * mapWidth + 4];

This works rather well for every part; its fast as a result of locality of reference and so on.

Besides… I do not know learn how to combine meta-data into the tiles — for instance, if I’ve a tile known as “FACTORY” that’s alleged to create models that may then exit to battle. Since enums can solely have world knowledge, “FACTORY” cannot retailer stuff like a manufacturing unit’s well being or how far it’s by developing a unit, and so on.

For entities, I’m presently utilizing their on particular person handlers, eg:

public class Troopers {
    float[] x; float[] y; float[] well being; // and so on. (utilizing arrays for DOP)
}

However troopers arent tiles — they’re their very own factor (they transfer separate from the grid and have little or no affect on the tiles round them so it is sensible to have them not be part of the tile system)

I attempted to have:

public class Factories {
    float[] well being; float[] constructionWorkDone; // and so on. (utilizing arrays for DOP)
}

Besides now I’m kinda defining the ‘manufacturing unit’ entity in two locations, as soon as by having a tile known as: “FACTORY’, and secondly in Factories. Moreover, the enum TileType presently shops a block’s well being. I’m utilizing an opportunity destruction system on blocks. As a substitute of getting each tile use a well being restrict, there’s merely a likelihood {that a} will probably be destroyed by a projectile (which will be scaled primarily based on the projectile’s harm). But when a FACTORY tile is destroyed, it will not have any manner of telling its “class Factories” meta knowledge that it’s destroyed.

“Simply use class Factories,” I hear you saying, besides my A* path discovering algorithm makes use of the tile array to navigate and it will be cool for models to keep away from sure buildings, and so on.
Moreover, I regarded a little bit into Minecraft’s design and (I may be flawed, however) it has each a “chest” voxel whereas the chest metadata is saved elsewhere. (This wants quotation although)

Is there a easy manner by?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments