Jump to content
  • Advertisement
Sign in to follow this  
kelcharge

Tile Map Engine troubles(Allegro)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I started making my tile map engine, but I hit a rut. I make a class called a texture and load the file on to a new bitmap. I was wondering, how across multiple classes do I make a map.
class CTexture {
   const char* filename;
   BITMAP *image;
   pulbic:
   CTexture() { }
   CTexture(filename) {
      image = load_bitmap(filename);
   }
   ~CTexture() { }
}

class CTileSet {
   BITMAP *tiles[32]; //or specified amount
   //this is where my thinking falls apart

I think that my thinking is all wrong, and I am very confused. Any help would be much appreciated and would help me sleep at night. :(

Share this post


Link to post
Share on other sites
Advertisement
You need an array of CTextures (tiles). But what you could also do is create only a tileset class and load all tiles for that as one image. Then show part of the image (=one tile) with a member function Draw_Tile or something like that.

Share this post


Link to post
Share on other sites
I am building a Tile Handler myself. I think it is definetly the best decision to just have one class to do it all. The way I do it is that I have an array of images that store all my tiles. And then I have an int array that has just a bunch of different numbers in it that each correspond to a tile. I have a separate private buffer that is big enough to hold the whole map. I just draw all the tiles to that buffer in the right order. Then I have a public memeber function called drawMap or something that just blits a certain part of the buffer to the screen. I'm not sure if thats how you would do it. I am using my tile handler to create a side scroller so it might be a little different for you. But I think this approach does pretty a pretty good job for the most part. This is what my class defintion looks like:



class Block
{
public:
bool checkForCollisions;
bool trigger;
int triggerType;

int imgNum;
};

class AnimBlock : public Block
{
public:
int startFrame;
int animLength;
int curFrame;

int frameDelay;
int frameCount;
};

class TileHandler
{
public:
void loadMap(char *filename, SDL_Surface *screen);

void drawTiles(SDL_Surface *dest, int x, int y);
void updateAnims();

int getBlockWidth();
int getBlockHeight();
int getBlockRow(int y);
int getBlockCol(int x);
int getMapWidthInBlocks();
int getMapWidthInPixels();
int getMapHeightInBlocks();
int getMapHeightInPixels();

/* returns true if the pixel point (x,y) is
* inside a block with collision detection
*/

bool collision(int x, int y);

//changes the block at the pixel point (x,y) to a new block
void changeBlock(int x, int y, int newBlockNumber);

//looks at the block by pixels
bool blockIsAnimated(int x, int y);
private:
//grabs a sub bitmap
SDL_Surface *grabFrame(SDL_Surface *src, int bpp, int w, int h, int startX, int startY, int columns, int frame);
//sets up a blank surface
SDL_Surface *createSurface(int width, int height, int bpp);
void loadImages(char *filename, SDL_Surface *screen);

void errorMessage(char *text);
bool getBoolean(string text);

void setupTileBuffer(SDL_Surface *screen);

int **mapArray; //array of ints
SDL_Surface **imgArray; //image array

//a big surface that contains all the tiles in the right order
SDL_Surface *tileMapBuffer;

Block *blocks; //array of blocks (1 for each tile image)
AnimBlock *animBlocks; //array of animated blocks

int mapPixelWidth, mapPixelHeight;
int mapBlockWidth, mapBlockHeight;
int blockWidth, blockHeight;

int blockCount, animBlockCount;
};




As you probably can see my Tile Handler is for SDL but I've worked with Allegro and you should be able to use this framework in that as well if it suits you.

Share this post


Link to post
Share on other sites
Yes, I agree that would be a way of doing it, and I have thought to do it that way. I have also done it that way before. But, for the versatility that I want in my tile engine, it doesn't exactly fit. I would want the engine to do more of the work for me. Your help has been noticed. rating++

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!