save commit

This commit is contained in:
Thomas 2022-01-09 17:25:33 +01:00
parent 7b2eda8549
commit 15dc67c348
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
13 changed files with 122 additions and 121 deletions

13
README
View File

@ -7,7 +7,7 @@ Les guards sont de cette forme : GUARD_<filename>_H
Concernant les const : 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 : 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 écran : constante 1280x720
@ -22,20 +22,9 @@ DOC
game.h : game.h :
scoremanager scoremanager
displayAll : const missing non? j'ai mit "in" faudra voir
manageOnePlayer : 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 le fin du fichier game.h enfaite lol
god.h god.h
tout lol 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<InvaderType, InvaderTypeDef> invadersDef; comment est ce que j'explique une map xD?
``` ```

View File

@ -87,7 +87,7 @@ struct ConfigData {
unsigned invadersFireCooldown; unsigned invadersFireCooldown;
/*! /*!
* @brief * @brief link between an invader type, and its data
*/ */
map<InvaderType, InvaderTypeDef> invadersDef; map<InvaderType, InvaderTypeDef> invadersDef;

View File

@ -114,7 +114,7 @@ private:
* @return true if there are no more invaders in the grid * @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 * @brief Asks the player(s) name(s) and write their score to the score file

View File

@ -69,7 +69,8 @@ public:
* @return * @return
* @fn * @fn
*/ */
unsigned randomValid() const; unsigned validColsNumber() const;
}; // InvadersGrid unsigned randomValidCol() const;
};
#endif #endif

View File

