From 1e6892f6b1de9ba1d73c9345a545c7875dee9465 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 10 Jan 2022 15:31:07 +0100 Subject: [PATCH 1/3] end menu score display --- config.yml | 5 +++++ headers/pixelManager/pixelManager.h | 12 +++++++++++- headers/scoresManager.h | 2 +- src/game/gameBasics.cpp | 2 +- src/pixelManager/drawMenus.cpp | 27 +++++++++++++++++++++++++-- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/config.yml b/config.yml index 786204f..08ae95f 100644 --- a/config.yml +++ b/config.yml @@ -8,10 +8,15 @@ # run for a pleasant experience it should be above 30 # maxFPS: 30 # +# The theme setting deffines which theme will be used during gameplay sesssion. +# For a more custom experience use the 'bad' theme, for a more eye pleasant +# experience use the 'good' theme. +# general: maxFPS: 30 theme: bad + ############################# # # # Player configuration # diff --git a/headers/pixelManager/pixelManager.h b/headers/pixelManager/pixelManager.h index 6658037..192eaa6 100644 --- a/headers/pixelManager/pixelManager.h +++ b/headers/pixelManager/pixelManager.h @@ -24,6 +24,7 @@ #include "utils.h" #include "playMode.h" #include "menu.h" +#include "scoresManager.h" #include "mySprite.h" using namespace std; @@ -178,6 +179,14 @@ public: */ void displayMenu(const Position& pos, Menu& currentMenu); + /*! + * @brief display a menu on screen + * @param[in] pos : pixel coordinates of the menu + * @param[in,out] currentMenu : menu struct conteining the menu option + * @param[in] rankings : the current top 10 players + * @fn void displayMenu(const Position& pos, Menu& currentMenu); + */ + void displayMenu(const Position& pos, Menu& currentMenu, const vector& rankings); /*! * @brief display text on screen * @param[in] pos : pixel coordinates of the text @@ -197,9 +206,10 @@ public: /*! * @brief show the menu after a player lose, or all invader has been defeated * @return true if the player plays again, else false + * @param[in] rankings : the current top 5 score * @fn bool showDeathMenu(); */ - bool showDeathMenu(); + bool showDeathMenu(const vector& rankings); /*! * @brief give the height of the screen diff --git a/headers/scoresManager.h b/headers/scoresManager.h index 9be7cd9..6e578b2 100644 --- a/headers/scoresManager.h +++ b/headers/scoresManager.h @@ -1,6 +1,6 @@ /*! * - * @file ScoreManager.h + * @file scoresManager.h * @author RUBINI Thomas * @date January 2022 * @version 1.0 diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index ad9666d..7a53c77 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -73,7 +73,7 @@ void Game::managedGames() { enterGameLoop(); // will read the playMode handleScoreSaving(); cout << "END OF GAME" << endl; - if(!pm->showDeathMenu())playMode = PlayMode::NONE; + if(!pm->showDeathMenu(sm.scores))playMode = PlayMode::NONE; } } } diff --git a/src/pixelManager/drawMenus.cpp b/src/pixelManager/drawMenus.cpp index ba575bb..aeb5b0d 100644 --- a/src/pixelManager/drawMenus.cpp +++ b/src/pixelManager/drawMenus.cpp @@ -40,6 +40,29 @@ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ endFrame(); } + +void PixelManager::displayMenu(const Position& pos, Menu& currentMenu, const vector& rankings){ + startFrame(); + drawSprite(menuBackground); + drawSprite(logo,Position(100,50)); + drawText(Position(1150, 700), "version 1.0.0"); + unsigned margin = 0; + unsigned cpt = 0; + for(string& value : currentMenu.entries ){ + displayButton(Position(0,0+margin)+ pos, value, (currentMenu.currentValue == cpt) ? currentMenu.selectedColor : currentMenu.unSelectedColor ); + ++cpt; + margin += 50; + } + margin = 0; + drawText(Position(0,350), "Top 10 des meilleurs joueurs",nsGraphics::KWhite); + for (auto& value: rankings){ + drawText(Position(0,400+margin),value.name,nsGraphics::KWhite); + drawText(Position(140,400+margin),to_string(value.score),nsGraphics::KWhite); + margin += 50; + } + endFrame(); +} + PlayMode PixelManager::showInitialMenu(){ vector entries {"single player","multi player (local)","exit"}; Menu initial {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; @@ -124,14 +147,14 @@ void PixelManager::askPlayerNameMenu(playerID pID, unsigned score, string& name) exit(0); } -bool PixelManager::showDeathMenu() { +bool PixelManager::showDeathMenu(const vector& rankings) { vector entries {"retry","main menu"}; Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; unsigned xOffset = getScreenHeight() / 2 ; unsigned yOffset = getScreenWidth() / 2 - 90; chrono::milliseconds waitTime = chrono::milliseconds(100); while(window.isOpen()){ - displayMenu(Position(yOffset,xOffset),death); + displayMenu(Position(yOffset,xOffset),death,rankings); // go down if (window.isPressed({'s', false})){ ++death.currentValue; From 209e1289abbb9a1896e8c714ea6d88816e4f5bed Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 10 Jan 2022 15:54:03 +0100 Subject: [PATCH 2/3] score during gameplay --- headers/game.h | 6 ++++++ src/game/display.cpp | 13 ++++++++++++- src/game/gameBasics.cpp | 6 ------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/headers/game.h b/headers/game.h index c63529d..3714560 100644 --- a/headers/game.h +++ b/headers/game.h @@ -132,6 +132,12 @@ private: // drawing methods + /*! + * @brief display players score on the screen + * @fn void displayScore(); + */ + void displayScore() const; + /*! * @brief main display function, clear the window and calls sub display functions * @param[in] fps : current screen refresh rate diff --git a/src/game/display.cpp b/src/game/display.cpp index d6d7b4e..3353a5f 100644 --- a/src/game/display.cpp +++ b/src/game/display.cpp @@ -34,8 +34,9 @@ void Game::displayAll(unsigned fps) const { pm->drawTorpedo(tor, confData.torpedosWidth, confData.torpedosColor); } - + displayGod(); + displayScore(); DEBUG_INSTR( pm->drawText(Position(pm->getScreenWidth()-200, 20), "FPS : "+to_string(fps), nsGraphics::KWhite, Font::BITMAP_8_BY_13); @@ -69,6 +70,16 @@ void Game::displayHearts(playerID pID) const { } } +void Game::displayScore() const{ + unsigned margin = 0; + unsigned playerNumber = 1; + for (auto& player: players){ + pm->drawText(Position(0,10+margin),"player "+to_string(playerNumber)+" :",nsGraphics::KWhite,Font::BITMAP_8_BY_13); + pm->drawText(Position(100,10+margin),to_string(player.score) ,nsGraphics::KWhite,Font::BITMAP_8_BY_13); + ++playerNumber; + } +} + void Game::displayInvader(const Position& pos, InvaderType type) const { if(type==InvaderType::NONE)return; const InvaderTypeDef& invDef = confData.invadersDef.at(type); diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index 67a6024..5618fc9 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -109,12 +109,6 @@ void Game::initGame(){ } -/** - * Plays the game, and returns once the game is finished - * - * @return @WinValue::PLAYERS if the players won, @WinValue::INVADERS is the invaders won, WinValue::NOBODY else (also in case of error) - */ - #define START_TIMER() DEBUG_INSTR(debugTime = chrono::high_resolution_clock::now()) #define PRINT_TIMER(X) DEBUG_MSG((X) << " :" << chrono::duration_cast(chrono::high_resolution_clock::now()-debugTime).count()) From f40fb1727ff5a9da8d4c48e75a16fe1ac02321a5 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 10 Jan 2022 15:55:16 +0100 Subject: [PATCH 3/3] score during gameplay + multiplayer --- src/game/display.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game/display.cpp b/src/game/display.cpp index 3353a5f..caf3e36 100644 --- a/src/game/display.cpp +++ b/src/game/display.cpp @@ -77,6 +77,7 @@ void Game::displayScore() const{ pm->drawText(Position(0,10+margin),"player "+to_string(playerNumber)+" :",nsGraphics::KWhite,Font::BITMAP_8_BY_13); pm->drawText(Position(100,10+margin),to_string(player.score) ,nsGraphics::KWhite,Font::BITMAP_8_BY_13); ++playerNumber; + margin +=15; } }