The most common way by far is using an array to represent the map. For
example as follows:
byte map[64][64]; A 64x64 map, you will now use an enum so that the
map represents different things
So
0-63 = Nothing (Different numbers represent different graphical looks)
63-127 = Wall (differnet numbers for different wall looks)
128-195 = Water ("")
196-255 = Other
Then you load a map from file and render appropriately
If a player wants to move to a block you first check that the block
falls into the Nothing category like this
bool CanMove(x,y) { return (map[x][y] < 64 ?); };
And then a different map/mask is used for the units like this
byte unit[64][64]; This is not commonly used and is overkill but it can
be done this way...
The better way to do the units is like this
CUnit
{
int x,y; // indexes into the array
int unitType;
}
you can also look at what I have done in perl:
It would be intersting if you could take the time to comment.
Personally I think you seem to over complicate the problem(solution),
this is very evident by single .cpp files that are only 20 lines long.
Yes they are labelled logically and nicely but OO is not always the
best/fastest solution.
Otherwise it all looks fine, here is how I would do the units if i was
you.
class CUnit
{
int x,y;
byte type;
int color;
// Functoins
void Think();
void Calc();
void Draw();
void Destroy();
}
list<CUnit> units;
function CreateUnit(x,y)
{
units.push_front();
*units.begin()->x = x;
....
}
// Draw units
units->doeach(Think);
units->doeach(Calc);
units->doeach(Draw);
Why are you using win32 for your graphical rendering??
Really your source code would look cleaner and better if you abstract
the mechanics of the game from the rendering. Further using OpenGL is
actually really easy. Infact if you want I have a very very good
framework you can use, you can then immediately display quads with
textures on and stuff.
I have to get a basic open GL book. I know there are on-line tutorials
but I don't like printing out ro reading the information from the
screen it is worth the cost of a book. I have a realy good c++ game
book that has taught me a great deal.
What went through my mind when I wrote the program is that I want my
player on the map able to access the objects in the space. My problem
dealt with picking up and dropping objects in a specific space. I
wrote a program that was different but it was a pain writing all those
functions moving the equipment from the space to maze to the player and
back. I wanted the player and objects in the same space object. I
realize that a map game is a bit different.
I don't realy care about graphics. That is not my consern I bitmapped
out those graphics and as long as they are meaningful they serve my
purpose. My real challenge is to create useful and interactive dialog
boxes. I still have a great deal of work to do on the full game
system.