I'm trying to think of a way to manage tiles in my game, so far I have a Tile
class that has characteristics about the tile in question, a TileDictionary
class to keep a list of tiles to use, and the map is simply just a Tile[,]
array.
class Tile
{
public Texture2D graphic;
string name;
bool walkable;
public Tile()
{
name = "Dirt";
graphic = null;
walkable = true;
}
public Tile(string _name, Texture2D _graphic, Boolean _walkable)
{
name = _name;
graphic = _graphic;
walkable = _walkable;
}
static class TileDictionary
{
public static Tile DIRT_TILE = new Tile("Dirt",null,true);
public static Tile STONE_TILE = new Tile("Stone", null, true);
public static Tile CLAY_TILE = new Tile("Clay", null, true);
public static void LoadTileGraphics(ContentManager content)
{
DIRT_TILE.setGraphic(content.Load<Texture2D>("tiles/dirt"));
STONE_TILE.setGraphic(content.Load<Texture2D>("tiles/stone"));
CLAY_TILE.setGraphic(content.Load<Texture2D>("tiles/clay"));
}
Is this a good method? I see games like Minecraft using static Block
instances to reference their blocks, but knowing that it was previously all magic numbers, I feel like this system was just a band-aid over the old system. Obviously all tiles would be loaded via the TileDictionary
, but I am confused on how using this method would handle implementing and using more complex blocks that have functions tied to them or anything.