Now we can win or loose, also restart

This commit is contained in:
Vladislav Khorev 2026-04-20 00:36:32 +03:00
parent d557c4b530
commit d64659c8d6
8 changed files with 78 additions and 15 deletions

BIN
resources/e/menu/final_loose.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
resources/e/menu/final_win.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
resources/e/menu/restart_button.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -231,6 +231,10 @@ namespace ZL
this->updateMusicForGameState(newState); this->updateMusicForGameState(newState);
}; };
menuManager.onRestartPressed = [this]() {
this->restartGame();
};
//menuManager.setupMainMenu(); //menuManager.setupMainMenu();
/*<<<<<<< HEAD /*<<<<<<< HEAD
menuManager.currentState = GameState::Gameplay; menuManager.currentState = GameState::Gameplay;
@ -253,7 +257,9 @@ namespace ZL
if (menuManager.getState() == GameState::MainMenu || if (menuManager.getState() == GameState::MainMenu ||
menuManager.getState() == GameState::HelpScreen || 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 // Normal UI: show cursor and release grab / relative mode
SDL_ShowCursor(SDL_ENABLE); SDL_ShowCursor(SDL_ENABLE);
@ -297,7 +303,9 @@ namespace ZL
if (menuManager.getState() == GameState::MainMenu || if (menuManager.getState() == GameState::MainMenu ||
menuManager.getState() == GameState::HelpScreen || 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); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -599,11 +607,13 @@ namespace ZL
x = x + 1; x = x + 1;
break; break;
case SDLK_o: case SDLK_o:
menuManager.setupWinMenu();
x = x - 1;
break; break;
case SDLK_l: case SDLK_l:
menuManager.setupLooseMenu();
break;
case SDLK_w: case SDLK_w:
case SDLK_s: case SDLK_s:
case SDLK_a: case SDLK_a:
@ -759,17 +769,25 @@ namespace ZL
void Game::createLocations() 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<Location>(renderer, inventory, "forest"); forestLocation = std::make_shared<Location>(renderer, inventory, "forest");
forestLocation->setup(); forestLocation->setup();
forestLocation->onLocationChangeRequest = [this](const std::string& locId) { wireLocationCallbacks(*forestLocation);
this->changeLocation(locId);
};
defaultLocation = std::make_shared<Location>(renderer, inventory, "default"); defaultLocation = std::make_shared<Location>(renderer, inventory, "default");
defaultLocation->setup(); defaultLocation->setup();
defaultLocation->onLocationChangeRequest = [this](const std::string& locId) { wireLocationCallbacks(*defaultLocation);
this->changeLocation(locId);
};
currentLocation = defaultLocation; currentLocation = defaultLocation;
} }

View File

@ -1835,10 +1835,10 @@ void Location::setup()
if (dialoguePlayedOffroad) { if (dialoguePlayedOffroad) {
shouldSpawn = true; 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 60s case from the spec collapses into the same trigger — once
// the car is spawned the second threshold is moot). // the car is spawned the second threshold is moot).
if (dialoguePlayedPhone1 && !inCar && playerOnFootSeconds > 30.0f) { if (dialoguePlayedPhone1 && !inCar && playerOnFootSeconds > 15.0f) {
shouldSpawn = true; shouldSpawn = true;
} }

View File

@ -162,6 +162,8 @@ namespace ZL
bool dialoguePlayedVillageFinal2 = false; bool dialoguePlayedVillageFinal2 = false;
std::function<void(const std::string&)> onLocationChangeRequest; std::function<void(const std::string&)> onLocationChangeRequest;
std::function<void()> onGameWon;
std::function<void()> onGameLost;
ScriptEngine scriptEngine; ScriptEngine scriptEngine;
Dialogue::DialogueSystem dialogueSystem; Dialogue::DialogueSystem dialogueSystem;
@ -180,7 +182,7 @@ namespace ZL
int lastMouseY = 0; int lastMouseY = 0;
bool mouseInitialized = false; bool mouseInitialized = false;
bool wasKeyForward = false; bool wasKeyForward = false;
bool invertCameraY = true; bool invertCameraY = false;
void setup(); void setup();

View File

@ -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() void MenuManager::enterMainMenu()
{ {
setupMainMenu(); setupMainMenu();

View File

@ -19,7 +19,9 @@ namespace ZL {
Gameplay, Gameplay,
GameOver, GameOver,
HelpScreen, HelpScreen,
ConnectionLost ConnectionLost,
Win,
Loose
}; };
class MenuManager { class MenuManager {
@ -65,14 +67,17 @@ namespace ZL {
void setupMainMenu(); void setupMainMenu();
void setupHelpMenu(); void setupHelpMenu();
void setupAboutMenu(); void setupAboutMenu();
void setupWinMenu();
void setupLooseMenu();
void enterMainMenu(); void enterMainMenu();
void enterHelpMenu(); void enterHelpMenu();
void enterAboutMenu(); void enterAboutMenu();
void startGame(); void startGame();
GameState getState() const { return currentState; } GameState getState() const { return currentState; }
GameState getPreviousState() const { return previousState; } GameState getPreviousState() const { return previousState; }
std::function<void(GameState)> onGameStateChanged; std::function<void(GameState)> onGameStateChanged;
std::function<void()> onRestartPressed;
/* /*
// Returns true for states where Space should render and run (Gameplay, GameOver, ConnectionLost) // Returns true for states where Space should render and run (Gameplay, GameOver, ConnectionLost)