Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Arrays of A5 bitmaps?

This thread is locked; no one can reply to it. rss feed Print
Arrays of A5 bitmaps?
Chris Katko
Member #1,881
January 2002
avatar

For some reason, I'm currently trying to track down, using my allegro bitmaps work fine until I try to turn them into multidimensional arrays.

ALLEGRO_BITMAP *buffer; //works
ALLEGRO_BITMAP *buffer[4][4]; //isn't null, but blows up attempting to draw anything past [0][0]

Actual code, only difference being the array locations:

al_draw_rotated_bitmap(ship_pretty_buffer[i][j],  
          (((internal_width /2))*32)+32+4, 
          (((internal_height/2))*32)+32+8, 
          x - offset_x, 
          y - offset_y, 
          angle, 0);

The crazy part is [0][0] works fine, but [0][1] doesn't, even though I have a loop going from [i=0:4][j=0:4]

#SelectExpand
1for(int i = 0; i < MAP_PARTITIONS-1; i++) 2 for(int j = 0; i < MAP_PARTITIONS-1; i++) 3 { 4 ship_buffer [i][j] = al_create_bitmap(1024, 1024); 5 ship_sprite_buffer[i][j] = al_create_bitmap(1024, 1024); 6 ship_fire_buffer [i][j] = al_create_bitmap(1024, 1024); 7 ship_oxygen_buffer[i][j] = al_create_bitmap(1024, 1024); 8 ship_pretty_buffer[i][j] = al_load_bitmap("./ship2.png"); 9 10 if(ship_buffer[i][j] == NULL || ship_sprite_buffer[i][j] == NULL || 11 ship_fire_buffer[i][j] == NULL || ship_oxygen_buffer[i][j] == NULL || 12 ship_sprite_buffer[i][j] == NULL) 13 { 14 global_fatal_error = 1; // Never flagged, indicating success. 15 }

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Elias
Member #358
May 2000

Quote:

for(int j = 0; i < MAP_PARTITIONS-1; i++)

Are you sure you want i two times there and not j? Also that -1 is suspicious.

--
"Either help out or stop whining" - Evert

Chris Katko
Member #1,881
January 2002
avatar

The -1 was added after it blew up. I KNEW THE ARRAY had to be blowing up some how. Thank you. It's too early to be programming. :o

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Kris Asick
Member #1,424
July 2001

That i/j thing with your for loop was the first thing I spotted looking at the code, but then I also thought, "Aren't i and j a little too similar looking to be using them reliably for something like this?"

Me personally, when I need to loop stuff, I either use x and y, or z, zz, zzz, and zzzz. My method of using single-letter variables is as follows:

c = Temporary single character that I only need briefly
f = Temporary floating point value that I only need briefly
j, jj, jjj, jjjj = Random Numbers
v = Temporary integer value that I only need briefly
x, y = Temporary or looped coordinates
z, zz, zzz, zzzz = Loop iterations

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Chris Katko
Member #1,881
January 2002
avatar

"Aren't i and j a little too similar looking to be using them reliably for something like this?"

It also means I'm moving too fast and need to calm down, and catch my breathe.

I tend to use i and j to denote iterations where as x and y, are positional. Additionally, i and j always denote something with a very short scope. For example, look at this little slice of hell:

#SelectExpand
1 2 for(int i = 0; i < map_partitions_used_x; i++) 3 for(int j = 0; j < map_partitions_used_y; j++) 4 { 5 6 // If a partition is outside the viewport, don't draw it! 7 if(x - (internal_width /2*32) - offset_x > window.width)continue; 8 if(y - (internal_height/2*32) - offset_y > window.height)continue; 9 if(x - (internal_width /2*32) - offset_x + MAP_PARTITION_SIZE_PX < 0)continue; 10 if(y - (internal_height/2*32) - offset_y + MAP_PARTITION_SIZE_PX < 0)continue; 11 12 cout << "i/j" << i << " " << j << endl; 13 14 // NOTICE THE SHIPS ARE DRAWN CENTERED ABOUT THE X/Y 15 al_draw_bitmap(ship_pretty_buffer[i][j], 16 x - (internal_width/2*32 ) - offset_x + i*MAP_PARTITION_SIZE_PX, 17 y - (internal_height/2*32) - offset_y + j*MAP_PARTITION_SIZE_PX, 0); 18 19 al_draw_bitmap(ship_buffer[i][j], 20 x - (internal_width/2*32 ) - offset_x + i*MAP_PARTITION_SIZE_PX, 21 y - (internal_height/2*32) - offset_y + j*MAP_PARTITION_SIZE_PX, 0);

The variable names are fairly informative. I'm trying to get into the habit of [variable_name]_til being tiles, and [variable_name]_px being pixel coordinate systems.

I'm having to break out the pen and paper for this slice because I have ship position (width/height/x/y), viewport position (with width/height/x_offset/y_offset), the ship's are centered about the x/y so subtract half the width and height, and then, let's kill ourselves by partitioning each ship into 5 by 5 bitmaps so that culling can occur across those boundaries and we can neglect entire sections from the drawing process. Window width/height also comes into play at specific places because I can technically have multiple viewports for possible local multiplayer.

Quote:

c = Temporary single character that I only need briefly
f = Temporary floating point value that I only need briefly
j, jj, jjj, jjjj = Random Numbers
v = Temporary integer value that I only need briefly
x, y = Temporary or looped coordinates
z, zz, zzz, zzzz = Loop iterations

I like that you qualify them, though, I definitely have different tastes. z, zz, and zzz, would make my brain melt.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: