erroroccured
02-07-2007, 06:00 AM
Hi, I have an little problem with allegro (like title says). I am trying to make a letter fall automatically down and so that you can move it. That worked well. But it usually goes off-screen. So, when I tried to fix this, I didn`t succeed.
What is wrong with my code? Here it is:
#include <allegro.h>
#include <time.h>
int x = 10;
int y = 10;
int dir=1;
int main(){
allegro_init();
install_keyboard();
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
while ( !key[KEY_ESC] ){
clear_keybuf();
acquire_screen();
textout_ex( screen, font, " ", x+49, y+49, makecol( 0, 0, 0), makecol( 0, 0, 0) );
if (key[KEY_RIGHT] && x < 420) ++x;
else if (key[KEY_LEFT]&& x > 0) --x;
else if (key[KEY_UP]&& y > 0) ----y;
else
allegro_message("An error has occured");
time_t seconds;
time(&seconds);
if (seconds>=0 && y < 420)
++y;
else
allegro_message ("An error has occured, and program must be quit. Please, inform us of this problem.");
textout_ex( screen, font, "@", x+50, y+50, makecol( 255, 0, 0), makecol( 0, 0, 0) );
release_screen();
acquire_screen();
textout_ex( screen, font, " ", x, y+9, makecol( 0, 0, 0), makecol( 0, 0, 0) );
if (key[KEY_RIGHT] && x < 420) ++x;
else if (key[KEY_LEFT]&& x > 0) --x;
else if (key[KEY_UP]&& y > 0) ----y;
else
allegro_message("An error has occured");
if (seconds>=0 && y < 420)
++y;
else
allegro_message ("An error has occured, and program must be quit. Please, inform us of this problem.");
textout_ex( screen, font, "b", x, y+10, makecol( 255, 0, 0), makecol( 0, 0, 0) );
release_screen();
rest(50);
}
return 0;
}
END_OF_MAIN();
What is wrong with my code? Here it is:
#include <allegro.h>
#include <time.h>
int x = 10;
int y = 10;
int dir=1;
int main(){
allegro_init();
install_keyboard();
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
while ( !key[KEY_ESC] ){
clear_keybuf();
acquire_screen();
textout_ex( screen, font, " ", x+49, y+49, makecol( 0, 0, 0), makecol( 0, 0, 0) );
if (key[KEY_RIGHT] && x < 420) ++x;
else if (key[KEY_LEFT]&& x > 0) --x;
else if (key[KEY_UP]&& y > 0) ----y;
else
allegro_message("An error has occured");
time_t seconds;
time(&seconds);
if (seconds>=0 && y < 420)
++y;
else
allegro_message ("An error has occured, and program must be quit. Please, inform us of this problem.");
textout_ex( screen, font, "@", x+50, y+50, makecol( 255, 0, 0), makecol( 0, 0, 0) );
release_screen();
acquire_screen();
textout_ex( screen, font, " ", x, y+9, makecol( 0, 0, 0), makecol( 0, 0, 0) );
if (key[KEY_RIGHT] && x < 420) ++x;
else if (key[KEY_LEFT]&& x > 0) --x;
else if (key[KEY_UP]&& y > 0) ----y;
else
allegro_message("An error has occured");
if (seconds>=0 && y < 420)
++y;
else
allegro_message ("An error has occured, and program must be quit. Please, inform us of this problem.");
textout_ex( screen, font, "b", x, y+10, makecol( 255, 0, 0), makecol( 0, 0, 0) );
release_screen();
rest(50);
}
return 0;
}
END_OF_MAIN();