From 947665d30631d0dd1752b4bcf72d2e99c49bb37e Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 9 Jan 2022 21:13:38 +0100 Subject: [PATCH] b --- headers/invadersGrid.h | 1 + src/drawMenu.cpp | 2 +- src/game/gameBasics.cpp | 3 +++ src/game/gameManagers.cpp | 3 ++- src/game/godManager.cpp | 19 +++++++++++-------- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/headers/invadersGrid.h b/headers/invadersGrid.h index da2d20e..78f1ac3 100644 --- a/headers/invadersGrid.h +++ b/headers/invadersGrid.h @@ -69,6 +69,7 @@ public: * @return * @fn */ + unsigned validColsNumber() const; unsigned randomValidCol() const; }; diff --git a/src/drawMenu.cpp b/src/drawMenu.cpp index 30a3186..2681de8 100644 --- a/src/drawMenu.cpp +++ b/src/drawMenu.cpp @@ -84,7 +84,7 @@ void PixelManager::askPlayerNameMenu(playerID pID, string& name) { while (window.isOpen()){ startFrame(); drawSprite(menuBackground); - displayText(Position(600,100),"Nom du joueur "+ string(1,pID)); + displayText(Position(600,100),"Nom du joueur "+to_string(pID+1)); for (size_t i = 0; i < name.size(); ++i){ displayText(Position(600+30*i,200),string(1,name[i]),(i == currentSelected) ? nsGraphics::KRed : nsGraphics::KWhite); } diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index 61e8889..9a87e55 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -64,6 +64,9 @@ void Game::initGame(){ // we re-construct players objects, we don't have to clear all members and can rely on the construction value (set in .h file) players.clear(); + missiles.clear(); + torpedos.clear(); + if(playMode==PlayMode::SINGLE){ players.resize(1); }else{ diff --git a/src/game/gameManagers.cpp b/src/game/gameManagers.cpp index dc356e6..c101684 100644 --- a/src/game/gameManagers.cpp +++ b/src/game/gameManagers.cpp @@ -49,7 +49,8 @@ void Game::managePlayers(){ } bool Game::manageInvaders(){ - if(grid.empty())return false; // If there are no more invaders we don't need to manage them + if(!areThereInvadersLeft())return false; // If there are no more invaders we don't need to manage them + // shoot if(fireCooldown==0) { fireCooldown = confData.invadersFireCooldown + rand() % 60; diff --git a/src/game/godManager.cpp b/src/game/godManager.cpp index f1cf045..d067bc6 100644 --- a/src/game/godManager.cpp +++ b/src/game/godManager.cpp @@ -58,7 +58,8 @@ bool Game::manageGod() { return false; } - if (grid.size() > god.thrownInvPosY && grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) { + if (grid[god.thrownInvPosX].size() > god.thrownInvPosY && + grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) { god.thrownInvType = grid[god.thrownInvPosX][god.thrownInvPosY]; grid[god.thrownInvPosX][god.thrownInvPosY] = InvaderType::NONE; } @@ -113,6 +114,11 @@ bool Game::manageGod() { if (invaderPos.getY() + confData.invadersSize >= pm.getScreenWidth() || (invaderPos.getX() < 0 || invaderPos.getX() + confData.invadersSize >= pm.getScreenWidth())) { touched = true; + + /* there are no invaders in the grid anymore, and the one thrown just went out of bound + * So... return true, the playere wins*/ + if(!areThereInvadersLeft())return true; + // check player collision } else if (invaderPos.getY() + confData.invadersSize >= pm.getScreenHeight() - PLAYER_HEIGHT) { for (Player &p: players) { @@ -131,16 +137,13 @@ bool Game::manageGod() { if (touched) { god.state = GodState::WAIT; god.counter = 0; + if(!areThereInvadersLeft())return true; } - /* - * we do not need to reset other members, they'll be treated as non-initialized - * When we cycle back between states - */ + /* we do not need to reset other members, they'll be treated as non-initialized + * When we cycle back between states*/ - // We could have optimized that, but it's more readable like this and hopefully the compiler will optimize it itself - if(areThereInvadersLeft())return false; - else return true; + return false; } case GodState::YOLO: {