mirror of https://git.sr.ht/~kikoodx/momento
Advance on game state organisation
This commit is contained in:
parent
a3c5f0e5a8
commit
6287fe306c
|
@ -2,4 +2,10 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
enum GameState { TitleScreen, MainMenu, LevelSelection, Playing };
|
||||
enum GameState {
|
||||
TitleScreen,
|
||||
MainMenu,
|
||||
LevelSelection,
|
||||
Playing,
|
||||
PackDone
|
||||
};
|
||||
|
|
17
src/main.c
17
src/main.c
|
@ -47,6 +47,7 @@ int main(void)
|
|||
int i;
|
||||
int timer;
|
||||
int player_return_code;
|
||||
int level_pack_beaten;
|
||||
enum TransitionMode transition_previous_mode;
|
||||
enum GameState game_state = Playing;
|
||||
volatile int has_ticked = 1;
|
||||
|
@ -90,11 +91,13 @@ int main(void)
|
|||
switch (game_state) {
|
||||
case TitleScreen:
|
||||
if (titlescreen_update(&titlescreen))
|
||||
game_state = Playing;
|
||||
game_state = MainMenu;
|
||||
break;
|
||||
case MainMenu:
|
||||
game_state = LevelSelection;
|
||||
break;
|
||||
case LevelSelection:
|
||||
game_state = Playing;
|
||||
break;
|
||||
case Playing:
|
||||
if (transition.mode == TransitionNone) {
|
||||
|
@ -135,6 +138,13 @@ int main(void)
|
|||
case TransitionHIn:
|
||||
break;
|
||||
case TransitionHOut:
|
||||
/* end level pack */
|
||||
if (level_id % 4 == 0) {
|
||||
game_state =
|
||||
PackDone;
|
||||
level_pack_beaten =
|
||||
level_id / 4;
|
||||
}
|
||||
LOAD_LEVEL();
|
||||
transition =
|
||||
transition_init(
|
||||
|
@ -161,6 +171,9 @@ int main(void)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case PackDone:
|
||||
game_state = LevelSelection;
|
||||
break;
|
||||
default:
|
||||
PANIC(
|
||||
"missing game_state case (update)");
|
||||
|
@ -183,6 +196,8 @@ int main(void)
|
|||
player_draw(player);
|
||||
transition_draw(transition);
|
||||
break;
|
||||
case PackDone:
|
||||
break;
|
||||
default:
|
||||
PANIC("missing game_state case (draw)");
|
||||
break;
|
||||
|
|
|
@ -20,7 +20,6 @@ void player_draw(struct Player player)
|
|||
dimage(player.x, player.y + PLAYER_HEIGHT, &bimg_burst);
|
||||
/* print level name
|
||||
* this shouldn't be in player code */
|
||||
dprint_opt(DWIDTH - 4, DHEIGHT, C_WHITE, C_NONE,
|
||||
DTEXT_RIGHT, DTEXT_BOTTOM, "%s",
|
||||
level_names[level.id]);
|
||||
dprint_opt(DWIDTH - 4, DHEIGHT, C_WHITE, C_NONE, DTEXT_RIGHT,
|
||||
DTEXT_BOTTOM, "%s", level_names[level.id]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue