SuperSpaceInvaderTurboApoca.../headers/game.h
2022-01-09 04:24:25 +01:00

267 lines
4.7 KiB
C++

/**
*
* @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 <vector>
#include "mingl/mingl.h"
#include "pixelManager.h"
#include "utils.h"
#include "playerDef.h"
#include "player.h"
#include "playMode.h"
#include "configData.h"
#include "projectiles.h"
#include "scoresManager.h"
#include "god.h"
#include "invadersGrid.h"
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<missile> missiles;
/*!
* @brief list of postion of all torpedos shot by the player(s)
*/
vector<Torpedo> torpedos;
/*!
* @brief Define the current type of the game
*/
PlayMode playMode;
/*!
* @brief list of all player data
*/
vector<Player> 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();
/*!
* @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();
/*!
*
*/
void managedGames();
/*!
* @brief
* @return
* @fn
*/
WinValue enterGameLoop();
/*!
* @brief
* @return
* @fn
*/
bool reloadConfig();
};
#endif