Game
Game file where the whole game is managed
enum Colors {
RED = 1,
GREEN,
BLUE,
YELLOW,
PURPLE,
CYAN,
WHITE
};
class Game: public EntityManager {
public:
Game(std::string ip, int port);
~Game();
int MainLoop();
void update();
void sendMoveToServer();
void handleChatInput(float deltaTime);
void createMainMenuScene();
void killGameEntity();
enum gameState {
MENU,
MATCHMAKING,
GAME,
ENDGAME
};
enum MISSILE_TYPE {
PLAYER_ONE = 1,
LITTLE_MONSTER,
ORANGE_MISSILE,
PURPLE_MISSILE,
GREEN_MISSILE,
PLAYER_TWO,
PLAYER_THREE,
};
private:
std::unique_ptr<Fbr> _fbr;
sf::RenderWindow _window;
sf::Vector2f _screenSize;
sf::Vector2f _realScreenSize;
sf::Vector2u _realScreenSizeU;
std::vector<entity_t> _strobes;
unsigned char currentSong;
sf::Vector2u topLeftOffeset;
Loader _manager;
ECS::Registry ecs;
Factory _factory;
Network _net;
MenuManager _menuManager;
long _lastTime;
float _resMult;
unsigned int _roomId;
unsigned int _playerId;
gameState _gameState;
unsigned int _startTimeLeft;
unsigned char _started;
int eventMemory;
std::chrono::system_clock::time_point _lastPing;
std::chrono::system_clock::time_point _startGameTime;
std::chrono::system_clock::time_point _lastPlayerFireTime;
std::chrono::system_clock::time_point _lastPlayerBombFireTime;
std::chrono::system_clock::time_point _lastPlaerLaserFireTime;
std::chrono::system_clock::time_point _lastPlaerRayFireTime;
std::vector<u_char> _keyboardInputs;
std::string _chatInput;
float _timeSinceLastUpdate;
void refreshScreenSize();
void initButtons();
void initMenus();
void sendChat(const std::string &msg);
int searchRoomId(int roomId);
void handleTimeoutMatchmaking(Network::Packet &packet);
void handlePlayerScore(Network::Packet &packet);
void handleGameEnd(Network::Packet &packet);
void handlePlayerPosition(Network::Packet &packet);
void handleMissilePosition(Network::Packet &packet);
void handleEnnemiPosition(Network::Packet &packet);
void handleEnnemiDeath(Network::Packet &packet);
void handleMissileDeath(Network::Packet &packet);
void handlePlayerDeath(Network::Packet &packet);
void handlePlayerDisconnected(Network::Packet &packet);
void handleRoomJoin(Network::Packet &packet);
void handlePlayerJoinGame(Network::Packet &packet);
void handlePlayerLife(Network::Packet &packet);
void handleMonsterLife(Network::Packet &packet);
void handleStrobes(Network::Packet &packet);
void handleResend(Network::Packet &packet);
void handleChangeLevel(Network::Packet &packet);
void handleLatency(Network::Packet &packet);
void handleListRooms(Network::Packet &packet);
void handleBonusPosition(Network::Packet &packet);
void handleBonusDestroyed(Network::Packet &packet);
void handleBombPosition(Network::Packet &packet);
void handleBombDestroyed(Network::Packet &packet);
void handleChatMessage(Network::Packet &packet);
void handlePodInfo(Network::Packet &packet);
void handleLaser(Network::Packet &packet);
void handleRay(Network::Packet &packet);
};
In this class, there is a lot of methods.
In the public part of the game class, there are a few main methods used to manage the whole game. There's one method for the game's main loop -> int MainLoop()
, but there's another used to update the game, i.e. to refresh data on players, missiles... this method is -> void update()
. You can also find a function -> void sendMoveToServer()
, used to adjust the player's behavior and position according to his own actions (moving, dying...).
About variables, you will find varibles used to manage the game like -> sf::Vector2u _screenSize, sf::RenderWindow _window, long _lastTime, float _resMult, unsigned int _roomId, unsigned int _playerId, bool _gameOver, unsigned int _startTimeLeft, unsigned char _started, int eventMemory
.
In this class, you will also find some instance of other classes like Loader _manager, ECS::Registry ecs, Factory _factory, Network _net
. These classes are used for differents things. For example, Loader is used to load texture of entities, ECS::Registry
is used to call update of components like ECS::systems::PositionSystem().update(this->ecs)
. You will also use ECS::Registry
to call function to kill an entity -> this->ecs.kill_entity(entityID)
.
Finally, there are many functions that are part of game management :
void handleTimeoutMatchmaking(Network::Packet &packet);
void handlePlayerScore(Network::Packet &packet);
void handleGameEnd(Network::Packet &packet);
void handlePlayerPosition(Network::Packet &packet);
void handleMissilePosition(Network::Packet &packet);
void handleEnnemiPosition(Network::Packet &packet);
void handleEnnemiDeath(Network::Packet &packet);
void handleMissileDeath(Network::Packet &packet);
void handlePlayerDeath(Network::Packet &packet);
void handlePlayerDisconnected(Network::Packet &packet);
void handleRoomJoin(Network::Packet &packet);
void handlePlayerJoinGame(Network::Packet &packet);
void handlePlayerLife(Network::Packet &packet);
void handleMonsterLife(Network::Packet &packet);
void handleStrobes(Network::Packet &packet);
void handleResend(Network::Packet &packet);
void handleChangeLevel(Network::Packet &packet);
void handleLatency(Network::Packet &packet);
void handleListRooms(Network::Packet &packet);
void handleBonusPosition(Network::Packet &packet);
void handleBonusDestroyed(Network::Packet &packet);
void handleBombPosition(Network::Packet &packet);
void handleBombDestroyed(Network::Packet &packet);
void handleChatMessage(Network::Packet &packet);
void handlePodInfo(Network::Packet &packet);
void handleLaser(Network::Packet &packet);
void handleRay(Network::Packet &packet);
Theses functions are used to update the game by part and manage all the entities.
Some additions function are there like void refreshScreenSize()
to refresh the resolution of the screen where the program's displayed, or void initButtons() && void initMenus()
to manage the menu displayed on the screen.
Moreover, there is also the method void sendChat(const std::string &msg)
to manage the chat that you will see during the matchmaking.
Finally, you will see int searchRoomId(int roomId) to get the current room accessible.
Last updated