Weird looking allegro tile

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

Recommended Posts

with this code: #include <allegro.h> int map[10][18]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},}; void setupgame(){ for(int i=0;i<=10;i++) { for(int t=0;t<=18;t++) { if(map[t]==0)rectfill(screen,i*20,t*20,(i+1)*20,(t+1)*20,makecol(0,255,255)); } } } int main(){ allegro_init(); install_keyboard(); set_color_depth(16); set_gfx_mode( GFX_AUTODETECT, 1024, 768, 0, 0); setupgame(); while( !key[KEY_ESC]){ } return 0; } END_OF_MAIN(); it displays a blue vertical rectangle, but there are some squares that arent filled in that are black, is there a problem with this program?

Share on other sites
Although this may not be what you're referring to, try map[t] instead of map[t]. Look carefully over the ranges you are iterating, and what indices you're using them with.

Share on other sites
tried that, it didnt work, im a total noob at this so i really have no idea.

Share on other sites
What mattd said is correct, the problem is that you have another error in your code:

for(int i=0;i<=10;i++){for(int t=0;t<=18;t++)

should be

for(int i=0;i<10;i++){for(int t=0;t<18;t++)

Right now you're accessing memory that's outside of your array.

Share on other sites
Quote:
 Original post by bawWhat mattd said is correct, the problem is that you have another error in your code:*** Source Snippet Removed ***should be*** Source Snippet Removed ***Right now you're accessing memory that's outside of your array.

thanks, now i get it. It works now

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 11
• 20
• 12
• 13
• 14
• Forum Statistics

• Total Topics
632144
• Total Posts
3004427

×