feat: exit menu with ESC to gameplay

This commit is contained in:
huaqo-games
2025-10-17 18:20:47 +02:00
parent 54b7dfbfd4
commit 3d304dcc7e
3 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
typedef struct { typedef struct {
bool showFPS; bool showFPS;
bool soundOn; bool soundtrackOn;
} Flags; } Flags;
#endif // FLAGS_H #endif // FLAGS_H
+8 -4
View File
@@ -75,19 +75,23 @@ void InitGame(GameState *g, Window *window)
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]); g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]);
} }
void UpdateGame(GameState *g, View *currentView, bool *running, Flags *flags) void UpdateGame(GameState *g, State *state, Flags *flags)
{ {
if(!state->gameStarted){
state->gameStarted = true;
}
if (GetFPS() <= 60) if (GetFPS() <= 60)
{ {
SetTargetFPS(0); SetTargetFPS(0);
} }
if (IsKeyPressed(KEY_ESCAPE)) if (IsKeyPressed(KEY_ESCAPE))
{ {
*currentView = MENU; state->currentView = MENU;
} }
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)) if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
{ {
*running = false; state->running = false;
} }
for (int i = 0; i < SHADER_COUNT; i++) for (int i = 0; i < SHADER_COUNT; i++)
{ {
@@ -95,7 +99,7 @@ void UpdateGame(GameState *g, View *currentView, bool *running, Flags *flags)
} }
for (int i = 0; i < SOUNDTRACK_COUNT; i++) for (int i = 0; i < SOUNDTRACK_COUNT; i++)
{ {
UpdateSoundtrack(&g->soundtracks[i], flags->soundOn); UpdateSoundtrack(&g->soundtracks[i], flags->soundtrackOn);
} }
UpdateMouse(&g->mouse, &g->camera); UpdateMouse(&g->mouse, &g->camera);
+5
View File
@@ -121,6 +121,11 @@ void UpdateMenu(MenuState *m, State *state, Flags *flags)
state->currentView = GAMEPLAY; state->currentView = GAMEPLAY;
} }
if (IsKeyPressed(KEY_ESCAPE) && state->gameStarted)
{
state->currentView = GAMEPLAY;
}
if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))) if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)))
{ {
state->running = false; state->running = false;