I'm currently developing a game with a 2D tiled map, similart to the 2D Final Fantasy games and their ilk. I plan on handling tiled maps through instances of a Map class.
Here's a very simple overview of how I plan to handle the Map class:
private Image tileSet = null;
So each Map class has its own tileSet PNG and a 2D matrix of Images that serve as tiles for the map.
I plan to use five 2D integer matrices to handle collision, event activation, and draw order:
- The solidTiles matrix is filled with 1s and 0s, where a 1 is a solid tile
- The eventTiles matrix is filled with 0s, 1s, 2s, and 3s, where 0 is a tile with no attached event, 1 is a tile that activates an event upon entering the tile, 2 is a tile that activates an event when the player "interacts" with the tile, and 3 is a tile that has both "enter" and "interact" events.
- The map____Layer matrices will be filled with integers that each correspond to an entry in the tiles Image matrix. The draw hierarchy is mapGroundLayer<mapWallLayer<entities on screen such as NPCs and the player<mapOverheadLayer
Now we get to my actual question: how should I store these matrices? I'd rather not define a subclass of Map for every single map in my game; the only reasonable alternative I see is a text file, but that could get very cumbersome very fast, especially if I have maps with hundreds of tiles.
So! If you have suggestions, let me hear them! And if you think my way of handling maps is ass-backwards for some reason, then tell me that, too! I've never tried to make a game before, and I'm quite sure that my inexperience shows.
[Edited to explain the map____Layer matrices a bit better.]
[Edit 2: Obviously my Map class will have more variables/methods than what I put here; I just showed these because they're relevant to my question.]