Implement pause functionality.

This commit is contained in:
Nicolás Ortega Froysa 2018-04-13 08:02:34 +02:00
parent 349848ebf6
commit 63f950e26b
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
3 changed files with 19 additions and 5 deletions

View File

@ -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;
}

View File

@ -27,7 +27,8 @@ enum {
KEY_RIGHT = 0x3,
KEY_RESET = 0x4,
KEY_FULLSCREEN = 0x5,
KEY_MAX = 0x6
KEY_PAUSE = 0x6,
KEY_MAX = 0x7
};
/**

View File

@ -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);