@ -48,36 +48,36 @@ public:
*/ */
/*! /*!
* @brief * @brief sprite of the logo of the game
*/ */
nsGui::Sprite logo{"assets/logo.si2"}; nsGui::Sprite logo{"assets/logo.si2"};
/*! /*!
* @brief * @brief sprite of the background during gameplay
*/ */
nsGui::Sprite gameBackground{"assets/game_background.si2"}; nsGui::Sprite gameBackground{"assets/game_background.si2"};
/*! /*!
* @brief * @brief sprite of the background during menu
*/ */
nsGui::Sprite menuBackground{"assets/menu_background.si2"}; nsGui::Sprite menuBackground{"assets/menu_background.si2"};
/*! /*!
* @brief * @brief sprite of the right hand of god
*/ */
nsGui::Sprite rightHand{"assets/hand_open.si2"}; nsGui::Sprite rightHand{"assets/hand_open.si2"};
/*! /*!
* @brief * @brief sprite of the left hand of god
*/ */
nsGui::Sprite leftHand{MIRROR(rightHand)}; nsGui::Sprite leftHand{MIRROR(rightHand)};
/*! /*!
* @brief * @brief constructor the pixel manager class
* @param[] * @param[in] window : window of the pixel manager
* @fn * @fn PixelManager(MinGL&);
*/ */
explicit PixelManager(MinGL&); explicit PixelManager(MinGL& window);
/*! /*!
* @brief display a type A invader on screen * @brief display a type A invader on screen
@ -136,92 +136,97 @@ public:
#define HEART_LENGTH 40 #define HEART_LENGTH 40
/*! /*!
* @brief * @brief display a singular heart on screen
* @param[] * @param[in] baseVector : pixel coordinates of the heart
* @fn * @fn void drawHeart(const Position& baseVector) const;
*/ */
void drawHeart(const Position& baseVector) const; void drawHeart(const Position& baseVector) const;
/*! /*!
* @brief * @brief display a sprite on screen
* @param[] * @param[in] sprite : sprite to draw
* @fn * @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; void drawSprite(const nsGui::Sprite& sprite, const Position& pos = Position(0, 0)) const;
/*! /*!
* @brief * @brief display a menu button on screen
* @param[] * @param[in] baseVector : pixel coordinates of the button
* @fn * @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); void displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color);
/*! /*!
* @brief * @brief display a menu on screen
* @param[] * @param[in] pos : pixel coordinates of the menu
* @fn * @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); void displayMenu(const Position& pos, Menu& currentMenu);
/*! /*!
* @brief * @brief display text on screen
* @param[] * @param[in] pos : pixel coordinates of the text
* @fn * @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; void displayText(const Position& pos, const string& text, const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const;
/*! /*!
* @brief * @brief display the current screen refresh rate
* @param[] * @param[in] fps : current framerate
* @fn * @fn void drawFPS(unsigned fps) const;
*/ */
void drawFPS(unsigned fps) const; void drawFPS(unsigned fps) const;
/*! /*!
* @brief * @brief show the title screen of the game
* @return * @return the playmode chosen inside the menu
* @fn * @fn PlayMode showInitialMenu();
*/ */
PlayMode showInitialMenu(); PlayMode showInitialMenu();
/*! /*!
* @brief * @brief show the menu after a player lose, or all invader has been defeated
* @return * @return true if the player plays again, else false
* @fn * @fn bool showDeathMenu();
*/ */
bool showDeathMenu(); bool showDeathMenu();
/*! /*!
* @brief * @brief give the height of the screen
* @return * @return the height of the screen in pixel
* @fn * @fn unsigned getScreenHeight() const;
*/ */
unsigned getScreenHeight() const; unsigned getScreenHeight() const;
/*! /*!
* @brief * @brief give the width of the screen
* @return * @return the width of the screen in pixel
* @fn * @fn unsigned getScreenWidth() const;
*/ */
unsigned getScreenWidth() const; unsigned getScreenWidth() const;
/*! /*!
* @brief * @brief clear the screen for a new frame
* @param[] * @fn void startFrame() const;
* @fn
*/ */
void startFrame() const; void startFrame() const;
/*! /*!
* @brief * @brief finish a frame render
* @param[] * @fn void endFrame() const;
* @fn
*/ */
void endFrame() const; void endFrame() const;
/*! /*!
* @brief * @brief display the player name selection menu
* @param[] * @param[in] pID : player id
* @param[out] name : name selected by the player
* @fn * @fn
*/ */
void askPlayerNameMenu(playerID pID, string& name); void askPlayerNameMenu(playerID pID, string& name);
@ -229,36 +234,44 @@ public:
// y will be negative sometimes, so not unsigned // y will be negative sometimes, so not unsigned
/*! /*!
* @brief * @brief display god's bar
* @param[] * @param[in] y : god y pixel position
* @fn * @fn void drawGodBench(int y) const
*/ */
void drawGodBench(int y) const; void drawGodBench(int y) const;
/*! /*!
* @brief * @brief display god's right hand
* @param[] * @param[in] pos : pixel coordiniates of the hand
* @fn * @fn void drawGodRightHand(const Position& pos) const;
*/ */
void drawGodRightHand(const Position& pos) const; void drawGodRightHand(const Position& pos) const;
/*! /*!
* @brief * @brief display god's left hand
* @param[] * @param[in] pos : pixel coordiniates of the hand
* @fn * @fn void drawGodLeftHand(const Position& pos) const;
*/ */
void drawGodLeftHand(const Position& pos) const; void drawGodLeftHand(const Position& pos) const;
/*! /*!
* @brief * @brief display god's face
* @param[] * @param[in] y : god's face y pixel position
* @fn * @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; void drawGodFace(int y, bool angry=false) const;
private: private:
// Explanation for choices : // Explanation for choices :
// non reference output : I don't think we have another choice than a std::move() here // 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<RGBAcolor> mirrorData(const vector<RGBAcolor>& inPixels, unsigned rowSize);
*/
vector<RGBAcolor> mirrorData(const vector<RGBAcolor>& inPixels, unsigned rowSize); vector<RGBAcolor> mirrorData(const vector<RGBAcolor>& inPixels, unsigned rowSize);
}; };

View File

