How do you get the image onto the tilemap?
Use paint? Are you talking about making an image file with tiles, or making a tilemap on the screen with Allegro?
The second I think, whichever will help me make a game that has tiles
Both will.
So, you already have a bitmap that looks like this? This is called your tileset.
You also need a tilemap. That is an array of data that makes up the map. For example, this is a 5x5 tilemap:
int tilemap[5][5] = { { 96, 96, 96, 96, 96 }, { 96, 96, 0, 0, 96 }, { 96, 0, 0, 0, 96 }, { 96, 0, 0, 96, 96 }, { 96, 96, 96, 96, 96 } };
What we are going to do is take the tile (32x32 pixel block) from the tileset that is at the number 96 or 0. 0 is the first tile, 2 is the next tile to the right, 3 is after that, all the way to 15, and 16 is the first tile in the second row. We can figure out this using a formula:
int tile_number = 96; // Set the to the tile number you want BITMAP* tileset; // Set this to the tileset you loaded int tile_size = 32; // Set this to how many pixels big each tile is. int set_x = tile_number % (tileset->w / tile_size); int set_y = tile_number / (tileset->w / tile_size);
Okay, some explanation. If you don't know how the % operator works, it does the same as a divide, but instead of giving you the quotient, it gives you the remained. So, since there are 16 tiles (of size 32) in the tileset I showed you, the % operator will count up to 15, then drop back down to 0. Try it out in your head.
The next line uses the standard divide. Each time the % operator drops down to 0, the tile is on a new row (and at column 0). The divide operator goes up once every 16 tiles (for the tileset that I showed you), so it measures the row number.
Once you have this down, we can put the tiles on the screen:
1 | BITMAP* tileset; |
2 | for(int y = 0; y < 5; y++) |
3 | { |
4 | for(int x = 0; x < 5; x++) |
5 | { |
6 | // Find out what tileset index to use based on the tilemap at the current (x, y) coordinates. |
7 | int set_x = tilemap[y][x] % (tileset->w / tile_size); |
8 | int set_y = tilemap[y][x] / (tileset->w / tile_size); |
9 | // Now put it on the screen. |
10 | // blit(tileset, screen, |
11 | // Blit from the tileset to the screen |
12 | // set_x * tile_size, set_y * tile_size, |
13 | // starting at the pixel coordinates of the desired tile |
14 | // x * tile_size, y * tile_size, |
15 | // put on the screen at the proper place |
16 | // tile_size, tile_size); |
17 | // and put only 1 tile's worth of pixels. |
18 | // To put this all together: |
19 | blit(tileset, screen, set_x * tile_size, set_y * tilesize, x * tile_size, y * tile_size, tile_size, tile_size); |
20 | } |
21 | } |
Once you get this code down (it's a mouthful!), then try and get it to put on a buffer instead, and be able to chose where to start drawing onto the buffer at. After all that, find a way to center the camera on a certain tile. Finally, add smooth scrolling. This is quite a challenge, so feel free to ask for hints. I also recommend you find yourself another tilemap tutorial on the net to help you out some more.
How do you load the tilemap?
This question probably sounds dumb.
Just load it like you load any other bitmap:load_bitmap
OK,
on a different topic,
what goes in a data header file?
what goes in a data header file?
Data?
what I mean is, what are the numbers on the side?
example
#define int STATE_DEAD........1
#define int STATE_CROUCH...2
#define int STATE_JUMP........4
#define int STATE_NORMAL...8
#define int STATE_BIG.........16
So where does the index come in?
see the code in my post?
Yeah, but:
1: There is no where that I can see where the number 1 comes in (the number I used for that in my example).
2: And also aren't the numbers random?
Do you not understand how arrays work?
OK, I get that it's an array now, but why would you need a datafile?
You don't need a datafile.. You can choose to use one if you like.
*sigh*
I mean, if you choose to use one, why would you?
Is it smart to?
*Yeah, I know, I need to learn more Allegro*
*Re-sigh*
Well, a datafile can load all the data faster, its all in one file, and possibly compressed. Then you can access all your data in a consistent way.
1) Where in the datafile is the location of the bitmap
2) Back to the tileset question, that 5 x 5 array, how do you know what numbers to make it?
3) Still with the tileset question, how do you load specific tiles from that one large bitmap that has all the kinds of tiles?
You need to sit down and think about all of those questions, you should be able to come up with solutions of your own.
I just realized 3 has been answered in this thread already, but 1 and 2????
2. You can count. There are 16 tiles across, so the tile in the 5th row down is 16 * 5 + column, and column was 0, so the number is 96.
OK, that makes sense, now number 1?
See Tomasu's post. That excerpt will make a BITMAP* from a bitmap stored in a DATAFILE*.
Ah I see now
Anyone ever tried randomizing the tiles on a tile map already configured, i mean puttin in tiles using rand() function... Sometimes it turns up real good... but only sometimes...
And why dont u read some good tile mapping tutorials, u still need to understand it well to start off with it...
Took a look at the tutorial.
Get yourself a C or C++ book. Stat.
And why dont u read some good tile mapping tutorials, u still need to understand it well to start off with it...
Die.
I have a C++ book!
I have a C++ book!
Read it!
What do you mean? Of course I've read it!
Read it again.
Where has he demonstrated that he needs to re-learn C/C++? The only things he hasn't understood are Allegro structures, which won't be in any book he could read. Please stop being not helpful and critical.
Really, but can we not talk about my C++ ability? Trust me. I know my C++. I just need to learn Allegro better. I know the basics pretty well. (I think)(Maybe not, depending on how much you consider 'basics');D8-);D
Its been quite a time since I checked www.gamedev.net, they had some good tile mapping tuts at some point of time, aint sure now, just check em out if you get a chance...
I don't think there is, but I can't get anywhere on that site. A specific link would be nice, if anyone can?