Original Post
Hi
I''m wondering if anyone could enlighten me of a good way to store a Map of a tile based game and the graphic for the tiles?
The most basic way I can think of is having two arrays:
byte Map[maxX][maxY];
Bitmap Tiles[MaxTileTypes];
Then you could draw a tile by doing something like this (Pseudo C/Java/Pascal code):
void drawTile(x,y) {
TileType = Map[x,y]; // get type of tile from map
Bmp = Tiles[tiletype]; // get tile bitmap from an array
drawBitmap(bmp,x,y) // draw bitmap on screen
}
Both the Map and the Tiles array could easily be created in some editor and loaded on game start. Also this concept could be expanded to provide multi-layered maps by making the map array an array of linked lists or something. This gives a little more flexibility.
But all this arrays and hard-coded constants is bugging me! What if I wanted to add or remove some tiles from my tile library (the ''Tiles'' array)? This would possibly alter the order of the tiles in the tile array and then force me to redo all previously saved levels because they will be totally ruined???
There must be a better way!
Regards
nicba