What is the best way to work with map data?

Started by
1 comment, last by arrow62 24 years, 3 months ago
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.
Advertisement
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[20][13]

Based on that, I created this structure:

struct MAP_TILE
{
base_tile[20][13];
fringe_tile[20][13];
obj_tile[20][13];
}

The main map was then created like this:

MAP_TILE LevelMap[20][13];

To access a particular tile layer (for example, on screen 13, 2) in the map array, I did it like this:

LevelMap[12][1].base_tile[20][13];

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.

- Fuge
(jonathan_morris@hotmail.com)


Oh! One thing I just noticed. I listed the initialization of the MAP_TILE array as
LevelMap[20][13]

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 [20][13]. In all truth, your game may do the arrays sizes quite different, but the OOP approach remains the same.

This topic is closed to new replies.

Advertisement