|
Arrays of A5 bitmaps? |
Chris Katko
Member #1,881
January 2002
|
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] 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: |
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. -- |
Chris Katko
Member #1,881
January 2002
|
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. -----sig: |
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 --- Kris Asick (Gemini) |
Chris Katko
Member #1,881
January 2002
|
Kris Asick said: "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: 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 I like that you qualify them, though, I definitely have different tastes. z, zz, and zzz, would make my brain melt. -----sig: |
|