For a while I've been working on a 2d tile based side scroller (Think Terraria).
I've spend a little week now reading up on game design in general, which ended up with me questioning my current methods.
Currently my world is an array of a class I call "Tile". Tile contains a lot of information, like type, collision information, and information about whether gravity affect it, and so on. My concern is, that I am wasting a lot of memory this way?
Now I have a few solutions in mind, but I can't decide which one would be the best, or if I even need to change anything at all.
The first one would be to simply have an array of integers where each number represents a certain tile type. My concern with this method is that for every cycle I will spend a lot of cpu power instead, since I will need to do hundreds of switch cases every cycle, to determine the behavior, and what to draw everytime a number is encountered in the array.
My second solution would be a more object oriented approach, by creating a base class for the tiles, and each tile type then inherrits from that class. This way only the tiles that require special variables and methods, will get those, wile the more simple tiles will require much less memory.
If the second solution is the better one, is it then viable to check for the tile type simply by using the is statement.
An example:
if(world[x,y] is DirtTile)
{
//Draw DirtTile (or whatever )
}
Is that a wrong way of doing it? Or should I keep some kind of identifier in the class? - Currently I have an enumerator that holds the tile type.
Thank you for reading, and I look forward to any input