Implement pause functionality.
This commit is contained in:
parent
349848ebf6
commit
63f950e26b
@ -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;
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ enum {
|
||||
KEY_RIGHT = 0x3,
|
||||
KEY_RESET = 0x4,
|
||||
KEY_FULLSCREEN = 0x5,
|
||||
KEY_MAX = 0x6
|
||||
KEY_PAUSE = 0x6,
|
||||
KEY_MAX = 0x7
|
||||
};
|
||||
|
||||
/**
|
||||
|
18
src/main.c
18
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);
|
||||
|
Loading…
Reference in New Issue
Block a user