mirror of https://git.sr.ht/~kikoodx/momento
reduce scope
This commit is contained in:
parent
55d386696f
commit
c420bb583f
|
@ -5,6 +5,7 @@
|
|||
enum GameState {
|
||||
TitleScreen,
|
||||
MainMenu,
|
||||
OptionsMenu,
|
||||
LevelSelection,
|
||||
Playing,
|
||||
GamePause,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
40
src/main.c
40
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())
|
||||
|
|
Loading…
Reference in New Issue