From f1709acbe289e12ba459d69b925e7de9f83c2577 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sun, 9 Jan 2022 04:24:25 +0100 Subject: [PATCH 1/3] little changes --- README | 23 +++++ headers/configData.h | 103 ++++++++++++++++++-- headers/game.h | 199 +++++++++++++++++++++++++++++++++++++- headers/god.h | 56 ++++++++++- headers/invaderDef.h | 23 ++++- headers/invadersGrid.h | 53 +++++++++- headers/menu.h | 29 ++++++ headers/pixelManager.h | 171 +++++++++++++++++++++++++++++++- headers/playMode.h | 13 +++ headers/player.h | 38 ++++++++ headers/playerDef.h | 38 ++++++++ headers/projectiles.h | 25 +++++ headers/scoresManager.h | 10 ++ src/configManagement.cpp | 11 +++ src/drawMenu.cpp | 23 +++-- src/game/gameBasics.cpp | 8 +- src/game/gameManagers.cpp | 10 ++ src/game/godThings.cpp | 10 ++ src/invaderGrids.cpp | 11 +++ src/main.cpp | 14 +++ src/player.cpp | 11 +++ src/projectiles.cpp | 9 ++ src/scoresManager.cpp | 10 ++ 23 files changed, 865 insertions(+), 33 deletions(-) diff --git a/README b/README index 6d39110..de73048 100644 --- a/README +++ b/README @@ -16,3 +16,26 @@ Reminder : les missiles sont tirés par les envahisseurs, et les torpilles par l Quelques unes des problèmes rencontrés : - La sépararation entre l'affichage et la logique nous force à calculer les positions 2 fois (pour le bounc checking, et le l'affichage)' + +``` +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 7fb1f2f..d99e58a 100644 --- a/headers/configData.h +++ b/headers/configData.h @@ -1,3 +1,13 @@ +/*! + * + * @file configData.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief Configuration file data storage + * + */ + #ifndef GUARD_CONFIGDATA_H #define GUARD_CONFIGDATA_H @@ -9,37 +19,116 @@ typedef string configKey; + +/*! + * @struct ConfigData + * @brief this struct stores all relevant data from the configuration file + */ struct ConfigData { - + + /*! + * @brief maximum framerate at which the game will run + */ unsigned maxFPS; - - + + /*! + * @brief Invader type matrix + */ InvadersGrid grid; + /*! + * @brief players horizontal start position + */ unsigned startXPosition; + + /*! + * @brief player movement speed + */ unsigned playersSpeed; + + /*! + * @brief player horizontal size in pixel + */ unsigned playersWidth; + + /*! + * @brief player shooting wait time + */ unsigned playersFireCooldown; + + /*! + * @brief player life points + */ unsigned playersLives; + + /*! + * @brief player key configuration + */ vector playerDefs; - - + /*! + * @brief invader movement speed + */ unsigned invadersSpeed; + + /*! + * @brief invader radius size in pixel + */ unsigned invadersSize; + + /*! + * @brief distance in pixel between two invader + */ unsigned invadersDistance; + + /*! + * @brief wait time between two invader missile + */ unsigned invadersFireCooldown; + /*! + * @brief + */ map invadersDef; + /*! + * @brief invaders missiles width in pixel + */ unsigned missilesWidth; - unsigned missilesLength; // auto defined from width + + /*! + * @brief invaders missiles length in pixel - auto defined from width + */ + unsigned missilesLength; + + /*! + * @brief invaders missiles movement speed + */ unsigned missilesSpeed; + + /*! + * @brief invaders missiles color + */ nsGraphics::RGBAcolor missilesColor; + /*! + * @brief players torpedos width in pixel + */ unsigned torpedosWidth; - unsigned torpedosLength; // auto defined from width + + /*! + * @brief players torpedos length in pixel // auto defined from width + */ + unsigned torpedosLength; + + /*! + * @brief players topedos movement speed + */ unsigned torpedosSpeed; + + /*! + * @brief players torpedos color + */ nsGraphics::RGBAcolor torpedosColor; }; diff --git a/headers/game.h b/headers/game.h index 192f3c0..94daa87 100644 --- a/headers/game.h +++ b/headers/game.h @@ -1,3 +1,15 @@ +/** + * + * @file game.h + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief full game logic and display management + * + **/ + + #ifndef GUARD_GAME_H #define GUARD_GAME_H #include @@ -15,63 +27,240 @@ using namespace std; +/*! + * @class Game + * @brief Main game class + */ class Game { private: + + /*! + * @brief the MinGL window in which the game will be drawn into + */ MinGL window; + + /*! + * @brief PixelManager : Class that contains and draws all the data that will be drawn on screen + */ PixelManager pm; + + /*! + * @brief ConfigData : Struct that stores all the relevant data read from the configuration file + */ ConfigData confData; + + /*! + * @brief + */ ScoresManager sm; + + /*! + * @brief Special entity : God + */ God god; - + + /*! + * @brief base position for game display + */ Position basePos; + + /*! + * @brief Invader posision and type matrix + */ InvadersGrid grid; + + /*! + * @brief Invader scroll direction - True = right , False = left + */ bool direction = true; - + + /*! + * @brief list of postion of all missiles shot by the invaders + */ vector missiles; + + /*! + * @brief list of postion of all torpedos shot by the player(s) + */ vector torpedos; - + + /*! + * @brief Define the current type of the game + */ PlayMode playMode; + + /*! + * @brief list of all player data + */ vector players; // invaders related variables + + /*! + * @brief cooldown between two invader shot in milliseconds + */ unsigned fireCooldown=120; // basic methods + + /*! + * @brief Set or reset all the setting for a new game + * @fn void initGame(); + */ void initGame(); + + /*! + * @brief + * @return true if there are no more invaders in the grid + * @fn bool updateColumns(); + */ bool updateColumns(); + + /*! + * @brief Asks the player(s) name(s) and write their score to the score file + * @fn void handleScoreSaving(); + */ void handleScoreSaving(); + + /*! + * @brief convert invader's matrix position to pixel coodinates + * @return pixel position object + * @fn Position invIndexToPos(unsigned x, unsigned y) const; + */ Position invIndexToPos(unsigned x, unsigned y) const; // drawing methods + + /*! + * @brief main display function, clear the window and calls sub display functions + * @param[in] fps : current screen framerate + * @fn void displayAll(unsigned fps) const; + */ void displayAll(unsigned fps) const; + + /*! + * @brief display God related objets + * @fn void displayGod() const; + */ void displayGod() const; + + /*! + * @brief display a singular invader + * @param[in] basePos : invader's pixel coordinates + * @param[in] type : invader's type + * @fn void displayInvader(const Position& basePos, InvaderType type) const + */ void displayInvader(const Position& basePos, InvaderType type) const; + + /*! + * @brief displays a player's remaining lives + * @fn void displayHearts(playerID) const; + */ void displayHearts(playerID) const; // managers + + /*! + * @brief Calls the function 'ManageOnePlayer' for all players in player list + * @fn void managePlayers(); + */ void managePlayers(); - void manageOnePlayer(playerID); + + /*! + * @brief Handles a player keystrokes, makes them move or make them shoot a torpedo + * @param[in] pID : Player id + * @fn void manageOnePlayer(playerID pID); + */ + void manageOnePlayer(playerID pID); + + /*! + * @brief Handles all invaders movements and when they'll shoot a missile + * @return true if the invaders went down from one line (and we should check lower boundary), else false + * @fn bool manageInvaders(); + */ bool manageInvaders(); // collision things + + /*! + * @brief Removes torpedo and missiles that are colliding + * @fn void remCollidingProjectiles(); + */ void remCollidingProjectiles(); + + /*! + * @brief Makes all missiles go downward + * @fn void moveMissiles(); + */ void moveMissiles(); + + /*! + * @brief Makes all torpedos go upward + * @fn void moveTorpedos(); + */ void moveTorpedos(); + + /*! + * @brief + * @return + * @fn + */ bool checkMissilesAndPlayers(); + + /*! + * @brief + * @return + * @fn + */ bool checkTorpedosAndInvaders(); + + /*! + * @brief + * @return + * @fn + */ bool invadersTouchPlayer() const; // god things + + /*! + * + */ void awakeGod(); + + /*! + * @brief + * @return + * @fn + */ bool manageGod(); public: // in case someone wants to mess with the code, here's a minimal API, costs nothing to us - Game(); + + /*! + * + */ + Game(); + + /*! + * + */ void managedGames(); + + /*! + * @brief + * @return + * @fn + */ WinValue enterGameLoop(); + /*! + * @brief + * @return + * @fn + */ bool reloadConfig(); }; diff --git a/headers/god.h b/headers/god.h index b8aa43c..1f4de1e 100644 --- a/headers/god.h +++ b/headers/god.h @@ -1,9 +1,22 @@ +/*! + * + * @file god.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief Special entity known as "God" + * + */ + #ifndef GUARD_GOD_H #define GUARD_GOD_H #include "utils.h" #include "invadersGrid.h" +/*! + * @brief + */ enum class GodState{ NONE, AWAKE, @@ -13,30 +26,69 @@ enum class GodState{ THROW, YOLO, }; + + // I don't want to put that in config, I feel like it would be useless and overkill at this point #define GOD_BENCH_SIZE 64 #define GOD_HAND_SIZE 64 #define GOD_HAND_DISTANCE 100 -/* +/*! * Hand position is determined */ - +/*! + * @class God + * @brief + */ class God{ public: + + /*! + * @brief + */ GodState state; + + /*! + * @brief + */ unsigned counter; // we do not use a Position because it is used for pixel X and Y + + /*! + * @brief + */ unsigned thrownInvPosX; + + /*! + * @brief + */ unsigned thrownInvPosY; + + /*! + * @brief + */ InvaderType thrownInvType; + + /*! + * @brief + */ Position thrownVector; + + /*! + * @brief + */ Position thrownTransition; + /*! + * @brief + * @param[in] screenWidth : + * @return + * @fn Position getRightHandPos(unsigned screenWidth) const; + */ Position getRightHandPos(unsigned screenWidth) const; }; diff --git a/headers/invaderDef.h b/headers/invaderDef.h index c616e33..286d481 100644 --- a/headers/invaderDef.h +++ b/headers/invaderDef.h @@ -1,11 +1,32 @@ +/*! + * + * @file invaderDef.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief invader type deffinition and related data + * + */ + #ifndef GUARD_INVADERDEF_H #define GUARD_INVADERDEF_H #include "mingl/graphics/rgbacolor.h" #include "utils.h" - + +/*! + * @struct InvaderTypeDef + * @brief defines an invader type + */ struct InvaderTypeDef { + /*! + * @brief color of the invader type + */ nsGraphics::RGBAcolor color; + + /*! + * @brief points given to the player by defeating this invader type + */ unsigned points; }; diff --git a/headers/invadersGrid.h b/headers/invadersGrid.h index 3cf12ae..4ca52c5 100644 --- a/headers/invadersGrid.h +++ b/headers/invadersGrid.h @@ -1,3 +1,14 @@ +/*! + * + * @file invaderGrid.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief invader matrix structure + * + */ + + #ifndef GUARD_INVADERSGRID_H #define GUARD_INVADERSGRID_H @@ -5,22 +16,60 @@ using namespace std; +/*! + * @brief List of all invader type + */ enum class InvaderType { TYPEA, TYPEB, TYPEC, NONE, }; + +/*! + * @class InvadersColumn + * @brief Column of invader + */ class InvadersColumn : public vector{ public: // idk why CLion says this is not implemented, but it is + + /*! + * @brief tells if the column contains no non type NONE invader + * @return True if there's only type NONE invader, False elsewise + * @fn bool hasNoValid() const; + */ bool hasNoValid() const; + + /*! + * @brief gives the index of the last valid (type different than NONE) invader + * @return index of the last valid invader if found, else size of the column + * @fn unsigned getOutterInvader() const; + */ unsigned getOutterInvader() const; + + /*! + * @brief + * @return + * @fn + */ unsigned randomValid() const; -}; +}; // class InvadersColumn + + +/*! + * @class InvadersColumn + * @brief Column of invader + */ class InvadersGrid : public vector{ public: + + /*! + * @brief List of all invader type + * @return + * @fn + */ unsigned randomValid() const; -}; +}; // InvadersGrid #endif \ No newline at end of file diff --git a/headers/menu.h b/headers/menu.h index d5c192e..6b35c6b 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -1,12 +1,41 @@ +/*! + * + * @file menu.h + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief simple menu backend implementation + * + */ + + #ifndef GUARD_MENU_H #define GUARD_MENU_H #include"vector" #include"string" +/*! + * @struct Menu + * @brief menu stuct + */ struct Menu{ + /*! + * @brief list of all menu options + */ vector entries; + + /*! + * @brief index of currently selected menu option + */ size_t currentValue = 0; + + /*! + * @brief color of currently selected menu option + */ nsGraphics::RGBAcolor selectedColor; + /*! + * @brief color of unelected menu option + */ nsGraphics::RGBAcolor unSelectedColor; }; diff --git a/headers/pixelManager.h b/headers/pixelManager.h index f890972..8d27716 100644 --- a/headers/pixelManager.h +++ b/headers/pixelManager.h @@ -1,3 +1,15 @@ +/*! + * + * @file pixelManager.h + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @author FABRE Lucas + * @date January 2022 + * @version 1.0 + * @brief manager + * + */ + #ifndef GUARD_PIXELMANAGER_H #define GUARD_PIXELMANAGER_H @@ -17,6 +29,11 @@ using namespace std; #define MIRROR(SP) mirrorData((SP).getPixelData(), (SP).getRowSize()), (SP).getRowSize() + +/*! +* @class PixelManager +* @brief main display function, clear the window and calls sub display functions +*/ class PixelManager{ public: MinGL& window; @@ -29,47 +46,195 @@ public: * * (We could copy them every time, but I feel like copying image data every frame isn't great) */ + + /*! + * @brief + */ nsGui::Sprite logo{"assets/logo.si2"}; + + /*! + * @brief + */ nsGui::Sprite gameBackground{"assets/game_background.si2"}; + + /*! + * @brief + */ nsGui::Sprite menuBackground{"assets/menu_background.si2"}; + + /*! + * @brief + */ nsGui::Sprite rightHand{"assets/hand_open.si2"}; + + /*! + * @brief + */ nsGui::Sprite leftHand{MIRROR(rightHand)}; - + /*! + * @brief + * @param[] + * @fn + */ explicit PixelManager(MinGL&); + /*! + * @brief + * @param[in] baseVector : + * @param[in] size : + * @param[in] color : + * @fn + */ void drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const; + + /*! + * @brief + * @param[in] baseVector : + * @param[in] size : + * @param[in] color : + * @fn + */ void drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const; + + /*! + * @brief + * @param[in] baseVector + * @param[in] size + * @param[in] color + * @fn + */ void drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const; + #define HEART_LENGTH 40 + + /*! + * @brief + * @param[] + * @fn + */ void drawHeart(const Position& baseVector) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawSprite(const nsGui::Sprite& sprite, const Position& pos) const; + + /*! + * @brief + * @param[] + * @fn + */ void displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color); - // TODO remove because unused ? - void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const; + + /*! + * @brief + * @param[] + * @fn + */ void displayMenu(const Position& pos, Menu& currentMenu); + + /*! + * @brief + * @param[] + * @fn + */ void drawGameBackground() const; + + /*! + * @brief + * @param[] + * @fn + */ void drawMenuBackground() const; + // TODO remove because unused ? + void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawFPS(unsigned fps) const; PlayMode showInitialMenu(); bool showDeathMenu() const; unsigned getScreenHeight() const; unsigned getScreenWidth() const; + + /*! + * @brief + * @param[] + * @fn + */ void startFrame() const; + + /*! + * @brief + * @param[] + * @fn + */ void endFrame() const; + /*! + * @brief + * @param[] + * @fn + */ void askPlayerNameMenu(playerID pID, string& name) const; // y will be negative sometimes, so not unsigned + + /*! + * @brief + * @param[] + * @fn + */ void drawGodBench(int y) const; + /*! + * @brief + * @param[] + * @fn + */ void drawGodRightHand(const Position& pos) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawGodLeftHand(const Position& pos) const; + + /*! + * @brief + * @param[] + * @fn + */ void drawGodFace(int y, bool angry=false) const; private: diff --git a/headers/playMode.h b/headers/playMode.h index 771c05b..0b7973d 100644 --- a/headers/playMode.h +++ b/headers/playMode.h @@ -1,6 +1,19 @@ +/*! + * + * @file playMode.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief game mode options + * + */ + #ifndef GUARD_PLAYMODE_H #define GUARD_PLAYMODE_H +/*! +* @brief List of all game playmode +*/ enum class PlayMode { NONE, SINGLE, diff --git a/headers/player.h b/headers/player.h index 10e8674..b177f3e 100644 --- a/headers/player.h +++ b/headers/player.h @@ -1,13 +1,51 @@ +/** + * + * @file player.h + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief player data storage + * + **/ + #ifndef GUARD_PLAYER_H #define GUARD_PLAYER_H +/*! + * @struct Player + * @brief player data structure + */ struct Player{ + + /*! + * @brief player life points + */ unsigned lives = 3; + + /*! + * @brief + */ unsigned x; + + /*! + * @brief player's unique identidier + */ unsigned id; + + /*! + * @brief player's personal score + */ unsigned score=0; + /*! + * @brief + */ unsigned deathAnimCounter=0; + + /*! + * @brief player's shooting cooldown + */ unsigned fireCooldown=0; // TODO remove ? diff --git a/headers/playerDef.h b/headers/playerDef.h index 7eb2886..6fd5d1a 100644 --- a/headers/playerDef.h +++ b/headers/playerDef.h @@ -1,16 +1,54 @@ +/*! + * + * @file playerDef.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief player key configuration + * + */ + #ifndef GUARD_PLAYER_DEF_H #define GUARD_PLAYER_DEF_H #include "mingl/graphics/rgbacolor.h" +/*! + * @struct PlayerKeys + * @brief player key configuration + */ struct PlayerKeys { + + /*! + * @brief key to move right + */ char right; + + /*! + * @brief key to move left + */ char left; + + /*! + * @brief key to shoot + */ char shoot; }; +/*! + * @struct PlayerDef + * @brief player data, contains colors and key configuration + */ struct PlayerDef { + + /*! + * @brief player color + */ nsGraphics::RGBAcolor color; + + /*! + * @brief player key configuration + */ PlayerKeys keys; }; diff --git a/headers/projectiles.h b/headers/projectiles.h index f76e9e6..cb858c9 100644 --- a/headers/projectiles.h +++ b/headers/projectiles.h @@ -1,3 +1,13 @@ +/*! + * + * @file projectiles.h + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief projectiles data storage + * + */ + #ifndef GUARD_PROJECTILES_H #define GUARD_PROJECTILES_H @@ -5,9 +15,24 @@ typedef Position missile; +/*! + * @class Torpedo + * @brief player's projectiles + */ class Torpedo : public Position { public: + + /*! + * @brief id of the player that shot the torpedo + */ playerID owner; + + /*! + * @brief constuctor for the torpedo class + * @param[in] x : horizontal pixel coordinate + * @param[in] y : vertical pixel coordinate + * @fn Torpedo(int x, int y, playerID owner); + */ Torpedo(int x, int y, playerID owner); }; diff --git a/headers/scoresManager.h b/headers/scoresManager.h index 9b9ef5f..93690c1 100644 --- a/headers/scoresManager.h +++ b/headers/scoresManager.h @@ -1,3 +1,13 @@ +/*! + * + * @file ScoreManager.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief Score file manager + * + */ + #ifndef GUARD_SCORESMANAGER_H #define GUARD_SCORESMANAGER_H diff --git a/src/configManagement.cpp b/src/configManagement.cpp index 640ab45..0b7325a 100644 --- a/src/configManagement.cpp +++ b/src/configManagement.cpp @@ -1,3 +1,14 @@ +/*! + * + * @file configManagement.cpp + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief config parser + * + */ + #include #include "game.h" diff --git a/src/drawMenu.cpp b/src/drawMenu.cpp index 9cfa1e4..7377dd4 100644 --- a/src/drawMenu.cpp +++ b/src/drawMenu.cpp @@ -1,3 +1,14 @@ +/*! + * + * @file drawMenu.cpp + * @author SIMAILA Djalim + * @author FABRE Lucas + * @date January 2022 + * @version 1.0 + * @brief menu drawing functions + * + */ + #include #include #include @@ -10,9 +21,9 @@ using namespace nsShape; using namespace nsGraphics; void PixelManager::displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color){ - window << Rectangle(Position(190, 430)+baseVector, Position(310, 465)+baseVector, KGray); - window << Rectangle(Position(188, 428)+baseVector, Position(312, 467)+baseVector, KBlack); - window << nsGui::Text(Vec2D(200, 450)+baseVector, text, color); + window << Rectangle(baseVector, Position(180, 40)+baseVector, KGray); + window << Rectangle(baseVector+Position(2,2), Position(178, 38)+baseVector, KBlack); + window << nsGui::Text(baseVector+Position(10,22), text, color); } void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ @@ -32,11 +43,11 @@ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ PlayMode PixelManager::showInitialMenu(){ 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; + const unsigned xOffset = getScreenHeight() / 2 ; + const unsigned yOffset = getScreenWidth() / 2 - 90; chrono::milliseconds waitTime = chrono::milliseconds(100); while(true){ - displayMenu(Position(350,0),initial); + displayMenu(Position(yOffset,xOffset),initial); // go down if (window.isPressed({'s', false})){ ++initial.currentValue; diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index a46d107..ab5dc9c 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -3,8 +3,7 @@ #include "game.h" #include "playMode.h" -#define WININIT window("space invader du turfu", Position(1280, 720), Position(128, 128), nsGraphics::KBlack) - +#define WININIT window("SUPER Space Invader : Turbo Apocalypse DX - VS GOD", Position(1280, 720), Position(128, 128), nsGraphics::KBlack) Game::Game() : WININIT, pm(window) { if(!reloadConfig()){ @@ -13,10 +12,6 @@ Game::Game() : WININIT, pm(window) { sm.readFile(); } -/** - * - * @return true if there are no more invaders in the grid - */ bool Game::updateColumns(){ while(true){ if(grid.empty())return true; @@ -66,7 +61,6 @@ void Game::managedGames() { } } - // we assume the game has been played before, and so we need to clean used members void Game::initGame(){ grid = confData.grid; // will copy the grid diff --git a/src/game/gameManagers.cpp b/src/game/gameManagers.cpp index 49fc605..137ae0d 100644 --- a/src/game/gameManagers.cpp +++ b/src/game/gameManagers.cpp @@ -1,3 +1,13 @@ +/*! + * + * @file gameBasics.cpp + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief game basic mechanisms + * + */ + #include "game.h" #define ISPRESSED(ID, X) window.isPressed({confData.playerDefs[ID].keys.X, false}) diff --git a/src/game/godThings.cpp b/src/game/godThings.cpp index 16a65f7..c6fbab2 100644 --- a/src/game/godThings.cpp +++ b/src/game/godThings.cpp @@ -1,3 +1,13 @@ +/*! + * + * @file gameBasics.cpp + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief god's implementation + * + */ + #include "game.h" void Game::awakeGod() { diff --git a/src/invaderGrids.cpp b/src/invaderGrids.cpp index 26b9082..8d2f560 100644 --- a/src/invaderGrids.cpp +++ b/src/invaderGrids.cpp @@ -1,9 +1,20 @@ +/*! + * + * @file invaderGrids.h + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief invader matrix structure + * + */ + #include #include bool InvadersColumn::hasNoValid() const { return getOutterInvader()==size(); } + unsigned InvadersColumn::getOutterInvader() const { unsigned i=size(); while(i>0){ diff --git a/src/main.cpp b/src/main.cpp index 1b586b6..a2d7d07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,17 @@ +/*! + * + * @file main.cpp + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @author FABRE Lucas + * @date January 2022 + * @version 1.0 + * @brief main + * + * Welcome to SUPER Space Invader turbo apocalypse DX - VS GOD + * This little game was made in love by the glorious Thomas, the sublime Lucas, and the magnificent Djalim + */ + #include #include "game.h" using namespace std; diff --git a/src/player.cpp b/src/player.cpp index e322ff8..2a00ebe 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1,3 +1,14 @@ +/** + * + * @file player.h + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief player data storage + * + **/ + #include "player.h" bool Player::isPlaying() const { diff --git a/src/projectiles.cpp b/src/projectiles.cpp index 4dfa44a..5b9a4ad 100644 --- a/src/projectiles.cpp +++ b/src/projectiles.cpp @@ -1,3 +1,12 @@ +/*! + * + * @file projectiles.cpp + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief projectiles data storage + * + */ #include "projectiles.h" Torpedo::Torpedo(int x, int y, playerID owner) : Position(x, y) { diff --git a/src/scoresManager.cpp b/src/scoresManager.cpp index bf82608..cf81fa5 100644 --- a/src/scoresManager.cpp +++ b/src/scoresManager.cpp @@ -1,3 +1,13 @@ +/*! + * + * @file ScoreManager.cpp + * @author RUBINI Thomas + * @date January 2022 + * @version 1.0 + * @brief Score file manager + * + */ + #include #include #include From ea6b4891262aac6e80bb84bbfc8a07a91e3030fa Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sun, 9 Jan 2022 04:27:18 +0100 Subject: [PATCH 2/3] forgot some files --- src/configManagement.cpp | 2 ++ src/drawEntity.cpp | 12 ++++++++++++ src/game/display.cpp | 11 +++++++++++ src/game/gameBasics.cpp | 11 +++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/configManagement.cpp b/src/configManagement.cpp index 0b7325a..c93dd60 100644 --- a/src/configManagement.cpp +++ b/src/configManagement.cpp @@ -12,6 +12,8 @@ #include #include "game.h" +// you will MOVE THIS OUT OF THIS FILE + class ConfigBuilder{ public: ConfigData collectedData; diff --git a/src/drawEntity.cpp b/src/drawEntity.cpp index 25ea2a7..4760d33 100644 --- a/src/drawEntity.cpp +++ b/src/drawEntity.cpp @@ -1,3 +1,15 @@ +/*! + * + * @file drawEntity.cpp + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @author FABRE Lucas + * @date January 2022 + * @version 1.0 + * @brief entity drawing functions + * + */ + #include #include "pixelManager.h" #include "mingl/gui/text.h" diff --git a/src/game/display.cpp b/src/game/display.cpp index bfeef8a..c99564e 100644 --- a/src/game/display.cpp +++ b/src/game/display.cpp @@ -1,3 +1,14 @@ +/*! + * + * @file display.cpp + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief game display + * + */ + #include "game.h" diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index ab5dc9c..1bde67f 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -1,3 +1,14 @@ +/*! + * + * @file gameBasics.cpp + * @author RUBINI Thomas + * @author SIMAILA Djalim + * @date January 2022 + * @version 1.0 + * @brief game basic mechanisms + * + */ + #include #include #include "game.h" From 4c8bbef0064277b8b83363ed20b2500319ed412e Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sun, 9 Jan 2022 14:28:48 +0100 Subject: [PATCH 3/3] 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(); } } }