Code:
int main(){
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
while(!key[KEY_ESC] && n == 0){
while(!key[KEY_ESC] && n == 0){
clear_keybuf();
acquire_screen();
textout_ex(screen, font, " ", x2, y2, makecol( 0, 0, 0), makecol( 0, 0, 0));
if(key[KEY_W]) --y2;
if(key[KEY_S]) ++y2;
if(key[KEY_D]) ++x2;
if(key[KEY_A]) --x2;
textout_ex(screen, font, "<^>", x2, y2, makecol(225,0,0), makecol(0,0,0));
release_screen();
rest(10);
moveCircle();
distant = distance(x2, y2, x, y);
if(distant < 10 ) n = 1;
}
while(!key[KEY_SPACE]){
textout_ex(screen, font, "Good job, you caught the circle! (hit space)", 100,
100, makecol(255, 0, 0), makecol( 0, 0, 0));
}
if(n == 1) {
while(!key[KEY_A]) {
textout_ex(screen, font, "Press 'a' to play again", 100, 100,
makecol(255, 0, 0), makecol( 0, 0, 0));
n = 0;
}
while(!key[KEY_ESC] || !key[KEY_SPACE]) {
textout_ex(screen, font, "Press ESC to exit, or space to play", 100, 100,
makecol(255, 0, 0), makecol( 0, 0, 0));
}
}
}