Tile based game help

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 :


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


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.


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

1struct map
3 struct layer *data;
4 int total_layers;
7struct layer
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;
15struct tile
17 BITMAP *pict;
18 int flags;
19 int trans;

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?


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.


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

Well, that was rude. ::)


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.



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!


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

Thread #591790. Printed from Allegro.cc