From 4c8bbef0064277b8b83363ed20b2500319ed412e Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sun, 9 Jan 2022 14:28:48 +0100 Subject: [PATCH] end of game menu done --- config.yml | 10 +++++----- headers/pixelManager.h | 2 +- src/drawMenu.cpp | 43 +++++++++++++++++++++++++++++++++++------ src/game/gameBasics.cpp | 4 +--- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/config.yml b/config.yml index 92b8e63..40fc54b 100644 --- a/config.yml +++ b/config.yml @@ -1,6 +1,6 @@ # General configuration general: - maxFPS: 50 + maxFPS: 30 # Players config players: @@ -25,7 +25,7 @@ players: # Enemies config invaders: fireCooldown: 20 - size: 25 + size: 40 speed: 7 distance: 10 # distance in pixels between invaders @@ -54,6 +54,6 @@ projectiles: # Grid definition # You can add more rows, make rows longer and add spaces grid: - - "AAAAAAAAAAAA" - - "BBBBBBBBBBBB" - - "CCCCCCCCCCCC" + - " " + - " " + - "B" diff --git a/headers/pixelManager.h b/headers/pixelManager.h index 8d27716..5394ccd 100644 --- a/headers/pixelManager.h +++ b/headers/pixelManager.h @@ -182,7 +182,7 @@ public: void drawFPS(unsigned fps) const; PlayMode showInitialMenu(); - bool showDeathMenu() const; + PlayMode showDeathMenu(); unsigned getScreenHeight() const; unsigned getScreenWidth() const; diff --git a/src/drawMenu.cpp b/src/drawMenu.cpp index 7377dd4..19d64f8 100644 --- a/src/drawMenu.cpp +++ b/src/drawMenu.cpp @@ -41,7 +41,7 @@ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ } PlayMode PixelManager::showInitialMenu(){ - vector entries {"single player","multi player (local)","EXIT"}; + vector entries {"single player","multi player (local)","exit"}; Menu initial {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; const unsigned xOffset = getScreenHeight() / 2 ; const unsigned yOffset = getScreenWidth() / 2 - 90; @@ -51,15 +51,15 @@ PlayMode PixelManager::showInitialMenu(){ // go down if (window.isPressed({'s', false})){ ++initial.currentValue; - if (initial.currentValue > initial.entries.size()) initial.currentValue = 0; + if (initial.currentValue > initial.entries.size()-1) initial.currentValue = 0; this_thread::sleep_for(waitTime); - } + } // go up if (window.isPressed({'z', false})){ if (initial.currentValue == 0) initial.currentValue = initial.entries.size()-1; else --initial.currentValue; this_thread::sleep_for(waitTime); - } + }// select option else if (window.isPressed({13, false})){ switch(initial.currentValue){ case 0: @@ -68,14 +68,45 @@ PlayMode PixelManager::showInitialMenu(){ return PlayMode::TWO_LOCAL; case 2: return PlayMode::EXIT; + default: + return PlayMode::SINGLE; } } } } -bool PixelManager::showDeathMenu() const { - return true; +PlayMode PixelManager::showDeathMenu() { + vector entries {"main menu","exit"}; + Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; + const unsigned xOffset = getScreenHeight() / 2 ; + const unsigned yOffset = getScreenWidth() / 2 - 90; + chrono::milliseconds waitTime = chrono::milliseconds(100); + while(true){ + displayMenu(Position(yOffset,xOffset),death); + // go down + if (window.isPressed({'s', false})){ + ++death.currentValue; + if (death.currentValue > death.entries.size()-1) death.currentValue = 0; + this_thread::sleep_for(waitTime); + } + // go up + if (window.isPressed({'z', false})){ + if (death.currentValue == 0) death.currentValue = death.entries.size()-1; + else --death.currentValue; + this_thread::sleep_for(waitTime); + }// select option + else if (window.isPressed({13, false})){ + switch(death.currentValue){ + case 0: + return PlayMode::NONE; + case 1: + return PlayMode::EXIT; + default: + return PlayMode::EXIT; + } + } + } } diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index 1bde67f..dacd210 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -65,9 +65,7 @@ void Game::managedGames() { enterGameLoop(); // will read the playMode handleScoreSaving(); cout << "END OF GAME" << endl; - break; // TODO remove - if(!pm.showDeathMenu()) playMode = PlayMode::NONE; // back to the main menu - + playMode = pm.showDeathMenu(); } } }