mirror of https://git.sr.ht/~kikoodx/momento
Improved main menu and added GamePause state
This commit is contained in:
parent
74635d67cd
commit
795f0ef5c1
|
@ -2,4 +2,4 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
enum GameState { TitleScreen, MainMenu, LevelSelection, Playing, PackDone };
|
||||
enum GameState { TitleScreen, MainMenu, LevelSelection, Playing, GamePause, PackDone };
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#define KEYS_COUNT 5
|
||||
enum Keys { K_LEFT, K_RIGHT, K_UP, K_DOWN, K_A };
|
||||
#define KEYS_COUNT 6
|
||||
enum Keys { K_LEFT, K_RIGHT, K_UP, K_DOWN, K_A, K_START };
|
||||
enum KeyState { KS_UP = 0, KS_DOWN, KS_PRESS };
|
||||
|
||||
struct Input {
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -50,7 +50,7 @@ int main(void)
|
|||
int i;
|
||||
int timer;
|
||||
int player_return_code;
|
||||
int level_pack_beaten;
|
||||
/* int level_pack_beaten; */
|
||||
enum TransitionMode transition_previous_mode;
|
||||
enum GameState game_state = TitleScreen;
|
||||
volatile int has_ticked = 1;
|
||||
|
@ -121,13 +121,16 @@ int main(void)
|
|||
player_return_code =
|
||||
player_update(&player, input);
|
||||
switch (player_return_code) {
|
||||
case -1:
|
||||
game_state = GamePause;
|
||||
break;
|
||||
case 1:
|
||||
level_id += 1;
|
||||
transition = transition_init(
|
||||
H_TRANS_SPD, ZX_BLUE,
|
||||
TransitionHOut);
|
||||
break;
|
||||
case -1:
|
||||
case 2:
|
||||
transition = transition_init(
|
||||
V_TRANS_SPD, ZX_RED,
|
||||
TransitionVOut);
|
||||
|
@ -152,8 +155,8 @@ int main(void)
|
|||
/* end level pack */
|
||||
if (level_id % 4 == 0) {
|
||||
game_state = PackDone;
|
||||
level_pack_beaten =
|
||||
level_id / 4;
|
||||
/* level_pack_beaten =
|
||||
level_id / 4; */
|
||||
}
|
||||
LOAD_LEVEL();
|
||||
transition = transition_init(
|
||||
|
@ -175,6 +178,9 @@ int main(void)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case GamePause:
|
||||
game_state = Playing;
|
||||
break;
|
||||
case PackDone:
|
||||
game_state = LevelSelection;
|
||||
break;
|
||||
|
@ -201,6 +207,8 @@ int main(void)
|
|||
player_draw(player);
|
||||
transition_draw(transition);
|
||||
break;
|
||||
case GamePause:
|
||||
break;
|
||||
case PackDone:
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -10,15 +10,21 @@
|
|||
int mainmenu_update(struct MainMenu *mainmenu, struct Input input)
|
||||
{
|
||||
/* decrease selected pack id */
|
||||
if ((input.keystates[K_UP] == KS_PRESS ||
|
||||
input.keystates[K_LEFT] == KS_PRESS) &&
|
||||
mainmenu->cursor > 0)
|
||||
mainmenu->cursor -= 1;
|
||||
if (input.keystates[K_UP] == KS_PRESS ||
|
||||
input.keystates[K_LEFT] == KS_PRESS) {
|
||||
if (mainmenu->cursor > 0)
|
||||
mainmenu->cursor -= 1;
|
||||
else
|
||||
mainmenu->cursor = MENU_ENTRIES - 1;
|
||||
}
|
||||
/* increase selected pack id */
|
||||
if ((input.keystates[K_DOWN] == KS_PRESS ||
|
||||
input.keystates[K_RIGHT] == KS_PRESS) &&
|
||||
mainmenu->cursor < MENU_ENTRIES - 1)
|
||||
mainmenu->cursor += 1;
|
||||
if (input.keystates[K_DOWN] == KS_PRESS ||
|
||||
input.keystates[K_RIGHT] == KS_PRESS) {
|
||||
if (mainmenu->cursor < MENU_ENTRIES - 1)
|
||||
mainmenu->cursor += 1;
|
||||
else
|
||||
mainmenu->cursor = 0;
|
||||
}
|
||||
/* confirm */
|
||||
if (input.keystates[K_A] == KS_PRESS)
|
||||
return 1;
|
||||
|
|
|
@ -12,7 +12,7 @@ static void player_move(struct Player *player, int x, int y);
|
|||
|
||||
extern struct Level level;
|
||||
|
||||
/* return 1 if exit reached, -1 on death/reset and 0 otherwise */
|
||||
/* return -1 on pause, return 1 if exit reached, 2 on death/reset and 0 otherwise */
|
||||
int player_update(struct Player *player, struct Input input)
|
||||
{
|
||||
Tile collisions[COLLIDE_POINTS];
|
||||
|
@ -25,6 +25,10 @@ int player_update(struct Player *player, struct Input input)
|
|||
const int k_jump = input.keystates[K_A] != KS_UP;
|
||||
const int kp_jump = input.keystates[K_A] == KS_PRESS;
|
||||
|
||||
/* pause the game? */
|
||||
if (input.keystates[K_START] == KS_PRESS)
|
||||
return -1;
|
||||
|
||||
/* horizontal friction/acceleration */
|
||||
player->spd_x *= (on_ground) ? (1 - FRC_GND) : (1 - FRC_AIR);
|
||||
player->spd_x += dir_x * ((on_ground) ? (ACC_GND) : (ACC_AIR));
|
||||
|
@ -122,7 +126,7 @@ int player_update(struct Player *player, struct Input input)
|
|||
}
|
||||
if (player_collide_tile(collisions, player->x, player->y, TILE_LETAL,
|
||||
MARGIN_LETAL, 1)) {
|
||||
return -1;
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue