save commit
This commit is contained in:
parent
7b2eda8549
commit
15dc67c348
13
README
13
README
@ -7,7 +7,7 @@ Les guards sont de cette forme : GUARD_<filename>_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<InvaderType, InvaderTypeDef> invadersDef; comment est ce que j'explique une map xD?
|
||||
```
|
@ -87,7 +87,7 @@ struct ConfigData {
|
||||
unsigned invadersFireCooldown;
|
||||
|
||||
/*!
|
||||
* @brief
|
||||
* @brief link between an invader type, and its data
|
||||
*/
|
||||
map<InvaderType, InvaderTypeDef> invadersDef;
|
||||
|
||||
|
@ -114,7 +114,7 @@ private:
|
||||
* @return true if there are no more invaders in the grid
|
||||
* @fn bool updateColumns();
|
||||
*/
|
||||
bool updateColumns();
|
||||
bool areThereInvadersLeft();
|
||||
|
||||
/*!
|
||||
* @brief Asks the player(s) name(s) and write their score to the score file
|
||||
|
@ -69,7 +69,8 @@ public:
|
||||
* @return
|
||||
* @fn
|
||||
*/
|
||||
unsigned randomValid() const;
|
||||
}; // InvadersGrid
|
||||
unsigned validColsNumber() const;
|
||||
unsigned randomValidCol() const;
|
||||
};
|
||||
|
||||
#endif
|
@ -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<RGBAcolor> mirrorData(const vector<RGBAcolor>& inPixels, unsigned rowSize);
|
||||
*/
|
||||
vector<RGBAcolor> mirrorData(const vector<RGBAcolor>& inPixels, unsigned rowSize);
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -10,9 +10,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <playMode.h>
|
||||
#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<RGBAcolor>
|
||||
PixelManager::mirrorData(const vector<nsGraphics::RGBAcolor>& inPixels, unsigned rowSize) {
|
||||
vector<RGBAcolor> outPixels;
|
||||
// we reserve size so the vector doesn't dynamically grows
|
||||
outPixels.reserve(inPixels.size());
|
||||
|
||||
for(unsigned i=0;i<inPixels.size();i+=rowSize){
|
||||
//for each line of pixel
|
||||
for(unsigned rowOffset=0; rowOffset < inPixels.size(); rowOffset+=rowSize){
|
||||
// for each pixel of that line
|
||||
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);
|
||||
|
@ -123,10 +123,6 @@ void PixelManager::askPlayerNameMenu(playerID pID, string& name) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the player plays again
|
||||
*/
|
||||
bool PixelManager::showDeathMenu() {
|
||||
vector<string> entries {"retry","main menu"};
|
||||
Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite};
|
||||
|
@ -41,9 +41,12 @@ void Game::displayAll(unsigned fps) const {
|
||||
|
||||
|
||||
for(size_t i=0;i<players.size();++i){
|
||||
if(players[i].deathAnimCounter%2==0){
|
||||
pm.drawPlayer(players[i].x, confData.playersWidth, confData.playerDefs[i].color);
|
||||
if(!players[i].isEliminated()){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -23,19 +23,8 @@ Game::Game() : WININIT, pm(window) {
|
||||
sm.readFile();
|
||||
}
|
||||
|
||||
bool Game::updateColumns(){
|
||||
while(true){
|
||||
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;
|
||||
bool Game::areThereInvadersLeft(){
|
||||
return grid.validColsNumber() > 0;
|
||||
}
|
||||
|
||||
void Game::handleScoreSaving(){
|
||||
|
@ -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),
|
||||
|
@ -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;
|
@ -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<size();++i){
|
||||
|
Loading…
Reference in New Issue
Block a user