• Advertisement
Sign in to follow this  

Weird looking allegro tile

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by baw
What 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement