Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Tile based game help

This thread is locked; no one can reply to it. rss feed Print
Tile based game help
Fishcake
Member #8,704
June 2007
avatar

im new in c++ programming and i just finished making a tic-tac-toe game with AI.
so i decided to start with tile based game, and found a tutorial :

http://agdn.netfirms.com/main/html/tut_2.htm

but i dont understand the load map part. what does map.cell contains?

23yrold3yrold
Member #1,134
March 2001
avatar

Right near the beginning of the code:

   #define GRID_WIDTH      15
   #define GRID_HEIGHT     15

   typedef struct WORLD
   {
      unsigned short cell[GRID_WIDTH][GRID_HEIGHT];
   } WORLD;

   WORLD map;

So map.cell is a 15x15 array of numbers. After loading it contains the ID number of each tile of the map.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Fishcake
Member #8,704
June 2007
avatar

ok, i understand that part, thanks ;D now i found these at http://awiki.tomasu.org/AllegroTileMaps

1struct map
2{
3 struct layer *data;
4 int total_layers;
5};
6 
7struct layer
8{
9 int x,y; // where to start drawing this layer (this should be relative to the map's x and y)
10 struct tile *data;
11 int w,h; // in our game different layers can have different sizes and different tile spacing.
12 int tile_spacing_w,tile_spacing_h;
13};
14 
15struct tile
16{
17 BITMAP *pict;
18 int flags;
19 int trans;
20};

can anyone write a simple code using these? a complete code that just draw 20x15 map loaded from a text file (no other stuff like scrolling, movement, etc..), with 2 different tiles and 2 layers. none of the tutorials i read actually helped me, so maybe i can understand it by this way. i don't think its too much for you guys, or is it?

DanielH
Member #934
January 2001
avatar

They didn't help or you didn't read them?

What you need is really simple. You should take the time to think about it. But ...

1st. What size map would you like?
2nd. How much of that map are you showing at one time?
3rd. How may layers do you need?

As to your question about load map. Each cell contains an integer value of the tile in the datafile.

From drawmap
p = map.cell[ j ][ i ];

There are 256 tiles. p is from 0 to 255.

I'd explain this more, but do a damn search on these forums. I've explained this more than once before.

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

i don't think its too much for you guys, or is it?

Well, that was rude. ::)

Quote:

none of the tutorials i read actually helped me, so maybe i can understand it by this way

You posted links to two excellent Allegro tilemap tutorials that have everything you need to know to do what you asked; you'd better learn to understand it this way or you're not going to learn much else without forum begging. It's giving a man a a fish vs. teaching a man to fish; sorry. Take an honest shot at it yourself, and post your work if you have trouble getting it to work.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Fishcake
Member #8,704
June 2007
avatar

23yrold3yrold:

oops, sorry. didn't mean to be rude :-X
i think i need a bit more time on this. maybe i just stick with simple tile based without all the classes and structs, because i just can't understand how to use them :(

thanks for answering!

DanielH:

i think its too early for me to mess with tile based engine. i dont understand the class and struct part. can't figure out how to actually use them.

yea, about the load map, i got it already. and i did do a damn search on the forum for the past 3 days. and yes, i found it ;D

Go to: