How to create a map game?

7 views
Skip to first unread message

JoeC

unread,
Aug 8, 2006, 12:34:12 AM8/8/06
to C++ Game Programming
I have written a simple maze game with one player moving on a map. I
would like to create a map and place units on that map as well as
terrain and have each space hold that data and units. What is a good
way to do that? I may have some challenges, I still have some windows
issues to work out like being able to select pieces with the mouse but
I can do graphics dialog boxes and menus as well as other basic windows
programming.

Spy187

unread,
Aug 8, 2006, 1:34:19 PM8/8/06
to C++ Game Programming

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;
}

JoeC

unread,
Aug 8, 2006, 1:39:36 PM8/8/06
to C++ Game Programming

Spy187

unread,
Aug 8, 2006, 1:59:02 PM8/8/06
to C++ Game Programming

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.

JoeC

unread,
Aug 8, 2006, 2:39:46 PM8/8/06
to C++ Game Programming
I am glad you like my work. It was tough. It is just that I have good
win32 resources and have gone that rout. This what I get formal
training or education. I also solve the probles based on the book I
have and read.

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.

JoeC

unread,
Aug 12, 2006, 2:18:18 PM8/12/06
to C++ Game Programming
I am working on my game with the suggestions and advice. I am trying
to create a very simple pro-game and still it is very challening and
daunting. I am taking small steps like I have my graphic object and I
am working on my map, which will use several colors which is also a
challenge.

Spy187

unread,
Aug 14, 2006, 5:40:21 AM8/14/06
to C++ Game Programming
Hey JoeC this google groups thing is nice but the community is too
small. Rather try posting your posts on gamedev.net . I guarantee you
will get atleast 10 responses.

Reply all
Reply to author
Forward
0 new messages