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:
|
case ALLEGRO_KEY_F:
|
||||||
keys[KEY_FULLSCREEN] = value;
|
keys[KEY_FULLSCREEN] = value;
|
||||||
break;
|
break;
|
||||||
|
case ALLEGRO_KEY_P:
|
||||||
|
keys[KEY_PAUSE] = value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ enum {
|
|||||||
KEY_RIGHT = 0x3,
|
KEY_RIGHT = 0x3,
|
||||||
KEY_RESET = 0x4,
|
KEY_RESET = 0x4,
|
||||||
KEY_FULLSCREEN = 0x5,
|
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;
|
redraw = 1;
|
||||||
show_help = 1;
|
show_help = 1;
|
||||||
show_info = 1;
|
show_info = 1;
|
||||||
|
int paused = 0;
|
||||||
|
int old_paused = 0;
|
||||||
while(run)
|
while(run)
|
||||||
{
|
{
|
||||||
handle_event();
|
handle_event();
|
||||||
@ -111,10 +113,18 @@ int main() {
|
|||||||
// only redraw or run simulation if the timer event has occurred
|
// only redraw or run simulation if the timer event has occurred
|
||||||
if(redraw)
|
if(redraw)
|
||||||
{
|
{
|
||||||
if(key_is_down(KEY_RESET))
|
if(paused == old_paused && key_is_down(KEY_PAUSE))
|
||||||
ship_init(&ship, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
paused = !paused;
|
||||||
else
|
else if(paused != old_paused && !key_is_down(KEY_PAUSE))
|
||||||
ship_update(&ship);
|
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));
|
al_clear_to_color(al_map_rgb(0, 0, 0));
|
||||||
ship_draw(&ship);
|
ship_draw(&ship);
|
||||||
|
Loading…
Reference in New Issue
Block a user