Jump to content
  • Advertisement
Sign in to follow this  
flump9

Tile-Based Map

This topic is 2464 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

Advertisement
The way I've been using for a simple game is as follows:




Create your array.

int Map[5][5] = {
{1, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 1, 1, 1, 1}
};

BITMAP *Graphics[2];

(Load the code for images)

Under your draw function you will need two for loops!

for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
al_draw_bitmap(Graphics[Map[y][x]], x * Tile_Width, y * Tile_Height, 0);
}
}


So pretty much what happens here, is that the Array is checked with X and Y. If the value = 1, or 2 that Graphics[VALUE] will draw. It will then space out each tile to the width and height values set. If you fail to multiply, it will draw 1 pixel from the last one, ect...

Share this post


Link to post
Share on other sites

The way I've been using for a simple game is as follows:




Create your array.

int Map[5][5] = {
{1, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 1, 1, 1, 1}
};

BITMAP *Graphics[2];

(Load the code for images)

Under your draw function you will need two for loops!

for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
al_draw_bitmap(Graphics[Map[y][x]], x * Tile_Width, y * Tile_Height, 0);
}
}


So pretty much what happens here, is that the Array is checked with X and Y. If the value = 1, or 2 that Graphics[VALUE] will draw. It will then space out each tile to the width and height values set. If you fail to multiply, it will draw 1 pixel from the last one, ect...


what allegro are you using,because i'm using 4.2.3.
and when i put it in it doesnt work.

Here is my code:

#include <allegro.h>

int Map[5][5] = {
{1, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 1, 1, 1, 1}
};

BITMAP *Graphics[2];

for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
al_draw_bitmap(Graphics[Map[y][x]], x * Tile_Width, y * Tile_Height, 0);
}
}

int main()
{
allegro_init();
install_keyboard();
install_mouse();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

readkey();
return 0;
}

END_OF_MAIN()



It says
expected unqualified id
expected constructor,destructor or conversion before '<' token
expected constructor,destructor or conversion before '++' token

Share this post


Link to post
Share on other sites
My example was for Allegro 5. If you apply the same principles, it will work.

In Allegro 4 the draw function is:

draw_sprite()

If the code you pasted is your actual program, you're using allegro wrong. You cannot draw to the screen before allegro is initialized. You also did not load any graphics. I would suggest learning how to use the library properly before attempting any projects to limit further confusion.

Your main should look something like this:


int main()
{
Allegro_Setup();

// Load Buffer
Load_Buffer();

// Game Loop
Game_Active = true;

while (Game_Active == true)
{
Input();
Draw();
Check();
}

Destroy();

return 0;
}
END_OF_MAIN()


You want to be drawing the map in your Draw() function.

Share this post


Link to post
Share on other sites

My example was for Allegro 5. If you apply the same principles, it will work.

In Allegro 4 the draw function is:

draw_sprite()

If the code you pasted is your actual program, you're using allegro wrong. You cannot draw to the screen before allegro is initialized. You also did not load any graphics. I would suggest learning how to use the library properly before attempting any projects to limit further confusion.

Your main should look something like this:


int main()
{
Allegro_Setup();

// Load Buffer
Load_Buffer();

// Game Loop
Game_Active = true;

while (Game_Active == true)
{
Input();
Draw();
Check();
}

Destroy();

return 0;
}
END_OF_MAIN()


You want to be drawing the map in your Draw() function.


I tried to upgrade to allegro 5,but i dont know how to with code::blocks,is there any over good ide's?

Share this post


Link to post
Share on other sites
Why not use Visual Studio Express? Unless I'm wrong, you should be able to use Visual C++ 2010 Express fully with Allegro 5.

Download Visual C++ 2010 Express here:

http://www.microsoft...ual-cpp-express

Download the Allegro 5 files here:

http://www.allegro.c...s/thread/608749

You might want to take advantage of Wiki for Allegro 5:

My linkhttp://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial

I hope this helps!

Share this post


Link to post
Share on other sites

Why not use Visual Studio Express? Unless I'm wrong, you should be able to use Visual C++ 2010 Express fully with Allegro 5.

Download Visual C++ 2010 Express here:

http://www.microsoft...ual-cpp-express

Download the Allegro 5 files here:

http://www.allegro.c...s/thread/608749

You might want to take advantage of Wiki for Allegro 5:

My linkhttp://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial

I hope this helps!


Thanks, i downloaded it!

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!