Now we can win or loose, also restart
This commit is contained in:
parent
d557c4b530
commit
d64659c8d6
BIN
resources/e/menu/final_loose.png
(Stored with Git LFS)
Normal file
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
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
BIN
resources/e/menu/restart_button.png
(Stored with Git LFS)
Normal file
Binary file not shown.
38
src/Game.cpp
38
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()
|
||||
{
|
||||
forestLocation = std::make_shared<Location>(renderer, inventory, "forest");
|
||||
forestLocation->setup();
|
||||
forestLocation->onLocationChangeRequest = [this](const std::string& locId) {
|
||||
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->setup();
|
||||
wireLocationCallbacks(*forestLocation);
|
||||
|
||||
defaultLocation = std::make_shared<Location>(renderer, inventory, "default");
|
||||
defaultLocation->setup();
|
||||
defaultLocation->onLocationChangeRequest = [this](const std::string& locId) {
|
||||
this->changeLocation(locId);
|
||||
};
|
||||
wireLocationCallbacks(*defaultLocation);
|
||||
|
||||
currentLocation = defaultLocation;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -162,6 +162,8 @@ namespace ZL
|
||||
bool dialoguePlayedVillageFinal2 = false;
|
||||
|
||||
std::function<void(const std::string&)> onLocationChangeRequest;
|
||||
std::function<void()> onGameWon;
|
||||
std::function<void()> 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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -19,7 +19,9 @@ namespace ZL {
|
||||
Gameplay,
|
||||
GameOver,
|
||||
HelpScreen,
|
||||
ConnectionLost
|
||||
ConnectionLost,
|
||||
Win,
|
||||
Loose
|
||||
};
|
||||
|
||||
class MenuManager {
|
||||
@ -65,6 +67,8 @@ namespace ZL {
|
||||
void setupMainMenu();
|
||||
void setupHelpMenu();
|
||||
void setupAboutMenu();
|
||||
void setupWinMenu();
|
||||
void setupLooseMenu();
|
||||
void enterMainMenu();
|
||||
void enterHelpMenu();
|
||||
void enterAboutMenu();
|
||||
@ -73,6 +77,7 @@ namespace ZL {
|
||||
GameState getState() const { return currentState; }
|
||||
GameState getPreviousState() const { return previousState; }
|
||||
std::function<void(GameState)> onGameStateChanged;
|
||||
std::function<void()> onRestartPressed;
|
||||
|
||||
/*
|
||||
// Returns true for states where Space should render and run (Gameplay, GameOver, ConnectionLost)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user