I am creating a strategy game in LibGDX with a tile system and destructible tiles. I am using an array of enums to represent the different types of tile, eg:

public enum TileType {AIR, DIRT, STONE, etc.};

and then:

private final TileType[] tiles = new TileType[maxTiles];

to get a tile 4 across and 2 down i can just use:

targetTile = tiles[2 * mapWidth + 4];

This works really well for everything; its quick due to locality of reference etc.

Except... I don't know how to integrate meta-data into the tiles -- for example, if I have a tile called "FACTORY" that is supposed to create units that can then go out to fight. Since enums can only have global data, "FACTORY" can't store stuff like a factory's health or how far it is through constructing a unit, etc.

For entities, I am currently using their on individual handlers, eg:

public class Soldiers {
    float[] x; float[] y; float[] health; // etc. (using arrays for DOP)

But soldiers arent tiles -- they are their own thing (they move separate from the grid and have very little impact on the tiles around them so it makes sense to have them not be a part of the tile system)

I tried to have:

public class Factories {
    float[] health; float[] constructionWorkDone; // etc. (using arrays for DOP)

Except now I am kinda defining the 'factory' entity in two places, once by having a tile called: "FACTORY', and secondly in Factories. Additionally, the enum TileType currently stores a block's health. I am using a chance destruction system on blocks. Instead of having every tile use a health limit, there is simply a probability that a will be destroyed by a projectile (which can be scaled based on the projectile's damage). But if a FACTORY tile is destroyed, it won't have any way of telling its "class Factories" meta data that it is destroyed.

"Just use class Factories," I hear you saying, except my A* path finding algorithm uses the tile array to navigate and it would be cool for units to avoid certain buildings, etc. Additionally, I looked a little into Minecraft's design and (I might be wrong, but) it has both a "chest" voxel while the chest metadata is stored elsewhere. (This needs citation though)

Is there a simple way through?


1 Answer 1


Use other arrays for building type (e.g. "factory") and building id. Or use a structure that holds them along the tile type.

Then, each tile will have a tile type, a building type and a building id. You can either have a "building" tile type, and only use the other two values when that is the tile type. Or you can allow building on any tile type, for which you will need a "no building" building type.

So you can use the building type to know where to look, and the building id to index it. And that is how you can find the information about the building that is on the type.

Just in case, I'll also mention that these buildings won't store their position. It is responsibility of the tiles to give them position. Thus, your path-finding algorithm does not need to query the the structure with the information about the buildings to know where they are, instead they look at the tile to know if there is a building there.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .