diff --git a/QUESTIONS.md b/QUESTIONS.md index f4424dd..191fc79 100644 --- a/QUESTIONS.md +++ b/QUESTIONS.md @@ -9,4 +9,5 @@ Questions que je (Thomas Rubini) voudrais poser - Que pensez-vous de la sémantique de déplacement, plutot que la référence constante ? - Est-ce qu'on doit forcément utiliser const pour des valeurs primitives (int, float...) qu'on ne touche pas en paramètres de fonction ? - Est-ce que vouloir faire des structures optimisées (pas de redondance de mémoire) est une bonne chose, ou pas importa,t ? -- Pour import MinGL, il vaut mieux utiliser "" ou <> ? \ No newline at end of file +- Pour import MinGL, il vaut mieux utiliser "" ou <> ? +- copier ou ref constante pour Position (Vec2D) ? \ No newline at end of file diff --git a/assets/hand_closed.png b/assets/hand_closed.png new file mode 100644 index 0000000..bc73786 Binary files /dev/null and b/assets/hand_closed.png differ diff --git a/assets/hand_open.png b/assets/hand_open.png new file mode 100644 index 0000000..bc73786 Binary files /dev/null and b/assets/hand_open.png differ diff --git a/headers/game.h b/headers/game.h index 58b8229..ac625ae 100644 --- a/headers/game.h +++ b/headers/game.h @@ -10,6 +10,7 @@ #include "configData.h" #include "projectiles.h" #include "scoresManager.h" +#include "god.h" using namespace std; @@ -19,6 +20,7 @@ private: PixelManager pm; ConfigData confData; ScoresManager sm; + God god; Position basePos; InvadersGrid grid; @@ -34,10 +36,15 @@ private: unsigned fireCooldown=120; // basic methods - void display(); void updateColumns(); void handleScoreSaving(); + // drawing methods + void display(); + void displayGod(); + void displayInvader(const Position& basePos, unsigned size, InvaderType type); + + // managers void managePlayers(); void manageOnePlayer(unsigned); @@ -51,6 +58,10 @@ private: bool checkTorpedosAndInvaders(); bool invadersTouchPlayer(); + // god things + void manageGod(); + void _manageGod_retrieve(bool back); + public: // in case someone wants to mess with the code, here's a minimal API, costs nothing to us Game(); diff --git a/headers/god.h b/headers/god.h new file mode 100644 index 0000000..1195f7f --- /dev/null +++ b/headers/god.h @@ -0,0 +1,37 @@ +#ifndef GUARD_GOD_H +#define GUARD_GOD_H + +#include "utils.h" + +enum class GodState{ + NONE, + LOAD, + WAIT, + RETRIEVE1, + RETRIEVE2, + THROW, +}; +// 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{ +public: + GodState state; + unsigned counter; + + Position throwedInvPos; + InvaderType thrownInvType; + Position thrownVector; + Position thrownTransition; + +}; + +#endif diff --git a/headers/pixelManager.h b/headers/pixelManager.h index b41f56b..0d9a94b 100644 --- a/headers/pixelManager.h +++ b/headers/pixelManager.h @@ -11,6 +11,7 @@ #include "utils.h" using namespace std; +using namespace nsGraphics; class PixelManager{ public: @@ -19,12 +20,13 @@ public: nsGui::Sprite background = nsGui::Sprite("./assets/bg.sl2"); // you cant create an empty sprite for some reasons explicit PixelManager(MinGL&); - void drawInvader1(const nsGraphics::Vec2D& baseVector, unsigned size); - void drawInvader2(const nsGraphics::Vec2D& baseVector, unsigned size); - void drawInvader3(const nsGraphics::Vec2D& baseVector, unsigned size); - void drawPlayer(const unsigned x, unsigned width, const nsGraphics::RGBAcolor &color); - void drawTorpedo(const nsGraphics::Vec2D& baseVector, unsigned width, const nsGraphics::RGBAcolor& color); - void drawMissile(const nsGraphics::Vec2D& baseVector, unsigned width, const nsGraphics::RGBAcolor& color); + + void drawInvaderA(const Position& baseVector, unsigned size, RGBAcolor& color); + void drawInvaderB(const Position& baseVector, unsigned size, RGBAcolor& color); + void drawInvaderC(const Position& baseVector, unsigned size, RGBAcolor& color); + void drawPlayer(const unsigned x, unsigned width, const nsGraphics::RGBAcolor& color); + void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color); + void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color); void drawBackground(); unsigned showInitialMenu(); @@ -36,6 +38,11 @@ public: void askPlayerNameMenu(playerID pID, string& name); + // y will be negative sometimes, so not unsigned + void displayGodBench(int y); + + void displayGodRightHand(const Position& pos); + void displayGodLeftHand(const Position& pos); }; diff --git a/headers/utils.h b/headers/utils.h index a944976..1c35710 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -7,6 +7,9 @@ // hardcoded values #define PLAYER_HEIGHT 100 #define PROJ_LENGTH_FACTOR 2 +// TODO utiliser ca de partout +// ou alors faire une method dans Game ? +#define INV_POS(i) confData.invadersSize*(i)+confData.invadersDistance*(i) enum class WinValue{ NOBODY, // should never be used @@ -27,7 +30,7 @@ public: size_t getOutterInvader(); }; typedef vector InvadersGrid; -typedef nsGraphics::Vec2D Position; +typedef nsGraphics::Vec2D Position; // in case we need to ad dmore methods, we defined our own type typedef unsigned playerID; // 0 for player 1, 1 for player 2 // didn't want to use Position because of the semantic with x and y diff --git a/scores.kus b/scores.kus index 019cf10..af13bd1 100644 --- a/scores.kus +++ b/scores.kus @@ -1,5 +1,6 @@ -1722516557529414056 +13651974094361129891 Thomas,1000 Thomas,0 Thomas,0 Thomas,0 +Thomas,0 diff --git a/src/game/display.cpp b/src/game/display.cpp new file mode 100644 index 0000000..27690b7 --- /dev/null +++ b/src/game/display.cpp @@ -0,0 +1,50 @@ +#include "game.h" + + +/** Displays the screen once, and returns + * + */ +void Game::display() { + pm.drawBackground(); + for (unsigned i = 0; i < this->grid.size(); ++i){ + for (unsigned j = 0; j < this->grid[i].size(); ++j){ + Position vec( + basePos.getX() + i * confData.invadersSize + i * confData.invadersDistance, + basePos.getY() + j * confData.invadersSize + j * confData.invadersDistance + ); + displayInvader(vec, confData.invadersSize, grid[i][j]); + } + } + + for(missile& miss : missiles){ + pm.drawMissile(miss, confData.missilesWidth, confData.missilesColor); + } + for(torpedo& tor : torpedos){ + pm.drawTorpedo(tor, confData.torpedosWidth, confData.torpedosColor); + } + + for(size_t i=0;igrid.size(); ++i){ - for (unsigned j = 0; j < this->grid[i].size(); ++j){ - nsGraphics::Vec2D vec( - basePos.getX() + i * confData.invadersSize + i * confData.invadersDistance, - basePos.getY() + j * confData.invadersSize + j * confData.invadersDistance - ); - switch(grid[i][j]){ - case InvaderType::TYPEA:{ - pm.drawInvader1(vec, confData.invadersSize); - break; - } - case InvaderType::TYPEB:{ - pm.drawInvader2(vec, confData.invadersSize); - break; - } - case InvaderType::TYPEC:{ - pm.drawInvader3(vec, confData.invadersSize); - break; - } - } - } - } - - for(missile& miss : missiles){ - pm.drawMissile(miss, confData.missilesWidth, confData.missilesColor); - } - for(torpedo& tor : torpedos){ - pm.drawTorpedo(tor, confData.torpedosWidth, confData.torpedosColor); - } - - for(size_t i=0;i