diff --git a/README b/README index de73048..dd32c56 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ Les guards sont de cette forme : GUARD__H Concernant les const : Afin de limiter l'utilisation du mot const (pour garder une certaine lisibilité du code), les cas suivants n'ont pas besoin d'etre déclarés comme const : -- déclaration/défintion de fonctions : les types primitifs/valeurs d'enum passés par valeurs ne sont pas notés const +- déclaration/définition de fonctions : les types primitifs/valeurs d'enum passés par valeurs ne sont pas notés const écran : constante 1280x720 @@ -22,20 +22,9 @@ DOC game.h : scoremanager -displayAll : const missing non? j'ai mit "in" faudra voir manageOnePlayer : const missing non? j'ai mit "in" faudra voir le fin du fichier game.h enfaite lol god.h tout lol - -invadergrid.h -les randomValid j'ai du mal a saisir - -player.h -x ? -DeathAnimCounter issou j'ai la flemme d'aller chercher ou c'est used - -configData.h -map invadersDef; comment est ce que j'explique une map xD? ``` \ No newline at end of file diff --git a/headers/configData.h b/headers/configData.h index d99e58a..39a675d 100644 --- a/headers/configData.h +++ b/headers/configData.h @@ -87,7 +87,7 @@ struct ConfigData { unsigned invadersFireCooldown; /*! - * @brief + * @brief link between an invader type, and its data */ map invadersDef; diff --git a/headers/game.h b/headers/game.h index 34b1c37..fc3ac27 100644 --- a/headers/game.h +++ b/headers/game.h @@ -108,13 +108,13 @@ private: * @fn void initGame(); */ void initGame(); - + /*! * @brief * @return true if there are no more invaders in the grid - * @fn bool updateColumns(); + * @fn bool updateColumns(); */ - bool updateColumns(); + bool areThereInvadersLeft(); /*! * @brief Asks the player(s) name(s) and write their score to the score file diff --git a/headers/invadersGrid.h b/headers/invadersGrid.h index 4ca52c5..44fa32e 100644 --- a/headers/invadersGrid.h +++ b/headers/invadersGrid.h @@ -69,7 +69,8 @@ public: * @return * @fn */ - unsigned randomValid() const; -}; // InvadersGrid + unsigned validColsNumber() const; + unsigned randomValidCol() const; +}; #endif \ No newline at end of file diff --git a/headers/pixelManager.h b/headers/pixelManager.h index 85f4e47..8750792 100644 --- a/headers/pixelManager.h +++ b/headers/pixelManager.h @@ -48,36 +48,36 @@ public: */ /*! - * @brief + * @brief sprite of the logo of the game */ nsGui::Sprite logo{"assets/logo.si2"}; /*! - * @brief + * @brief sprite of the background during gameplay */ nsGui::Sprite gameBackground{"assets/game_background.si2"}; /*! - * @brief + * @brief sprite of the background during menu */ nsGui::Sprite menuBackground{"assets/menu_background.si2"}; /*! - * @brief + * @brief sprite of the right hand of god */ nsGui::Sprite rightHand{"assets/hand_open.si2"}; /*! - * @brief + * @brief sprite of the left hand of god */ nsGui::Sprite leftHand{MIRROR(rightHand)}; /*! - * @brief - * @param[] - * @fn + * @brief constructor the pixel manager class + * @param[in] window : window of the pixel manager + * @fn PixelManager(MinGL&); */ - explicit PixelManager(MinGL&); + explicit PixelManager(MinGL& window); /*! * @brief display a type A invader on screen @@ -136,92 +136,97 @@ public: #define HEART_LENGTH 40 /*! - * @brief - * @param[] - * @fn + * @brief display a singular heart on screen + * @param[in] baseVector : pixel coordinates of the heart + * @fn void drawHeart(const Position& baseVector) const; */ void drawHeart(const Position& baseVector) const; /*! - * @brief - * @param[] - * @fn + * @brief display a sprite on screen + * @param[in] sprite : sprite to draw + * @param[in] pos : pixel coordinates to draw the sprite + * @fn void drawSprite(const nsGui::Sprite& sprite, const Position& pos = Position(0, 0)) const; */ void drawSprite(const nsGui::Sprite& sprite, const Position& pos = Position(0, 0)) const; /*! - * @brief - * @param[] - * @fn + * @brief display a menu button on screen + * @param[in] baseVector : pixel coordinates of the button + * @param[in] text : text inside the button + * @param[in] color : color of the text inside the button + * @fn void displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color); */ void displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color); /*! - * @brief - * @param[] - * @fn + * @brief display a menu on screen + * @param[in] pos : pixel coordinates of the menu + * @param[in,out] currentMenu : menu struct conteining the menu option + * @fn void displayMenu(const Position& pos, Menu& currentMenu); */ void displayMenu(const Position& pos, Menu& currentMenu); /*! - * @brief - * @param[] - * @fn + * @brief display text on screen + * @param[in] pos : pixel coordinates of the text + * @param[in] text : text to show on screen + * @param[in] color : color of the text to show + * @fn void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const; */ void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const; /*! - * @brief - * @param[] - * @fn + * @brief display the current screen refresh rate + * @param[in] fps : current framerate + * @fn void drawFPS(unsigned fps) const; */ void drawFPS(unsigned fps) const; /*! - * @brief - * @return - * @fn + * @brief show the title screen of the game + * @return the playmode chosen inside the menu + * @fn PlayMode showInitialMenu(); */ PlayMode showInitialMenu(); - + /*! - * @brief - * @return - * @fn + * @brief show the menu after a player lose, or all invader has been defeated + * @return true if the player plays again, else false + * @fn bool showDeathMenu(); */ bool showDeathMenu(); /*! - * @brief - * @return - * @fn + * @brief give the height of the screen + * @return the height of the screen in pixel + * @fn unsigned getScreenHeight() const; */ unsigned getScreenHeight() const; /*! - * @brief - * @return - * @fn + * @brief give the width of the screen + * @return the width of the screen in pixel + * @fn unsigned getScreenWidth() const; */ unsigned getScreenWidth() const; /*! - * @brief - * @param[] - * @fn + * @brief clear the screen for a new frame + * @fn void startFrame() const; */ void startFrame() const; /*! - * @brief - * @param[] - * @fn + * @brief finish a frame render + * @fn void endFrame() const; */ void endFrame() const; /*! - * @brief - * @param[] + * @brief display the player name selection menu + * @param[in] pID : player id + * @param[out] name : name selected by the player * @fn */ void askPlayerNameMenu(playerID pID, string& name); @@ -229,36 +234,44 @@ public: // y will be negative sometimes, so not unsigned /*! - * @brief - * @param[] - * @fn + * @brief display god's bar + * @param[in] y : god y pixel position + * @fn void drawGodBench(int y) const */ void drawGodBench(int y) const; /*! - * @brief - * @param[] - * @fn + * @brief display god's right hand + * @param[in] pos : pixel coordiniates of the hand + * @fn void drawGodRightHand(const Position& pos) const; */ void drawGodRightHand(const Position& pos) const; /*! - * @brief - * @param[] - * @fn + * @brief display god's left hand + * @param[in] pos : pixel coordiniates of the hand + * @fn void drawGodLeftHand(const Position& pos) const; */ void drawGodLeftHand(const Position& pos) const; /*! - * @brief - * @param[] - * @fn + * @brief display god's face + * @param[in] y : god's face y pixel position + * @param[in] angry : flag if god is angry or not + * @fn void drawGodFace(int y, bool angry=false) const; */ void drawGodFace(int y, bool angry=false) const; private: // Explanation for choices : // non reference output : I don't think we have another choice than a std::move() here + + /*! + * @brief + * @param[in] inPixel : vector of pixel from a sprite + * @param[in] rowSize : size of a line of pixel + * @fn vector mirrorData(const vector& inPixels, unsigned rowSize); + */ vector mirrorData(const vector& inPixels, unsigned rowSize); }; diff --git a/headers/player.h b/headers/player.h index b177f3e..8b1f08c 100644 --- a/headers/player.h +++ b/headers/player.h @@ -24,7 +24,7 @@ struct Player{ unsigned lives = 3; /*! - * @brief + * @brief x coordinate of the player */ unsigned x; @@ -39,7 +39,8 @@ struct Player{ unsigned score=0; /*! - * @brief + * @brief counter used for the death animation of players + * undefined once the player is eliminated */ unsigned deathAnimCounter=0; diff --git a/src/drawEntity.cpp b/src/drawEntity.cpp index 388da7a..4a88f12 100644 --- a/src/drawEntity.cpp +++ b/src/drawEntity.cpp @@ -10,9 +10,8 @@ * */ -#include -#include "pixelManager.h" #include "mingl/gui/text.h" +#include "pixelManager.h" #include "utils.h" #include "god.h" @@ -20,7 +19,7 @@ using namespace nsShape; using namespace nsGui; -PixelManager::PixelManager(MinGL& a) : window(a) { +PixelManager::PixelManager(MinGL& win) : window(win) { window.initGlut(); window.initGraphic(); } @@ -138,11 +137,14 @@ void PixelManager::drawFPS(unsigned fps) const { vector PixelManager::mirrorData(const vector& inPixels, unsigned rowSize) { vector outPixels; + // we reserve size so the vector doesn't dynamically grows outPixels.reserve(inPixels.size()); - - for(unsigned i=0;i entries {"retry","main menu"}; Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; diff --git a/src/game/display.cpp b/src/game/display.cpp index 54d78a4..2895280 100644 --- a/src/game/display.cpp +++ b/src/game/display.cpp @@ -41,9 +41,12 @@ void Game::displayAll(unsigned fps) const { for(size_t i=0;i 0; } void Game::handleScoreSaving(){ diff --git a/src/game/gameManagers.cpp b/src/game/gameManagers.cpp index f068ccf..314dc5e 100644 --- a/src/game/gameManagers.cpp +++ b/src/game/gameManagers.cpp @@ -13,6 +13,7 @@ #define ISPRESSED(ID, X) window.isPressed({confData.playerDefs[ID].keys.X, false}) void Game::manageOnePlayer(playerID pID){ Player& p = players[pID]; + if(p.isEliminated())return; if (ISPRESSED(pID, left)){ if(p.x < confData.playersSpeed) p.x = 0; @@ -26,7 +27,7 @@ void Game::manageOnePlayer(playerID pID){ if(p.hasDeathAnimation()) { ++p.deathAnimCounter; - if (p.deathAnimCounter == 100) { + if (p.deathAnimCounter == 75) { p.deathAnimCounter = 0; } }else{ @@ -57,7 +58,7 @@ bool Game::manageInvaders(){ if(fireCooldown==0) { fireCooldown = confData.invadersFireCooldown + rand() % 60; - unsigned rdCol = grid.randomValid(); + unsigned rdCol = grid.randomValidCol(); // fire ! missiles.push_back(basePos + Position( confData.invadersSize * rdCol + confData.invadersDistance * (rdCol + 0.5), diff --git a/src/game/godThings.cpp b/src/game/godManager.cpp similarity index 88% rename from src/game/godThings.cpp rename to src/game/godManager.cpp index c6fbab2..2da3f03 100644 --- a/src/game/godThings.cpp +++ b/src/game/godManager.cpp @@ -35,26 +35,28 @@ bool Game::manageGod() { ++god.counter; return false; } - // init throw - god.counter = 0; - god.state = GodState::RETRIEVE1; - god.thrownInvPosX = grid.randomValid(); - god.thrownInvPosY = grid[god.thrownInvPosX].randomValid(); - god.thrownInvType = InvaderType::NONE; + if (areThereInvadersLeft()) { + // init throw + god.counter = 0; + god.state = GodState::RETRIEVE1; + god.thrownInvPosX = grid.randomValidCol(); + god.thrownInvPosY = grid[god.thrownInvPosX].randomValid(); + god.thrownInvType = InvaderType::NONE; - god.thrownTransition.setX(pm.getScreenWidth() - GOD_HAND_DISTANCE - GOD_HAND_SIZE); - god.thrownTransition.setY(basePos.getY() + INV_GET_POS(god.thrownInvPosY)); - return false; + god.thrownTransition.setX(pm.getScreenWidth() - GOD_HAND_DISTANCE - GOD_HAND_SIZE); + god.thrownTransition.setY(basePos.getY() + INV_GET_POS(god.thrownInvPosY)); + return false; + } } case GodState::RETRIEVE1: { if (god.counter < 100) { god.counter += 2; return false; } + if (grid.size() > god.thrownInvPosY && grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) { god.thrownInvType = grid[god.thrownInvPosX][god.thrownInvPosY]; grid[god.thrownInvPosX][god.thrownInvPosY] = InvaderType::NONE; - updateColumns(); } god.state = GodState::RETRIEVE2; return false; diff --git a/src/invaderGrids.cpp b/src/invaderGrids.cpp index 8d2f560..a48eb9d 100644 --- a/src/invaderGrids.cpp +++ b/src/invaderGrids.cpp @@ -47,15 +47,19 @@ unsigned InvadersColumn::randomValid() const { throw runtime_error("SHOULD NOT HAPPEN"); } -unsigned InvadersGrid::randomValid() const { - - +unsigned InvadersGrid::validColsNumber() const { unsigned validTotal = 0; for(const InvadersColumn& i : *this){ if(!i.hasNoValid())++validTotal; } + return validTotal; +} - unsigned rd = rand() % validTotal; +unsigned InvadersGrid::randomValidCol() const { + + + + unsigned rd = rand() % validColsNumber(); unsigned validIndex = 0; for(unsigned i=0;i