From 3d304dcc7e636ad49e82e1fa7f9edbc325d11172 Mon Sep 17 00:00:00 2001 From: huaqo-games Date: Fri, 17 Oct 2025 18:20:47 +0200 Subject: [PATCH] feat: exit menu with ESC to gameplay --- include/flags.h | 2 +- include/game.h | 12 ++++++++---- include/menu.h | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/flags.h b/include/flags.h index ef8faf4..d5ded90 100644 --- a/include/flags.h +++ b/include/flags.h @@ -3,7 +3,7 @@ typedef struct { bool showFPS; - bool soundOn; + bool soundtrackOn; } Flags; #endif // FLAGS_H diff --git a/include/game.h b/include/game.h index d0a0628..cac77a2 100644 --- a/include/game.h +++ b/include/game.h @@ -75,19 +75,23 @@ void InitGame(GameState *g, Window *window) 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) { SetTargetFPS(0); } if (IsKeyPressed(KEY_ESCAPE)) { - *currentView = MENU; + state->currentView = MENU; } if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)) { - *running = false; + state->running = false; } 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++) { - UpdateSoundtrack(&g->soundtracks[i], flags->soundOn); + UpdateSoundtrack(&g->soundtracks[i], flags->soundtrackOn); } UpdateMouse(&g->mouse, &g->camera); diff --git a/include/menu.h b/include/menu.h index 9cd2a7a..f84aa1d 100644 --- a/include/menu.h +++ b/include/menu.h @@ -121,6 +121,11 @@ void UpdateMenu(MenuState *m, State *state, Flags *flags) 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))) { state->running = false;