I've got another little dilemma for you. I'm wondering what the best way is to implement this kind of level map for a game in C++ is. The map is supposed to be a regular 2D grid of. What I have is something similar to this:
enum TileType { // not an enum in the current code though but should be changed to one
...
};
class LevelTile {
private:
TileType tileType;
... (various flags and settings in here) ...
public:
...
};
class LevelMap {
private:
...
std::vector< std::vector< LevelTile > > mapTiles;
...
public:
...
};
The trick part is representing the different types of tiles. Here, I have the tiles referred to by a type-field. But then we need a bunch of switch statements to give different tile behaviors based on different types of tiles. Would it be better to use multiple types of LevelTile (i.e. derived classes)? But then comes the questions of:
1. we need to then store an array of pointers,
2. we need to allocate on the heap with new (and that takes more time, doesn't it, than just updating a type field) if we want to change a tile
3. when changing a tile, we need to be able to preserve its flags, which means we need some kind of "copyFlags()" function or something in LevelTile that would need to be called when doing such a change and so would complicate setting one tile to that of another type, or have conversion code for each kind of tile
Though these may not be insurmountable problems (e.g. in issue 3, we could have some kind of "mutateTile()" function in LevelMap that wraps up that calling of copyFlags() etc.). But I'd like to be clear as to which way is the "preferred" way of doing this: multiple types of Tile or type-field.