From c420bb583fbf7c951aeb5b509a80406f92e13746 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Fri, 28 May 2021 17:17:27 +0200 Subject: [PATCH] reduce scope --- include/game_state.h | 1 + include/mainmenu.h | 6 +++--- make_filepaths.sh | 2 +- src/levelselection/update.c | 11 +++++++--- src/main.c | 40 ++++++++++++++++++++++++++++++------- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/game_state.h b/include/game_state.h index 41a2d8f..14a5c66 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -5,6 +5,7 @@ enum GameState { TitleScreen, MainMenu, + OptionsMenu, LevelSelection, Playing, GamePause, diff --git a/include/mainmenu.h b/include/mainmenu.h index d177d69..db6e6b0 100644 --- a/include/mainmenu.h +++ b/include/mainmenu.h @@ -4,12 +4,12 @@ #include "input.h" -#define MENU_ENTRIES 4 +#define MENU_ENTRIES 2 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" -static const char *menu_entries[MENU_ENTRIES] = { - "%c Play %c", "%c Options %c", "%c Achievements %c", "%c Quit %c"}; +static const char *menu_entries[MENU_ENTRIES] = {"%c Play %c", + "%c Save & Exit %c"}; #pragma GCC diagnostic pop struct MainMenu { diff --git a/make_filepaths.sh b/make_filepaths.sh index 80e2077..a4a33a5 100755 --- a/make_filepaths.sh +++ b/make_filepaths.sh @@ -47,4 +47,4 @@ printf '%s\n}\n' "$LEVEL_ARRAY" cd "$START_POS" mkdir -p generated/include [ "$((LEVEL_COUNT % 4))" != 0 ] && LEVEL_COUNT="$((LEVEL_COUNT + 4 - LEVEL_COUNT % 4))" -printf '#define PACK_COUNT %s\n' "$((LEVEL_COUNT / 4))" >> generated/include/pack_count.h +printf '#define PACK_COUNT %s\n' "$((LEVEL_COUNT / 4))" > generated/include/pack_count.h diff --git a/src/levelselection/update.c b/src/levelselection/update.c index 82fbd73..da099f9 100644 --- a/src/levelselection/update.c +++ b/src/levelselection/update.c @@ -6,7 +6,8 @@ #include "pack_count.h" #include "util.h" -/* Return 1 if game state should change. */ +/* Return 1 if game state should change. + * Return -1 to return to main menu. */ int levelselection_update(struct LevelSelection *restrict levelselection, struct Input input) @@ -26,8 +27,12 @@ levelselection_update(struct LevelSelection *restrict levelselection, (float)levelselection->pack_cursor; } - /* confirm */ - if (input.keystates[K_A] == KS_PRESS) { + if (input.keystates[K_START] == KS_PRESS) { + levelselection->visual_cursor = + (float)levelselection->pack_cursor; + levelselection->visual_target = levelselection->visual_cursor; + return -1; + } else if (input.keystates[K_A] == KS_PRESS) { levelselection->visual_cursor = (float)levelselection->pack_cursor; levelselection->visual_target = levelselection->visual_cursor; diff --git a/src/main.c b/src/main.c index 5b7488c..8956c2f 100644 --- a/src/main.c +++ b/src/main.c @@ -65,7 +65,7 @@ main(void) { int i; int timer; - int player_return_code; + int return_code; int draw_pause; int frameskip = 0; /* int level_pack_beaten; */ @@ -134,12 +134,30 @@ main(void) game_state = MainMenu; break; case MainMenu: - if (mainmenu_update(&mainmenu, input)) - game_state = LevelSelection; + if (mainmenu_update(&mainmenu, input)) { + switch (mainmenu.cursor) { + case 0: + game_state = LevelSelection; + break; + case 1: + goto exit_game; + default: + PANIC("unknown return code " + "(MainMenu)"); + break; + } + } break; case LevelSelection: - if (levelselection_update(&levelselection, - input)) { + return_code = levelselection_update( + &levelselection, input); + switch (return_code) { + case -1: + game_state = MainMenu; + break; + case 0: + break; + case 1: game_state = Playing; /* set level according to * selected pack */ @@ -149,16 +167,21 @@ main(void) transition = transition_init( H_TRANS_SPD, ZX_BLUE, TransitionHIn); + break; + default: + PANIC("unknown return code " + "(LevelSelection)"); + break; } break; case Playing: if (transition.mode == TransitionNone) { trail_update(player); particles_update(); - player_return_code = + return_code = player_update(&player, input); level_update(); - switch (player_return_code) { + switch (return_code) { case -1: game_state = GamePause; break; @@ -228,6 +251,7 @@ main(void) case PackDone: game_state = LevelSelection; break; + case OptionsMenu: default: PANIC("missing game_state case (update)"); break; @@ -263,6 +287,7 @@ main(void) break; case PackDone: break; + case OptionsMenu: default: PANIC("missing game_state case (draw)"); break; @@ -282,6 +307,7 @@ main(void) } } +exit_game: timer_stop(timer); #ifdef RECORDING if (usb_is_open())