I am making a tile based strategy game in C++ and Directx and was wondering what the best way was to work with map data. I have considered just putting the data into arrays but since I will need to store 3-4 layers(base tile, terrain, forest, roads, etc...) as well as resource data and perhaps other things. Is there a more object oriented approach that would still be efficient? I''m curious how others are dealing with this. Any comments would be appreciated.
Here''s a more object-oriented approach that I used on one of my engines. I did end up using arrays, which I found to work quite well. In this particular game I was using 32x32 tiles on a screen of 640x480, so I had a screen array like this: Screen
To access a particular tile layer (for example, on screen 13, 2) in the map array, I did it like this:
That''s mainly it for how I did the actual data storage. Like I said, it may not be the most optimal way of doing this, but it worked just fine for me. If you want more info on how I did it, I''d be happy to show you how.
Oh! One thing I just noticed. I listed the initialization of the MAP_TILE array as LevelMap
I hope that didn''t confuse you. The game I had done was a Zelda-style RPG so only one screen was shown at a time and the scrolling was fron screen to screen. That was why my array was . In all truth, your game may do the arrays sizes quite different, but the OOP approach remains the same.