@ -24,7 +24,7 @@ struct Player{
unsigned lives = 3; unsigned lives = 3;
/*! /*!
* @brief * @brief x coordinate of the player
*/ */
unsigned x; unsigned x;
@ -39,7 +39,8 @@ struct Player{
unsigned score=0; unsigned score=0;
/*! /*!
* @brief * @brief counter used for the death animation of players
* undefined once the player is eliminated
*/ */
unsigned deathAnimCounter=0; unsigned deathAnimCounter=0;

View File

@ -10,9 +10,8 @@
* *
*/ */
#include <playMode.h>
#include "pixelManager.h"
#include "mingl/gui/text.h" #include "mingl/gui/text.h"
#include "pixelManager.h"
#include "utils.h" #include "utils.h"
#include "god.h" #include "god.h"
@ -20,7 +19,7 @@ using namespace nsShape;
using namespace nsGui; using namespace nsGui;
PixelManager::PixelManager(MinGL& a) : window(a) { PixelManager::PixelManager(MinGL& win) : window(win) {
window.initGlut(); window.initGlut();
window.initGraphic(); window.initGraphic();
} }
@ -138,11 +137,14 @@ void PixelManager::drawFPS(unsigned fps) const {
vector<RGBAcolor> vector<RGBAcolor>
PixelManager::mirrorData(const vector<nsGraphics::RGBAcolor>& inPixels, unsigned rowSize) { PixelManager::mirrorData(const vector<nsGraphics::RGBAcolor>& inPixels, unsigned rowSize) {
vector<RGBAcolor> outPixels; vector<RGBAcolor> outPixels;
// we reserve size so the vector doesn't dynamically grows
outPixels.reserve(inPixels.size()); outPixels.reserve(inPixels.size());
//for each line of pixel
for(unsigned i=0;i<inPixels.size();i+=rowSize){ for(unsigned rowOffset=0; rowOffset < inPixels.size(); rowOffset+=rowSize){
// for each pixel of that line
for(unsigned j=0;j<rowSize;++j) { for(unsigned j=0;j<rowSize;++j) {
outPixels.push_back(inPixels[i + rowSize - j - 1]); // push back the pixel opposed to this one (still in the same line)
outPixels.push_back(inPixels[rowOffset + rowSize - j - 1]);
} }
} }
return std::move(outPixels); return std::move(outPixels);

View File

@ -123,10 +123,6 @@ void PixelManager::askPlayerNameMenu(playerID pID, string& name) {
exit(0); exit(0);
} }
/**
*
* @return true if the player plays again
*/
bool PixelManager::showDeathMenu() { bool PixelManager::showDeathMenu() {
vector<string> entries {"retry","main menu"}; vector<string> entries {"retry","main menu"};
Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite};

View File

@ -41,9 +41,12 @@ void Game::displayAll(unsigned fps) const {
for(size_t i=0;i<players.size();++i){ for(size_t i=0;i<players.size();++i){
if(players[i].deathAnimCounter%2==0){ if(!players[i].isEliminated()){
pm.drawPlayer(players[i].x, confData.playersWidth, confData.playerDefs[i].color); if(players[i].deathAnimCounter%2==0){
pm.drawPlayer(players[i].x, confData.playersWidth, confData.playerDefs[i].color);
}
} }
// out of the condition, because we still need to display the falling heart
displayHearts(i); displayHearts(i);
} }
} }

View File

@ -23,19 +23,8 @@ Game::Game() : WININIT, pm(window) {
sm.readFile(); sm.readFile();
} }
bool Game::updateColumns(){ bool Game::areThereInvadersLeft(){
while(true){ return grid.validColsNumber() > 0;
if(grid.empty())return true;
if(grid.at(0).hasNoValid()){
grid.erase(grid.begin());
basePos+=confData.invadersSize+confData.invadersDistance;
}else break;
}
while(grid.at(grid.size() - 1).hasNoValid()){
grid.erase(grid.end()-1);
}
return false;
} }
void Game::handleScoreSaving(){ void Game::handleScoreSaving(){

View File

@ -13,6 +13,7 @@
#define ISPRESSED(ID, X) window.isPressed({confData.playerDefs[ID].keys.X, false}) #define ISPRESSED(ID, X) window.isPressed({confData.playerDefs[ID].keys.X, false})
void Game::manageOnePlayer(playerID pID){ void Game::manageOnePlayer(playerID pID){
Player& p = players[pID]; Player& p = players[pID];
if(p.isEliminated())return;
if (ISPRESSED(pID, left)){ if (ISPRESSED(pID, left)){
if(p.x < confData.playersSpeed) p.x = 0; if(p.x < confData.playersSpeed) p.x = 0;
@ -26,7 +27,7 @@ void Game::manageOnePlayer(playerID pID){
if(p.hasDeathAnimation()) { if(p.hasDeathAnimation()) {
++p.deathAnimCounter; ++p.deathAnimCounter;
if (p.deathAnimCounter == 100) { if (p.deathAnimCounter == 75) {
p.deathAnimCounter = 0; p.deathAnimCounter = 0;
} }
}else{ }else{
@ -57,7 +58,7 @@ bool Game::manageInvaders(){
if(fireCooldown==0) { if(fireCooldown==0) {
fireCooldown = confData.invadersFireCooldown + rand() % 60; fireCooldown = confData.invadersFireCooldown + rand() % 60;
unsigned rdCol = grid.randomValid(); unsigned rdCol = grid.randomValidCol();
// fire ! // fire !
missiles.push_back(basePos + Position( missiles.push_back(basePos + Position(
confData.invadersSize * rdCol + confData.invadersDistance * (rdCol + 0.5), confData.invadersSize * rdCol + confData.invadersDistance * (rdCol + 0.5),

View File

@ -35,26 +35,28 @@ bool Game::manageGod() {
++god.counter; ++god.counter;
return false; return false;
} }
// init throw if (areThereInvadersLeft()) {
god.counter = 0; // init throw
god.state = GodState::RETRIEVE1; god.counter = 0;
god.thrownInvPosX = grid.randomValid(); god.state = GodState::RETRIEVE1;
god.thrownInvPosY = grid[god.thrownInvPosX].randomValid(); god.thrownInvPosX = grid.randomValidCol();
god.thrownInvType = InvaderType::NONE; god.thrownInvPosY = grid[god.thrownInvPosX].randomValid();
god.thrownInvType = InvaderType::NONE;
god.thrownTransition.setX(pm.getScreenWidth() - GOD_HAND_DISTANCE - GOD_HAND_SIZE); god.thrownTransition.setX(pm.getScreenWidth() - GOD_HAND_DISTANCE - GOD_HAND_SIZE);
god.thrownTransition.setY(basePos.getY() + INV_GET_POS(god.thrownInvPosY)); god.thrownTransition.setY(basePos.getY() + INV_GET_POS(god.thrownInvPosY));
return false; return false;
}
} }
case GodState::RETRIEVE1: { case GodState::RETRIEVE1: {
if (god.counter < 100) { if (god.counter < 100) {
god.counter += 2; god.counter += 2;
return false; return false;
} }
if (grid.size() > god.thrownInvPosY && grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) { if (grid.size() > god.thrownInvPosY && grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) {
god.thrownInvType = grid[god.thrownInvPosX][god.thrownInvPosY]; god.thrownInvType = grid[god.thrownInvPosX][god.thrownInvPosY];
grid[god.thrownInvPosX][god.thrownInvPosY] = InvaderType::NONE; grid[god.thrownInvPosX][god.thrownInvPosY] = InvaderType::NONE;
updateColumns();
} }
god.state = GodState::RETRIEVE2; god.state = GodState::RETRIEVE2;
return false; return false;

View File

@ -47,15 +47,19 @@ unsigned InvadersColumn::randomValid() const {
throw runtime_error("SHOULD NOT HAPPEN"); throw runtime_error("SHOULD NOT HAPPEN");
} }
unsigned InvadersGrid::randomValid() const { unsigned InvadersGrid::validColsNumber() const {
unsigned validTotal = 0; unsigned validTotal = 0;
for(const InvadersColumn& i : *this){ for(const InvadersColumn& i : *this){
if(!i.hasNoValid())++validTotal; if(!i.hasNoValid())++validTotal;
} }
return validTotal;
}
unsigned rd = rand() % validTotal; unsigned InvadersGrid::randomValidCol() const {
unsigned rd = rand() % validColsNumber();
unsigned validIndex = 0; unsigned validIndex = 0;
for(unsigned i=0;i<size();++i){ for(unsigned i=0;i<size();++i){