diff --git a/src/event_manager.c b/src/event_manager.c index 96b860e..e3c4d10 100644 --- a/src/event_manager.c +++ b/src/event_manager.c @@ -101,6 +101,9 @@ void set_key(int keycode, int value) { case ALLEGRO_KEY_F: keys[KEY_FULLSCREEN] = value; break; + case ALLEGRO_KEY_P: + keys[KEY_PAUSE] = value; + break; default: break; } diff --git a/src/event_manager.h b/src/event_manager.h index 89baadb..f4dbfa1 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -27,7 +27,8 @@ enum { KEY_RIGHT = 0x3, KEY_RESET = 0x4, KEY_FULLSCREEN = 0x5, - KEY_MAX = 0x6 + KEY_PAUSE = 0x6, + KEY_MAX = 0x7 }; /** diff --git a/src/main.c b/src/main.c index 3e5bfa5..16b5de4 100644 --- a/src/main.c +++ b/src/main.c @@ -104,6 +104,8 @@ int main() { redraw = 1; show_help = 1; show_info = 1; + int paused = 0; + int old_paused = 0; while(run) { handle_event(); @@ -111,10 +113,18 @@ int main() { // only redraw or run simulation if the timer event has occurred if(redraw) { - if(key_is_down(KEY_RESET)) - ship_init(&ship, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2); - else - ship_update(&ship); + if(paused == old_paused && key_is_down(KEY_PAUSE)) + paused = !paused; + else if(paused != old_paused && !key_is_down(KEY_PAUSE)) + old_paused = paused; + + if(!paused) + { + if(key_is_down(KEY_RESET)) + ship_init(&ship, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2); + else + ship_update(&ship); + } al_clear_to_color(al_map_rgb(0, 0, 0)); ship_draw(&ship);