From 07301f1b8dd6b1e32a0213e5ff16c9189f14541b Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 22 Aug 2021 01:09:46 +0200 Subject: [PATCH] EXIT to menu (including after last level) --- src/main.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 1e46957..cdddb30 100644 --- a/src/main.c +++ b/src/main.c @@ -80,17 +80,8 @@ int strcount(char const *str, int c) return count; } -int main(void) +void game_loop(int current_episode, int current_level) { - __printf_enable_fp(); - - /* Azur trickz for less tearing */ - r61524_set(0x010, 0x0010); - - int current_episode = 0; - int current_level = 0; - main_menu(¤t_episode, ¤t_level); - game_t game; memset(&game, 0x00, sizeof game); @@ -164,9 +155,13 @@ int main(void) bool rotate_left=false, rotate_right=false; key_event_t e; + bool stop_playing=false; + while ((e = pollevent()).type != KEYEV_NONE) { if (e.type == KEYEV_DOWN && e.key == KEY_MENU) gint_osmenu(); + if (e.type == KEYEV_DOWN && e.key == KEY_EXIT) + stop_playing = true; } if (keydown(KEY_7)) { rotate_left = true; @@ -174,6 +169,8 @@ int main(void) if (keydown(KEY_0)) { rotate_right = true; } + if (stop_playing) + break; /* Level transitions */ @@ -286,5 +283,22 @@ int main(void) } timer_stop(timer); - return (1); +} + +int main(void) +{ + __printf_enable_fp(); + + /* Azur trickz for less tearing */ + r61524_set(0x010, 0x0010); + + int current_episode = 0; + int current_level = 0; + + while(1) { + main_menu(¤t_episode, ¤t_level); + game_loop(current_episode, current_level); + } + + return 1; }