Merge remote-tracking branch 'origin/master'

This commit is contained in:
Thomas 2022-01-09 14:48:59 +01:00
commit 338df7af3d
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
26 changed files with 945 additions and 48 deletions

23
README
View File

@ -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 : 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)' - 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<InvaderType, InvaderTypeDef> invadersDef; comment est ce que j'explique une map xD?
```

View File

@ -1,6 +1,6 @@
# General configuration # General configuration
general: general:
maxFPS: 50 maxFPS: 30
# Players config # Players config
players: players:
@ -25,7 +25,7 @@ players:
# Enemies config # Enemies config
invaders: invaders:
fireCooldown: 20 fireCooldown: 20
size: 25 size: 40
speed: 7 speed: 7
distance: 10 # distance in pixels between invaders distance: 10 # distance in pixels between invaders
@ -54,6 +54,6 @@ projectiles:
# Grid definition # Grid definition
# You can add more rows, make rows longer and add spaces # You can add more rows, make rows longer and add spaces
grid: grid:
- "AAAAAAAAAAAA" - " "
- "BBBBBBBBBBBB" - " "
- "CCCCCCCCCCCC" - "B"

View File

@ -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 #ifndef GUARD_CONFIGDATA_H
#define GUARD_CONFIGDATA_H #define GUARD_CONFIGDATA_H
@ -9,37 +19,116 @@
typedef string configKey; typedef string configKey;
/*!
* @struct ConfigData
* @brief this struct stores all relevant data from the configuration file
*/
struct ConfigData { struct ConfigData {
/*!
* @brief maximum framerate at which the game will run
*/
unsigned maxFPS; unsigned maxFPS;
/*!
* @brief Invader type matrix
*/
InvadersGrid grid; InvadersGrid grid;
/*!
* @brief players horizontal start position
*/
unsigned startXPosition; unsigned startXPosition;
/*!
* @brief player movement speed
*/
unsigned playersSpeed; unsigned playersSpeed;
/*!
* @brief player horizontal size in pixel
*/
unsigned playersWidth; unsigned playersWidth;
/*!
* @brief player shooting wait time
*/
unsigned playersFireCooldown; unsigned playersFireCooldown;
/*!
* @brief player life points
*/
unsigned playersLives; unsigned playersLives;
/*!
* @brief player key configuration
*/
vector<PlayerDef> playerDefs; vector<PlayerDef> playerDefs;
/*!
* @brief invader movement speed
*/
unsigned invadersSpeed; unsigned invadersSpeed;
/*!
* @brief invader radius size in pixel
*/
unsigned invadersSize; unsigned invadersSize;
/*!
* @brief distance in pixel between two invader
*/
unsigned invadersDistance; unsigned invadersDistance;
/*!
* @brief wait time between two invader missile
*/
unsigned invadersFireCooldown; unsigned invadersFireCooldown;
/*!
* @brief
*/
map<InvaderType, InvaderTypeDef> invadersDef; map<InvaderType, InvaderTypeDef> invadersDef;
/*!
* @brief invaders missiles width in pixel
*/
unsigned missilesWidth; 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; unsigned missilesSpeed;
/*!
* @brief invaders missiles color
*/
nsGraphics::RGBAcolor missilesColor; nsGraphics::RGBAcolor missilesColor;
/*!
* @brief players torpedos width in pixel
*/
unsigned torpedosWidth; 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; unsigned torpedosSpeed;
/*!
* @brief players torpedos color
*/
nsGraphics::RGBAcolor torpedosColor; nsGraphics::RGBAcolor torpedosColor;
}; };

View File

@ -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 #ifndef GUARD_GAME_H
#define GUARD_GAME_H #define GUARD_GAME_H
#include <vector> #include <vector>
@ -15,63 +27,240 @@
using namespace std; using namespace std;
/*!
* @class Game
* @brief Main game class
*/
class Game { class Game {
private: private:
/*!
* @brief the MinGL window in which the game will be drawn into
*/
MinGL window; MinGL window;
/*!
* @brief PixelManager : Class that contains and draws all the data that will be drawn on screen
*/
PixelManager pm; PixelManager pm;
/*!
* @brief ConfigData : Struct that stores all the relevant data read from the configuration file
*/
ConfigData confData; ConfigData confData;
/*!
* @brief
*/
ScoresManager sm; ScoresManager sm;
/*!
* @brief Special entity : God
*/
God god; God god;
/*!
* @brief base position for game display
*/
Position basePos; Position basePos;
/*!
* @brief Invader posision and type matrix
*/
InvadersGrid grid; InvadersGrid grid;
/*!
* @brief Invader scroll direction - True = right , False = left
*/
bool direction = true; bool direction = true;
/*!
* @brief list of postion of all missiles shot by the invaders
*/
vector<missile> missiles; vector<missile> missiles;
/*!
* @brief list of postion of all torpedos shot by the player(s)
*/
vector<Torpedo> torpedos; vector<Torpedo> torpedos;
/*!
* @brief Define the current type of the game
*/
PlayMode playMode; PlayMode playMode;
/*!
* @brief list of all player data
*/
vector<Player> players; vector<Player> players;
// invaders related variables // invaders related variables
/*!
* @brief cooldown between two invader shot in milliseconds
*/
unsigned fireCooldown=120; unsigned fireCooldown=120;
// basic methods // basic methods
/*!
* @brief Set or reset all the setting for a new game
* @fn void initGame();
*/
void initGame(); void initGame();
/*!
* @brief
* @return true if there are no more invaders in the grid
* @fn bool updateColumns();
*/
bool updateColumns(); bool updateColumns();
/*!
* @brief Asks the player(s) name(s) and write their score to the score file
* @fn void handleScoreSaving();
*/
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; Position invIndexToPos(unsigned x, unsigned y) const;
// drawing methods // 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; void displayAll(unsigned fps) const;
/*!
* @brief display God related objets
* @fn void displayGod() const;
*/
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; void displayInvader(const Position& basePos, InvaderType type) const;
/*!
* @brief displays a player's remaining lives
* @fn void displayHearts(playerID) const;
*/
void displayHearts(playerID) const; void displayHearts(playerID) const;
// managers // managers
/*!
* @brief Calls the function 'ManageOnePlayer' for all players in player list
* @fn void managePlayers();
*/
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(); bool manageInvaders();
// collision things // collision things
/*!
* @brief Removes torpedo and missiles that are colliding
* @fn void remCollidingProjectiles();
*/
void remCollidingProjectiles(); void remCollidingProjectiles();
/*!
* @brief Makes all missiles go downward
* @fn void moveMissiles();
*/
void moveMissiles(); void moveMissiles();
/*!
* @brief Makes all torpedos go upward
* @fn void moveTorpedos();
*/
void moveTorpedos(); void moveTorpedos();
/*!
* @brief
* @return
* @fn
*/
bool checkMissilesAndPlayers(); bool checkMissilesAndPlayers();
/*!
* @brief
* @return
* @fn
*/
bool checkTorpedosAndInvaders(); bool checkTorpedosAndInvaders();
/*!
* @brief
* @return
* @fn
*/
bool invadersTouchPlayer() const; bool invadersTouchPlayer() const;
// god things // god things
/*!
*
*/
void awakeGod(); void awakeGod();
/*!
* @brief
* @return
* @fn
*/
bool manageGod(); bool manageGod();
public: public:
// in case someone wants to mess with the code, here's a minimal API, costs nothing to us // in case someone wants to mess with the code, here's a minimal API, costs nothing to us
/*!
*
*/
Game(); Game();
/*!
*
*/
void managedGames(); void managedGames();
/*!
* @brief
* @return
* @fn
*/
WinValue enterGameLoop(); WinValue enterGameLoop();
/*!
* @brief
* @return
* @fn
*/
bool reloadConfig(); bool reloadConfig();
}; };

View File

@ -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 #ifndef GUARD_GOD_H
#define GUARD_GOD_H #define GUARD_GOD_H
#include "utils.h" #include "utils.h"
#include "invadersGrid.h" #include "invadersGrid.h"
/*!
* @brief
*/
enum class GodState{ enum class GodState{
NONE, NONE,
AWAKE, AWAKE,
@ -13,30 +26,69 @@ enum class GodState{
THROW, THROW,
YOLO, YOLO,
}; };
// I don't want to put that in config, I feel like it would be useless and overkill at this point // 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_BENCH_SIZE 64
#define GOD_HAND_SIZE 64 #define GOD_HAND_SIZE 64
#define GOD_HAND_DISTANCE 100 #define GOD_HAND_DISTANCE 100
/* /*!
* Hand position is determined * Hand position is determined
*/ */
/*!
* @class God
* @brief
*/
class God{ class God{
public: public:
/*!
* @brief
*/
GodState state; GodState state;
/*!
* @brief
*/
unsigned counter; unsigned counter;
// we do not use a Position because it is used for pixel X and Y // we do not use a Position because it is used for pixel X and Y
/*!
* @brief
*/
unsigned thrownInvPosX; unsigned thrownInvPosX;
/*!
* @brief
*/
unsigned thrownInvPosY; unsigned thrownInvPosY;
/*!
* @brief
*/
InvaderType thrownInvType; InvaderType thrownInvType;
/*!
* @brief
*/
Position thrownVector; Position thrownVector;
/*!
* @brief
*/
Position thrownTransition; Position thrownTransition;
/*!
* @brief
* @param[in] screenWidth :
* @return
* @fn Position getRightHandPos(unsigned screenWidth) const;
*/
Position getRightHandPos(unsigned screenWidth) const; Position getRightHandPos(unsigned screenWidth) const;
}; };

View File

@ -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 #ifndef GUARD_INVADERDEF_H
#define GUARD_INVADERDEF_H #define GUARD_INVADERDEF_H
#include "mingl/graphics/rgbacolor.h" #include "mingl/graphics/rgbacolor.h"
#include "utils.h" #include "utils.h"
/*!
* @struct InvaderTypeDef
* @brief defines an invader type
*/
struct InvaderTypeDef { struct InvaderTypeDef {
/*!
* @brief color of the invader type
*/
nsGraphics::RGBAcolor color; nsGraphics::RGBAcolor color;
/*!
* @brief points given to the player by defeating this invader type
*/
unsigned points; unsigned points;
}; };

View File

@ -1,3 +1,14 @@
/*!
*
* @file invaderGrid.h
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief invader matrix structure
*
*/
#ifndef GUARD_INVADERSGRID_H #ifndef GUARD_INVADERSGRID_H
#define GUARD_INVADERSGRID_H #define GUARD_INVADERSGRID_H
@ -5,22 +16,60 @@
using namespace std; using namespace std;
/*!
* @brief List of all invader type
*/
enum class InvaderType { enum class InvaderType {
TYPEA, TYPEA,
TYPEB, TYPEB,
TYPEC, TYPEC,
NONE, NONE,
}; };
/*!
* @class InvadersColumn
* @brief Column of invader
*/
class InvadersColumn : public vector<InvaderType>{ class InvadersColumn : public vector<InvaderType>{
public: public:
// idk why CLion says this is not implemented, but it is // 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; 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; unsigned getOutterInvader() const;
/*!
* @brief
* @return
* @fn
*/
unsigned randomValid() const; unsigned randomValid() const;
}; }; // class InvadersColumn
/*!
* @class InvadersColumn
* @brief Column of invader
*/
class InvadersGrid : public vector<InvadersColumn>{ class InvadersGrid : public vector<InvadersColumn>{
public: public:
/*!
* @brief List of all invader type
* @return
* @fn
*/
unsigned randomValid() const; unsigned randomValid() const;
}; }; // InvadersGrid
#endif #endif

View File

@ -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 #ifndef GUARD_MENU_H
#define GUARD_MENU_H #define GUARD_MENU_H
#include"vector" #include"vector"
#include"string" #include"string"
/*!
* @struct Menu
* @brief menu stuct
*/
struct Menu{ struct Menu{
/*!
* @brief list of all menu options
*/
vector<string> entries; vector<string> entries;
/*!
* @brief index of currently selected menu option
*/
size_t currentValue = 0; size_t currentValue = 0;
/*!
* @brief color of currently selected menu option
*/
nsGraphics::RGBAcolor selectedColor; nsGraphics::RGBAcolor selectedColor;
/*!
* @brief color of unelected menu option
*/
nsGraphics::RGBAcolor unSelectedColor; nsGraphics::RGBAcolor unSelectedColor;
}; };

View File

@ -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 #ifndef GUARD_PIXELMANAGER_H
#define GUARD_PIXELMANAGER_H #define GUARD_PIXELMANAGER_H
@ -17,6 +29,11 @@ using namespace std;
#define MIRROR(SP) mirrorData((SP).getPixelData(), (SP).getRowSize()), (SP).getRowSize() #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{ class PixelManager{
public: public:
MinGL& window; 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) * (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"}; nsGui::Sprite logo{"assets/logo.si2"};
/*!
* @brief
*/
nsGui::Sprite gameBackground{"assets/game_background.si2"}; nsGui::Sprite gameBackground{"assets/game_background.si2"};
/*!
* @brief
*/
nsGui::Sprite menuBackground{"assets/menu_background.si2"}; nsGui::Sprite menuBackground{"assets/menu_background.si2"};
/*!
* @brief
*/
nsGui::Sprite rightHand{"assets/hand_open.si2"}; nsGui::Sprite rightHand{"assets/hand_open.si2"};
/*!
* @brief
*/
nsGui::Sprite leftHand{MIRROR(rightHand)}; nsGui::Sprite leftHand{MIRROR(rightHand)};
/*!
* @brief
* @param[]
* @fn
*/
explicit PixelManager(MinGL&); 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; 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; 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; 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; 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; 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; void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const;
#define HEART_LENGTH 40 #define HEART_LENGTH 40
/*!
* @brief
* @param[]
* @fn
*/
void drawHeart(const Position& baseVector) const; void drawHeart(const Position& baseVector) const;
/*!
* @brief
* @param[]
* @fn
*/
void drawSprite(const nsGui::Sprite& sprite, const Position& pos) const; void drawSprite(const nsGui::Sprite& sprite, const Position& pos) const;
/*!
* @brief
* @param[]
* @fn
*/
void displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color); 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); void displayMenu(const Position& pos, Menu& currentMenu);
/*!
* @brief
* @param[]
* @fn
*/
void drawGameBackground() const; void drawGameBackground() const;
/*!
* @brief
* @param[]
* @fn
*/
void drawMenuBackground() const; 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; void drawFPS(unsigned fps) const;
PlayMode showInitialMenu(); PlayMode showInitialMenu();
bool showDeathMenu() const; PlayMode showDeathMenu();
unsigned getScreenHeight() const; unsigned getScreenHeight() const;
unsigned getScreenWidth() const; unsigned getScreenWidth() const;
/*!
* @brief
* @param[]
* @fn
*/
void startFrame() const; void startFrame() const;
/*!
* @brief
* @param[]
* @fn
*/
void endFrame() const; void endFrame() const;
/*!
* @brief
* @param[]
* @fn
*/
void askPlayerNameMenu(playerID pID, string& name) const; void askPlayerNameMenu(playerID pID, string& name) const;
// y will be negative sometimes, so not unsigned // y will be negative sometimes, so not unsigned
/*!
* @brief
* @param[]
* @fn
*/
void drawGodBench(int y) const; void drawGodBench(int y) const;
/*!
* @brief
* @param[]
* @fn
*/
void drawGodRightHand(const Position& pos) const; void drawGodRightHand(const Position& pos) const;
/*!
* @brief
* @param[]
* @fn
*/
void drawGodLeftHand(const Position& pos) const; void drawGodLeftHand(const Position& pos) const;
/*!
* @brief
* @param[]
* @fn
*/
void drawGodFace(int y, bool angry=false) const; void drawGodFace(int y, bool angry=false) const;
private: private:

View File

@ -1,6 +1,19 @@
/*!
*
* @file playMode.h
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief game mode options
*
*/
#ifndef GUARD_PLAYMODE_H #ifndef GUARD_PLAYMODE_H
#define GUARD_PLAYMODE_H #define GUARD_PLAYMODE_H
/*!
* @brief List of all game playmode
*/
enum class PlayMode { enum class PlayMode {
NONE, NONE,
SINGLE, SINGLE,

View File

@ -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 #ifndef GUARD_PLAYER_H
#define GUARD_PLAYER_H #define GUARD_PLAYER_H
/*!
* @struct Player
* @brief player data structure
*/
struct Player{ struct Player{
/*!
* @brief player life points
*/
unsigned lives = 3; unsigned lives = 3;
/*!
* @brief
*/
unsigned x; unsigned x;
/*!
* @brief player's unique identidier
*/
unsigned id; unsigned id;
/*!
* @brief player's personal score
*/
unsigned score=0; unsigned score=0;
/*!
* @brief
*/
unsigned deathAnimCounter=0; unsigned deathAnimCounter=0;
/*!
* @brief player's shooting cooldown
*/
unsigned fireCooldown=0; unsigned fireCooldown=0;
// TODO remove ? // TODO remove ?

View File

@ -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 #ifndef GUARD_PLAYER_DEF_H
#define GUARD_PLAYER_DEF_H #define GUARD_PLAYER_DEF_H
#include "mingl/graphics/rgbacolor.h" #include "mingl/graphics/rgbacolor.h"
/*!
* @struct PlayerKeys
* @brief player key configuration
*/
struct PlayerKeys { struct PlayerKeys {
/*!
* @brief key to move right
*/
char right; char right;
/*!
* @brief key to move left
*/
char left; char left;
/*!
* @brief key to shoot
*/
char shoot; char shoot;
}; };
/*!
* @struct PlayerDef
* @brief player data, contains colors and key configuration
*/
struct PlayerDef { struct PlayerDef {
/*!
* @brief player color
*/
nsGraphics::RGBAcolor color; nsGraphics::RGBAcolor color;
/*!
* @brief player key configuration
*/
PlayerKeys keys; PlayerKeys keys;
}; };

View File

@ -1,3 +1,13 @@
/*!
*
* @file projectiles.h
* @author SIMAILA Djalim
* @date January 2022
* @version 1.0
* @brief projectiles data storage
*
*/
#ifndef GUARD_PROJECTILES_H #ifndef GUARD_PROJECTILES_H
#define GUARD_PROJECTILES_H #define GUARD_PROJECTILES_H
@ -5,9 +15,24 @@
typedef Position missile; typedef Position missile;
/*!
* @class Torpedo
* @brief player's projectiles
*/
class Torpedo : public Position { class Torpedo : public Position {
public: public:
/*!
* @brief id of the player that shot the torpedo
*/
playerID owner; 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); Torpedo(int x, int y, playerID owner);
}; };

View File

@ -1,3 +1,13 @@
/*!
*
* @file ScoreManager.h
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief Score file manager
*
*/
#ifndef GUARD_SCORESMANAGER_H #ifndef GUARD_SCORESMANAGER_H
#define GUARD_SCORESMANAGER_H #define GUARD_SCORESMANAGER_H

View File

@ -1,6 +1,19 @@
/*!
*
* @file configManagement.cpp
* @author RUBINI Thomas
* @author SIMAILA Djalim
* @date January 2022
* @version 1.0
* @brief config parser
*
*/
#include <fstream> #include <fstream>
#include "game.h" #include "game.h"
// you will MOVE THIS OUT OF THIS FILE
class ConfigBuilder{ class ConfigBuilder{
public: public:
ConfigData collectedData; ConfigData collectedData;

View File

@ -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 <playMode.h> #include <playMode.h>
#include "pixelManager.h" #include "pixelManager.h"
#include "mingl/gui/text.h" #include "mingl/gui/text.h"

View File

@ -1,3 +1,14 @@
/*!
*
* @file drawMenu.cpp
* @author SIMAILA Djalim
* @author FABRE Lucas
* @date January 2022
* @version 1.0
* @brief menu drawing functions
*
*/
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <playMode.h> #include <playMode.h>
@ -10,9 +21,9 @@ using namespace nsShape;
using namespace nsGraphics; using namespace nsGraphics;
void PixelManager::displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color){ 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(baseVector, Position(180, 40)+baseVector, KGray);
window << Rectangle(Position(188, 428)+baseVector, Position(312, 467)+baseVector, KBlack); window << Rectangle(baseVector+Position(2,2), Position(178, 38)+baseVector, KBlack);
window << nsGui::Text(Vec2D(200, 450)+baseVector, text, color); window << nsGui::Text(baseVector+Position(10,22), text, color);
} }
void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){
@ -30,17 +41,17 @@ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){
} }
PlayMode PixelManager::showInitialMenu(){ PlayMode PixelManager::showInitialMenu(){
vector<string> entries {"single player","multi player (local)","EXIT"}; vector<string> entries {"single player","multi player (local)","exit"};
Menu initial {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; Menu initial {entries,0,nsGraphics::KRed,nsGraphics::KWhite};
const unsigned xOffset = getScreenHeight() / 2 ; const unsigned xOffset = getScreenHeight() / 2 ;
const unsigned yOffset = getScreenWidth() / 2; const unsigned yOffset = getScreenWidth() / 2 - 90;
chrono::milliseconds waitTime = chrono::milliseconds(100); chrono::milliseconds waitTime = chrono::milliseconds(100);
while(true){ while(true){
displayMenu(Position(350,0),initial); displayMenu(Position(yOffset,xOffset),initial);
// go down // go down
if (window.isPressed({'s', false})){ if (window.isPressed({'s', false})){
++initial.currentValue; ++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); this_thread::sleep_for(waitTime);
} }
// go up // go up
@ -48,7 +59,7 @@ PlayMode PixelManager::showInitialMenu(){
if (initial.currentValue == 0) initial.currentValue = initial.entries.size()-1; if (initial.currentValue == 0) initial.currentValue = initial.entries.size()-1;
else --initial.currentValue; else --initial.currentValue;
this_thread::sleep_for(waitTime); this_thread::sleep_for(waitTime);
} }// select option
else if (window.isPressed({13, false})){ else if (window.isPressed({13, false})){
switch(initial.currentValue){ switch(initial.currentValue){
case 0: case 0:
@ -57,14 +68,45 @@ PlayMode PixelManager::showInitialMenu(){
return PlayMode::TWO_LOCAL; return PlayMode::TWO_LOCAL;
case 2: case 2:
return PlayMode::EXIT; return PlayMode::EXIT;
default:
return PlayMode::SINGLE;
} }
} }
} }
} }
bool PixelManager::showDeathMenu() const { PlayMode PixelManager::showDeathMenu() {
return true; vector<string> 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;
}
}
}
} }

View File

@ -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" #include "game.h"

View File

@ -1,10 +1,20 @@
/*!
*
* @file gameBasics.cpp
* @author RUBINI Thomas
* @author SIMAILA Djalim
* @date January 2022
* @version 1.0
* @brief game basic mechanisms
*
*/
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include "game.h" #include "game.h"
#include "playMode.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) { Game::Game() : WININIT, pm(window) {
if(!reloadConfig()){ if(!reloadConfig()){
@ -13,10 +23,6 @@ Game::Game() : WININIT, pm(window) {
sm.readFile(); sm.readFile();
} }
/**
*
* @return true if there are no more invaders in the grid
*/
bool Game::updateColumns(){ bool Game::updateColumns(){
while(true){ while(true){
if(grid.empty())return true; if(grid.empty())return true;
@ -59,14 +65,11 @@ void Game::managedGames() {
enterGameLoop(); // will read the playMode enterGameLoop(); // will read the playMode
handleScoreSaving(); handleScoreSaving();
cout << "END OF GAME" << endl; cout << "END OF GAME" << endl;
break; // TODO remove playMode = pm.showDeathMenu();
if(!pm.showDeathMenu()) playMode = PlayMode::NONE; // back to the main menu
} }
} }
} }
// we assume the game has been played before, and so we need to clean used members // we assume the game has been played before, and so we need to clean used members
void Game::initGame(){ void Game::initGame(){
grid = confData.grid; // will copy the grid grid = confData.grid; // will copy the grid

View File

@ -1,3 +1,13 @@
/*!
*
* @file gameBasics.cpp
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief game basic mechanisms
*
*/
#include "game.h" #include "game.h"
#define ISPRESSED(ID, X) window.isPressed({confData.playerDefs[ID].keys.X, false}) #define ISPRESSED(ID, X) window.isPressed({confData.playerDefs[ID].keys.X, false})

View File

@ -1,3 +1,13 @@
/*!
*
* @file gameBasics.cpp
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief god's implementation
*
*/
#include "game.h" #include "game.h"
void Game::awakeGod() { void Game::awakeGod() {

View File

@ -1,9 +1,20 @@
/*!
*
* @file invaderGrids.h
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief invader matrix structure
*
*/
#include<invadersGrid.h> #include<invadersGrid.h>
#include<iostream> #include<iostream>
bool InvadersColumn::hasNoValid() const { bool InvadersColumn::hasNoValid() const {
return getOutterInvader()==size(); return getOutterInvader()==size();
} }
unsigned InvadersColumn::getOutterInvader() const { unsigned InvadersColumn::getOutterInvader() const {
unsigned i=size(); unsigned i=size();
while(i>0){ while(i>0){

View File

@ -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 <iostream> #include <iostream>
#include "game.h" #include "game.h"
using namespace std; using namespace std;

View File

@ -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" #include "player.h"
bool Player::isPlaying() const { bool Player::isPlaying() const {

View File

@ -1,3 +1,12 @@
/*!
*
* @file projectiles.cpp
* @author SIMAILA Djalim
* @date January 2022
* @version 1.0
* @brief projectiles data storage
*
*/
#include "projectiles.h" #include "projectiles.h"
Torpedo::Torpedo(int x, int y, playerID owner) : Position(x, y) { Torpedo::Torpedo(int x, int y, playerID owner) : Position(x, y) {

View File

@ -1,3 +1,13 @@
/*!
*
* @file ScoreManager.cpp
* @author RUBINI Thomas
* @date January 2022
* @version 1.0
* @brief Score file manager
*
*/
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>