From d64659c8d6f71c83d9cbfd6c6a98b2daf33263ca Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Mon, 20 Apr 2026 00:36:32 +0300 Subject: [PATCH] Now we can win or loose, also restart --- resources/e/menu/final_loose.png | 3 +++ resources/e/menu/final_win.png | 3 +++ resources/e/menu/restart_button.png | 3 +++ src/Game.cpp | 38 +++++++++++++++++++++-------- src/Location.cpp | 4 +-- src/Location.h | 4 ++- src/MenuManager.cpp | 29 ++++++++++++++++++++++ src/MenuManager.h | 9 +++++-- 8 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 resources/e/menu/final_loose.png create mode 100644 resources/e/menu/final_win.png create mode 100644 resources/e/menu/restart_button.png diff --git a/resources/e/menu/final_loose.png b/resources/e/menu/final_loose.png new file mode 100644 index 0000000..62a6e09 --- /dev/null +++ b/resources/e/menu/final_loose.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c1e75801d917f9de3c5610e853d8352717d6e824e080034af45711f6d7c8fa2 +size 49978 diff --git a/resources/e/menu/final_win.png b/resources/e/menu/final_win.png new file mode 100644 index 0000000..cec4454 --- /dev/null +++ b/resources/e/menu/final_win.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cefdfe3b8e6ca63e9d2cc1b4a45a3d065ff49281a4fbe1bc076cff315e0ba9f2 +size 48309 diff --git a/resources/e/menu/restart_button.png b/resources/e/menu/restart_button.png new file mode 100644 index 0000000..b3792c8 --- /dev/null +++ b/resources/e/menu/restart_button.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b26d24e430027b75cfd7731d6222789f2718d4e825f451bda5f49ca50bd9dcb +size 3179 diff --git a/src/Game.cpp b/src/Game.cpp index fb0718e..3501dee 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -231,6 +231,10 @@ namespace ZL this->updateMusicForGameState(newState); }; + menuManager.onRestartPressed = [this]() { + this->restartGame(); + }; + //menuManager.setupMainMenu(); /*<<<<<<< HEAD menuManager.currentState = GameState::Gameplay; @@ -253,7 +257,9 @@ namespace ZL if (menuManager.getState() == GameState::MainMenu || menuManager.getState() == GameState::HelpScreen || - menuManager.getState() == GameState::AboutMenu) + menuManager.getState() == GameState::AboutMenu || + menuManager.getState() == GameState::Win || + menuManager.getState() == GameState::Loose) { // Normal UI: show cursor and release grab / relative mode SDL_ShowCursor(SDL_ENABLE); @@ -297,7 +303,9 @@ namespace ZL if (menuManager.getState() == GameState::MainMenu || menuManager.getState() == GameState::HelpScreen || - menuManager.getState() == GameState::AboutMenu) + menuManager.getState() == GameState::AboutMenu || + menuManager.getState() == GameState::Win || + menuManager.getState() == GameState::Loose) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -599,11 +607,13 @@ namespace ZL x = x + 1; break; case SDLK_o: - - x = x - 1; + menuManager.setupWinMenu(); break; case SDLK_l: + menuManager.setupLooseMenu(); + break; + case SDLK_w: case SDLK_s: case SDLK_a: @@ -759,17 +769,25 @@ namespace ZL void Game::createLocations() { + auto wireLocationCallbacks = [this](Location& loc) { + loc.onLocationChangeRequest = [this](const std::string& locId) { + this->changeLocation(locId); + }; + loc.onGameWon = [this]() { + this->menuManager.setupWinMenu(); + }; + loc.onGameLost = [this]() { + this->menuManager.setupLooseMenu(); + }; + }; + forestLocation = std::make_shared(renderer, inventory, "forest"); forestLocation->setup(); - forestLocation->onLocationChangeRequest = [this](const std::string& locId) { - this->changeLocation(locId); - }; + wireLocationCallbacks(*forestLocation); defaultLocation = std::make_shared(renderer, inventory, "default"); defaultLocation->setup(); - defaultLocation->onLocationChangeRequest = [this](const std::string& locId) { - this->changeLocation(locId); - }; + wireLocationCallbacks(*defaultLocation); currentLocation = defaultLocation; } diff --git a/src/Location.cpp b/src/Location.cpp index ed9c2ff..acf7d20 100644 --- a/src/Location.cpp +++ b/src/Location.cpp @@ -1835,10 +1835,10 @@ void Location::setup() if (dialoguePlayedOffroad) { shouldSpawn = true; } - // Cases 1 & 2: phone dialogue done and player has been on foot >30s + // Cases 1 & 2: phone dialogue done and player has been on foot >15s // (the 60s case from the spec collapses into the same trigger — once // the car is spawned the second threshold is moot). - if (dialoguePlayedPhone1 && !inCar && playerOnFootSeconds > 30.0f) { + if (dialoguePlayedPhone1 && !inCar && playerOnFootSeconds > 15.0f) { shouldSpawn = true; } diff --git a/src/Location.h b/src/Location.h index 0fb1100..8fbcadc 100644 --- a/src/Location.h +++ b/src/Location.h @@ -162,6 +162,8 @@ namespace ZL bool dialoguePlayedVillageFinal2 = false; std::function onLocationChangeRequest; + std::function onGameWon; + std::function onGameLost; ScriptEngine scriptEngine; Dialogue::DialogueSystem dialogueSystem; @@ -180,7 +182,7 @@ namespace ZL int lastMouseY = 0; bool mouseInitialized = false; bool wasKeyForward = false; - bool invertCameraY = true; + bool invertCameraY = false; void setup(); diff --git a/src/MenuManager.cpp b/src/MenuManager.cpp index a0279b6..5f4a06a 100644 --- a/src/MenuManager.cpp +++ b/src/MenuManager.cpp @@ -68,6 +68,35 @@ namespace ZL { }); } + void MenuManager::setupWinMenu() + { + previousState = currentState; + currentState = GameState::Win; + uiManager.loadFromFile("resources/config2/menu_win.json", renderer, CONST_ZIP_FILE); + + if (onGameStateChanged) { + onGameStateChanged(GameState::Win); + } + } + + void MenuManager::setupLooseMenu() + { + previousState = currentState; + currentState = GameState::Loose; + uiManager.loadFromFile("resources/config2/menu_loose.json", renderer, CONST_ZIP_FILE); + + if (onGameStateChanged) { + onGameStateChanged(GameState::Loose); + } + + uiManager.setButtonCallback("backButton", [this](const std::string&) { + if (onRestartPressed) { + onRestartPressed(); + } + startGame(); + }); + } + void MenuManager::enterMainMenu() { setupMainMenu(); diff --git a/src/MenuManager.h b/src/MenuManager.h index 1dd27a6..dfb4b8c 100644 --- a/src/MenuManager.h +++ b/src/MenuManager.h @@ -19,7 +19,9 @@ namespace ZL { Gameplay, GameOver, HelpScreen, - ConnectionLost + ConnectionLost, + Win, + Loose }; class MenuManager { @@ -65,14 +67,17 @@ namespace ZL { void setupMainMenu(); void setupHelpMenu(); void setupAboutMenu(); + void setupWinMenu(); + void setupLooseMenu(); void enterMainMenu(); void enterHelpMenu(); void enterAboutMenu(); void startGame(); - + GameState getState() const { return currentState; } GameState getPreviousState() const { return previousState; } std::function onGameStateChanged; + std::function onRestartPressed; /* // Returns true for states where Space should render and run (Gameplay, GameOver, ConnectionLost)