Archived

This topic is now archived and is closed to further replies.

the same old tiling question :p

This topic is 5016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I''m making RPG 2D, with c++ and allegro, but I couldn''t get my tiling engine working, so I started everything again, and now I first want to ask help before starting.. blah.. and yes, I have tried to search with google, and I have read many topics here, but would anybody have a little piece of code of tiling with allegro and loading the tiles from the tiles.dat? I don''t use animations so I have only 4 pictures of the character, (up down left right, if it is too hard to quess ) and my other tiles are 32x32 and they are in tiles.bmp(160x32)

Share on other sites
You''re not offering us much info here. "tiles.dat" could be anything. A list of RECTs storing the coordinates of the tile to draw, a list of tile IDs...

I''ve never used Allegro. That''s a graphic API for DOS-based games... isn''t it? In any event, getting the tiles on the screen doesn''t appear to be where you''re having difficulties. Loading tile data is pretty simple, depending on your format.

For instance, if you have 16x16 tiles (number of tiles, not the size) in your tile.bmp, you could give them all an ID ((16 * Y) + X, assuming 0-15 for the positions; so the tile at (10,10) would be 176, (3,2) would be 34, etc..). Then you''d write the ID of the tile you want to use in the tiles.dat file for every tile on your map (10,10,14,15,15,15,14,10...).

When comes time to code a loader, you''d simply load the contents of the tiles.dat file into an array. Then to render, you''d just loop through every tile you need to display in your array and draw the corresponding tile from the bitmap onto the screen.

That''s a really simply and basic way to do it, but you should be able to get an engine up in no time like that. Then, you should improve on it to have it do whatever your engine needs.

Share on other sites
quote:
Original post by RuneLancer
You''re not offering us much info here. "tiles.dat" could be anything. A list of RECTs storing the coordinates of the tile to draw, a list of tile IDs...
Well, he was asking for instructions/suggestions on how to structure the whole thing as opposed to analyses of his currently futile efforts.

quote:
I''ve never used Allegro. That''s a graphic API for DOS-based games... isn''t it?
No.

@toodles:
How about you structure your tiles.dat file in screen terms? Your tiles are 32x32; let''s work in 640x480 resolution because it gives us nice multiples in both directions. For 640x480, you have 20-tile wide screens, and 15 tiles high. So in your tiles.dat, each line should be 20 characters, and every 15 lines is a complete screen. You''ll want to assign an ASCII character (like ''a'', ''A'', ''#'', etc) to each tile. That way, you can edit your tiles.dat file by hand.

With this information, you have a few benefits: You can skip to any screen number because you know that each screen contains 20 * 15 (= 300) tiles, and each tile is represented by a 1-byte ASCII character, so just fseek 300 * (screen_number - 1) bytes ahead. You can edit your file in Notepad (or any other text editor), fire up the game and see changes immediately, too.

I don''t use Allegro, so I can''t help you with the specific drawing APIs and so forth (try their forums for that), but I can show you the tile loading mechanism. Before I introduce it, let me also share an idea with you: ASCII characters are interpreted as text, but they''re really just integers under the hood. By choosing them carefully, you can skip translating the character to an integer offset in your tile array and use them directly.
#include <fstream>#include <iostream>bool LoadScreen( int screen_number, char * buffer ){  using namespace std;  fstream fin("tiles.dat", ios::binary);  if( fin.fail() )    return false;  fin.seekg( 300 * (screen_number - 1) );  fin.read(buffer, 300 * sizeof(char));  fin.close();  return true;}bool DrawScreen( int screen_number ){  char buffer[20][15];  if( !LoadScreen(screen_number, (char *)buffer) )    return false;  for( int y = 0; y < 15; ++y )  {    for( int x = 0; x < 20; ++x )    {      <allegro_draw_tile_fn>(tiles[buffer[x][y]], 32 * x, 32 * y);    }  }  return true;}

That should give you some good ideas on how to get your technology up and running.

Share on other sites
quote:
Original post by Oluseyi
Well, he was asking for instructions/suggestions on how to structure the whole thing as opposed to analyses of his currently futile efforts.

Quite certain that''s what the both of us provided: instructions and suggestions to getting his tile engine up and running. Hopefully it was helpful and gave him something to start working with.

Share on other sites
Oluseyi: thanks, but there''s something wrong with the code you gave " error C2143: syntax error : missing '';'' before ''<'' " ,but I can''t see anything wrong it there :/

Share on other sites
Don't copy-paste the code directly.

< allegro_draw_tile_function > isn't meant to be taken literally. Replace that (including the < > around it) by whatever is used to draw graphics and adapt the syntax to it accordingly.

[edited by - RuneLancer on March 24, 2004 2:43:16 PM]

Share on other sites
I imagine tiles.dat is a file created with the Allegro Grabber utility. I don't remember exactly how it works. I seem to remember that the grabber writes a header file with the datafile. I seem to remeber it going something like this:

#include "my_datafile.h"...DATAFILE *my_data = load_datafile("my_datafile.dat");BITMAP *my_tile = my_data[MY_TILE].dat;// do whateverunload_datafile(my_data);

In C++ I think you also have to cast it to the correct type, since my_data->dat would be a void pointer.

[edited by - smart_idiot on March 24, 2004 4:58:36 PM]

• Forum Statistics

• Total Topics
628752
• Total Posts
2984509

• 12
• 25
• 12
• 10
• 17