Jump to content
  • Advertisement
Sign in to follow this  
Static290

Allegro help

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

hey, i was going to create a collapse clone, if you dont know what collapse is http://www.terragame.com/Collapse/1.jpg its something like tetris but i need some advice from you guys on how to implement this i was thinking,make the different blocks in an image editing program and export. creating an array of a specific size, and filling it with random block images. example with array (using allegro by he way)


BITMAP* blockImage;

BITMAP* blockArray[100][100];

for ( int i = 0; i < 100; i++ }
{
   for ( int j = 0; j < 100; j++
   {
         /*load a random bitmap into each array element. for simplicities sake, im just gonna use one image for now, so load one bitmap into each of these elements*/

        blockImage = load_bitmap("blockImage.bmp"),NULL);
   }
}


there...a 100 x 100 array with a bitmap file in each block. and to print it to the screen, just blit(blockArray[j],buffer,0,0,0,0,1024,768 i'd have no idea how to position it right, i dunno, i may be wrong, and i might have the completely wrong idea of going about this. are there any tutorials on collapse clone? [Edited by - Static290 on July 27, 2007 2:40:48 AM]

Share this post


Link to post
Share on other sites
Advertisement
A 100x100 would obviously be 10,000 cells. I assume you don't intend to have 10,000 different blocks, but only a handful.

With this in mind, you certainly don't want to load a seperate copy of each bitmap for each block.

I'd suggest you load a single copy of each bitmap into an array of BITMAP*s, (or a std::vector<>).

Then each of the cells in your 100x100 map can just be an int containing an index into the array. I'll do this with arrays instead of std::vector<> in case you are not familiar with the STL and it muddies my point.


BITMAP *Bitmaps[MAX];
int block_array[100][100];

void load()
{
Bitmaps[0]=load_bitmap("0.bmp",NULL);
Bitmaps[1]=load_bitmap("1.bmp",NULL);
Bitmaps[2]=load_bitmap("2.bmp",NULL);

for(int y=0;y<100;++y) for(int x=0;x<100;++x) block_array[x][y]=std::rand()%3;
}


Then as you draw each cell, you can just do sort of (forgive my Allegro ignorance):


void draw()
{
for(int y=0;y<100;++y)
{
for(int x=0;x<100;++x)
{
blit(Bitmaps[blockArray[x][y]],buffer, /* etc */);
}
}
}


Clearly there needs to be error handling added to check for failed bitmap loads, and out-of-bounds indexing on the Bitmaps array.

Share this post


Link to post
Share on other sites
While this is sort of a generic problem, it seems like it would be helpful to have someone who knows Allegro around, so I'm moving this over to the Alternative Game Libraries forum.

Share this post


Link to post
Share on other sites
On your Screenshot the playscreen is 12 blocks wide and about 16 blocks high.

Then lets say the block images are 32*32 pixels.


const BLOCKSIZE_X=32;
const BLOCKSIZE_Y=32;
int blockArray[12][16]; //the Array representing our playscreen.
//1 = Green Block
//2 = Blue
//3 = Red
//add the Blockarray[] init that EasilyConfused explained.




To draw the Blocks on the right position we just need to multiply the position by the block size


void draw()
{
for(int y=0;y<16;++y)
{
for(int x=0;x<12;++x)
{
blit(Bitmaps[blockArray[x][y]],buffer, 0, 0, x*BLOCKSIZE_X, y*BLOCKSIZE_Y, BLOCKSIZE_X, BLOCKSIZE_Y);
}
}
}






edit: wrong code tags

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!