Compare commits
19 Commits
alpha-0.0.
...
alpha-0.2.
| Author | SHA1 | Date | |
|---|---|---|---|
| 784c558840 | |||
| 5d366b6f6c | |||
| f70661694b | |||
| 36a1ab0572 | |||
| 409268b604 | |||
| 174d144d26 | |||
| 360258e4cf | |||
| 2148c0050c | |||
| 61166023df | |||
| e7bf22cea6 | |||
| f09f79198d | |||
| 8c19d3cc3c | |||
| 208892d266 | |||
| 4384806cf0 | |||
| 1a091baeaf | |||
| 43f21ffd44 | |||
| 24617c539f | |||
| 4611a198c9 | |||
| d40ffe8f6c |
@@ -12,14 +12,28 @@ enum class GameState : std::uint8_t {
|
|||||||
Game,
|
Game,
|
||||||
EndGame,
|
EndGame,
|
||||||
Disconnected,
|
Disconnected,
|
||||||
|
Closed
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::uint8_t, Player> PlayerList;
|
typedef std::map<std::uint8_t, Player> PlayerList;
|
||||||
|
|
||||||
class Game {
|
class GameListener {
|
||||||
|
public:
|
||||||
|
virtual void OnPlayerJoin(PlayerID player) {}
|
||||||
|
virtual void OnPlayerLeave(PlayerID player) {}
|
||||||
|
|
||||||
|
virtual void OnGameStateUpdate(GameState newState) {}
|
||||||
|
virtual void OnGameBegin() {}
|
||||||
|
virtual void OnGameEnd() {}
|
||||||
|
virtual void OnGameClose() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef utils::ObjectNotifier<GameListener> GameNotifier;
|
||||||
|
|
||||||
|
class Game : public GameNotifier {
|
||||||
protected:
|
protected:
|
||||||
World* m_World;
|
World* m_World;
|
||||||
std::array<Team, 2> m_Teams = { Team{TeamColor::Red}, Team{TeamColor::Blue} };
|
TeamList m_Teams = { Team{TeamColor::Red}, Team{TeamColor::Blue} };
|
||||||
GameState m_GameState = GameState::Lobby;
|
GameState m_GameState = GameState::Lobby;
|
||||||
PlayerList m_Players;
|
PlayerList m_Players;
|
||||||
public:
|
public:
|
||||||
@@ -49,6 +63,8 @@ public:
|
|||||||
const Player* getPlayerById(PlayerID id) const;
|
const Player* getPlayerById(PlayerID id) const;
|
||||||
Player* getPlayerById(PlayerID id);
|
Player* getPlayerById(PlayerID id);
|
||||||
|
|
||||||
|
const TeamList& getTeams() const { return m_Teams; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -111,11 +111,13 @@ public:
|
|||||||
|
|
||||||
virtual bool OnDeath(World* world) { return true; }
|
virtual bool OnDeath(World* world) { return true; }
|
||||||
|
|
||||||
|
MobID getMobID() const { return m_ID; }
|
||||||
const TowerImmunities& getTowerImmunities() const { return getMobTowerImmunities(getType(), m_Level); }
|
const TowerImmunities& getTowerImmunities() const { return getMobTowerImmunities(getType(), m_Level); }
|
||||||
const EffectImmunities& getEffectImmunities() const { return getMobEffectImmunities(getType(), m_Level); }
|
const EffectImmunities& getEffectImmunities() const { return getMobEffectImmunities(getType(), m_Level); }
|
||||||
PlayerID getSender() const { return m_Sender; }
|
PlayerID getSender() const { return m_Sender; }
|
||||||
MobLevel getLevel() const { return m_Level; }
|
MobLevel getLevel() const { return m_Level; }
|
||||||
const MobStats* getStats() const { return getMobStats(getType(), m_Level); }
|
const MobStats* getStats() const { return getMobStats(getType(), m_Level); }
|
||||||
|
void setHealth(float newHealth) { m_Health = newHealth; }
|
||||||
float getHealth() const { return m_Health; }
|
float getHealth() const { return m_Health; }
|
||||||
bool isDead() const { return m_Health <= 0; }
|
bool isDead() const { return m_Health <= 0; }
|
||||||
bool isAlive() const { return m_Health > 0; }
|
bool isAlive() const { return m_Health > 0; }
|
||||||
|
|||||||
@@ -33,19 +33,34 @@ public:
|
|||||||
void setDirection(Direction direction) { m_Direction = direction; }
|
void setDirection(Direction direction) { m_Direction = direction; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TeamCastle : public utils::shape::Rectangle{
|
class Team;
|
||||||
|
|
||||||
|
class TeamCastle : public utils::shape::Rectangle {
|
||||||
private:
|
private:
|
||||||
|
const Team* m_Team;
|
||||||
float m_Life;
|
float m_Life;
|
||||||
public:
|
public:
|
||||||
TeamCastle() : m_Life(1000) {
|
static constexpr int CastleMaxLife = 1000;
|
||||||
|
|
||||||
|
TeamCastle(const Team* team) : m_Team(team), m_Life(CastleMaxLife) {
|
||||||
setWidth(5);
|
setWidth(5);
|
||||||
setHeight(5);
|
setHeight(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TeamCastle() : TeamCastle(nullptr) {}
|
||||||
|
|
||||||
float getLife() const { return m_Life; }
|
float getLife() const { return m_Life; }
|
||||||
|
|
||||||
|
const Team* getTeam() const { return m_Team; }
|
||||||
|
void setTeam(const Team* team) { m_Team = team; }
|
||||||
|
|
||||||
void setLife(float life) { m_Life = life; }
|
void setLife(float life) { m_Life = life; }
|
||||||
void damage(float damage) { m_Life = std::max(0.0f, m_Life - damage); }
|
void damage(float damage) { m_Life = std::max(0.0f, m_Life - damage); }
|
||||||
|
|
||||||
|
void setShape(utils::shape::Rectangle rect) {
|
||||||
|
setCenter(rect.getCenter());
|
||||||
|
setSize(rect.getSize());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Team {
|
class Team {
|
||||||
@@ -71,5 +86,7 @@ public:
|
|||||||
std::uint8_t getPlayerCount() const;
|
std::uint8_t getPlayerCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::array<Team, 2> TeamList;
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -56,6 +56,13 @@ struct Color {
|
|||||||
std::uint8_t r, g, b;
|
std::uint8_t r, g, b;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr Color BLACK{ 0, 0, 0 };
|
||||||
|
static constexpr Color WHITE{ 255, 255, 255 };
|
||||||
|
|
||||||
|
static constexpr Color RED{ 255, 0, 0 };
|
||||||
|
static constexpr Color GREEN{ 0, 255, 0 };
|
||||||
|
static constexpr Color BLUE{ 0, 0, 255 };
|
||||||
|
|
||||||
struct Tile {
|
struct Tile {
|
||||||
virtual TileType getType() const = 0;
|
virtual TileType getType() const = 0;
|
||||||
};
|
};
|
||||||
@@ -134,6 +141,7 @@ protected:
|
|||||||
TowerTileColorPalette m_TowerPlacePalette;
|
TowerTileColorPalette m_TowerPlacePalette;
|
||||||
Color m_WalkablePalette;
|
Color m_WalkablePalette;
|
||||||
std::vector<Color> m_DecorationPalette;
|
std::vector<Color> m_DecorationPalette;
|
||||||
|
Color m_Background;
|
||||||
|
|
||||||
std::unordered_map<ChunkCoord, ChunkPtr> m_Chunks;
|
std::unordered_map<ChunkCoord, ChunkPtr> m_Chunks;
|
||||||
|
|
||||||
@@ -152,8 +160,6 @@ protected:
|
|||||||
public:
|
public:
|
||||||
World(Game* game);
|
World(Game* game);
|
||||||
|
|
||||||
static constexpr std::uint8_t CastleWidth = 5, CastleHeight = 5;
|
|
||||||
|
|
||||||
bool loadMap(const protocol::WorldBeginDataPacket* worldHeader);
|
bool loadMap(const protocol::WorldBeginDataPacket* worldHeader);
|
||||||
bool loadMap(const protocol::WorldDataPacket* worldData);
|
bool loadMap(const protocol::WorldDataPacket* worldData);
|
||||||
|
|
||||||
@@ -172,6 +178,7 @@ public:
|
|||||||
const TowerTileColorPalette& getTowerTileColorPalette() const { return m_TowerPlacePalette; }
|
const TowerTileColorPalette& getTowerTileColorPalette() const { return m_TowerPlacePalette; }
|
||||||
const Color& getWalkableTileColor() const { return m_WalkablePalette; }
|
const Color& getWalkableTileColor() const { return m_WalkablePalette; }
|
||||||
const std::vector<Color>& getDecorationPalette() const { return m_DecorationPalette; }
|
const std::vector<Color>& getDecorationPalette() const { return m_DecorationPalette; }
|
||||||
|
const Color& getBackgroundColor() const { return m_Background; }
|
||||||
|
|
||||||
const TilePalette& getTilePalette() const { return m_TilePalette; }
|
const TilePalette& getTilePalette() const { return m_TilePalette; }
|
||||||
|
|
||||||
@@ -205,6 +212,8 @@ public:
|
|||||||
Team& getTeam(TeamColor team);
|
Team& getTeam(TeamColor team);
|
||||||
const Team& getTeam(TeamColor team) const;
|
const Team& getTeam(TeamColor team) const;
|
||||||
|
|
||||||
|
const TeamList& getTeams() const;
|
||||||
|
|
||||||
const TowerList& getTowers() const { return m_Towers; };
|
const TowerList& getTowers() const { return m_Towers; };
|
||||||
TowerPtr getTowerById(TowerID tower);
|
TowerPtr getTowerById(TowerID tower);
|
||||||
|
|
||||||
@@ -223,7 +232,6 @@ public:
|
|||||||
// MobListener
|
// MobListener
|
||||||
|
|
||||||
virtual void OnMobDamage(Mob* target, float damage, Tower* source);
|
virtual void OnMobDamage(Mob* target, float damage, Tower* source);
|
||||||
virtual void OnMobDie(Mob* mob);
|
|
||||||
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage);
|
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -19,16 +19,16 @@ class Client {
|
|||||||
private:
|
private:
|
||||||
render::Renderer* m_Renderer;
|
render::Renderer* m_Renderer;
|
||||||
ClientConnexion m_Connexion;
|
ClientConnexion m_Connexion;
|
||||||
ClientGame m_Game;
|
std::unique_ptr<ClientGame> m_Game;
|
||||||
bool m_Connected;
|
bool m_Connected;
|
||||||
public:
|
public:
|
||||||
Client(render::Renderer* renderer) : m_Renderer(renderer), m_Game(this), m_Connected(false) {}
|
Client(render::Renderer* renderer) : m_Renderer(renderer), m_Game(std::make_unique<ClientGame>(this)), m_Connected(false) {}
|
||||||
|
|
||||||
const ClientGame& getGame() const { return m_Game; }
|
const ClientGame& getGame() const { return *m_Game; }
|
||||||
const ClientConnexion& getConnexion() const { return m_Connexion; }
|
const ClientConnexion& getConnexion() const { return m_Connexion; }
|
||||||
render::Renderer* getRenderer() const { return m_Renderer; }
|
render::Renderer* getRenderer() const { return m_Renderer; }
|
||||||
|
|
||||||
ClientGame& getGame() { return m_Game; }
|
ClientGame& getGame() { return *m_Game; }
|
||||||
ClientConnexion& getConnexion() { return m_Connexion; }
|
ClientConnexion& getConnexion() { return m_Connexion; }
|
||||||
|
|
||||||
void tick(std::uint64_t delta);
|
void tick(std::uint64_t delta);
|
||||||
@@ -45,6 +45,8 @@ public:
|
|||||||
void placeTower(game::TowerType type, const glm::vec2& position);
|
void placeTower(game::TowerType type, const glm::vec2& position);
|
||||||
void upgradeTower(game::TowerID tower, game::TowerLevel level);
|
void upgradeTower(game::TowerID tower, game::TowerLevel level);
|
||||||
void removeTower(game::TowerID tower);
|
void removeTower(game::TowerID tower);
|
||||||
|
private:
|
||||||
|
void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
Client* getClient() const { return m_Client; }
|
Client* getClient() const { return m_Client; }
|
||||||
|
|
||||||
render::Renderer* getRenderer() const { return m_Renderer; }
|
render::Renderer* getRenderer() const { return m_Renderer; }
|
||||||
WorldClient& getWorld() { return m_WorldClient; }
|
WorldClient& getWorldClient() { return m_WorldClient; }
|
||||||
|
|
||||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet);
|
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet);
|
||||||
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet);
|
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public:
|
|||||||
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet);
|
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet);
|
||||||
virtual void HandlePacket(const protocol::WorldAddTowerPacket* packet);
|
virtual void HandlePacket(const protocol::WorldAddTowerPacket* packet);
|
||||||
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet);
|
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet);
|
||||||
|
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet);
|
||||||
|
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,11 @@ private:
|
|||||||
bool m_ServerRunning;
|
bool m_ServerRunning;
|
||||||
public:
|
public:
|
||||||
Server(const std::string& worldFilePath);
|
Server(const std::string& worldFilePath);
|
||||||
virtual ~Server() {}
|
virtual ~Server();
|
||||||
|
|
||||||
bool start(std::uint16_t port);
|
bool start(std::uint16_t port);
|
||||||
void stop();
|
void stop(); // force the server to stop
|
||||||
|
void close(); // at the end of a game
|
||||||
void lauchGame();
|
|
||||||
|
|
||||||
void removeConnexion(std::uint8_t connexionID);
|
void removeConnexion(std::uint8_t connexionID);
|
||||||
|
|
||||||
@@ -74,6 +73,8 @@ public:
|
|||||||
|
|
||||||
float getTPS() const { return m_TickCounter.getTPS(); }
|
float getTPS() const { return m_TickCounter.getTPS(); }
|
||||||
|
|
||||||
|
bool isRunning() { return m_ServerRunning; }
|
||||||
|
|
||||||
const ServerGame& getGame() const { return m_Game; }
|
const ServerGame& getGame() const { return m_Game; }
|
||||||
ServerGame& getGame() { return m_Game; }
|
ServerGame& getGame() { return m_Game; }
|
||||||
|
|
||||||
@@ -88,6 +89,7 @@ private:
|
|||||||
void accept();
|
void accept();
|
||||||
void updateSockets();
|
void updateSockets();
|
||||||
|
|
||||||
|
void clean();
|
||||||
void startThread();
|
void startThread();
|
||||||
void stopThread();
|
void stopThread();
|
||||||
void tick(std::uint64_t delta);
|
void tick(std::uint64_t delta);
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ namespace server {
|
|||||||
|
|
||||||
class Server;
|
class Server;
|
||||||
|
|
||||||
class ServerGame : public game::Game {
|
class ServerGame : public game::Game, public game::GameListener {
|
||||||
private:
|
private:
|
||||||
Server* m_Server;
|
Server* m_Server;
|
||||||
ServerWorld m_ServerWorld;
|
ServerWorld m_ServerWorld;
|
||||||
utils::AutoTimer m_GoldMineTimer{ 1000, std::bind(&ServerGame::updateGoldMines, this) };
|
utils::AutoTimer m_GoldMineTimer;
|
||||||
|
utils::AutoTimer m_MobStatesTimer;
|
||||||
|
utils::CooldownTimer m_EndGameCooldown;
|
||||||
public:
|
public:
|
||||||
ServerGame(Server* server);
|
ServerGame(Server* server);
|
||||||
~ServerGame() {}
|
~ServerGame() {}
|
||||||
@@ -22,8 +24,16 @@ public:
|
|||||||
|
|
||||||
virtual void tick(std::uint64_t delta);
|
virtual void tick(std::uint64_t delta);
|
||||||
void startGame();
|
void startGame();
|
||||||
|
|
||||||
|
// GameListener
|
||||||
|
|
||||||
|
virtual void OnGameStateUpdate(game::GameState newState);
|
||||||
|
virtual void OnGameBegin();
|
||||||
|
virtual void OnGameEnd();
|
||||||
|
virtual void OnGameClose();
|
||||||
private:
|
private:
|
||||||
void balanceTeams();
|
void balanceTeams();
|
||||||
|
void updateMobStates();
|
||||||
void updateGoldMines();
|
void updateGoldMines();
|
||||||
void updatePlayerStats();
|
void updatePlayerStats();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,11 +14,17 @@ private:
|
|||||||
game::TowerID m_CurrentTowerID;
|
game::TowerID m_CurrentTowerID;
|
||||||
Server* m_Server;
|
Server* m_Server;
|
||||||
public:
|
public:
|
||||||
|
static constexpr float MobSpawnBorder = 0.01f;
|
||||||
|
|
||||||
ServerWorld(Server* server, ServerGame* game);
|
ServerWorld(Server* server, ServerGame* game);
|
||||||
|
|
||||||
void spawnMobs(game::MobType type, std::uint8_t level, game::PlayerID sender, std::uint8_t count);
|
void spawnMobs(game::MobType type, std::uint8_t level, game::PlayerID sender, std::uint8_t count);
|
||||||
game::TowerPtr placeTowerAt(game::TowerType type, std::int32_t x, std::int32_t y, game::PlayerID builder);
|
game::TowerPtr placeTowerAt(game::TowerType type, std::int32_t x, std::int32_t y, game::PlayerID builder);
|
||||||
|
|
||||||
|
virtual void OnMobDie(game::Mob* mob);
|
||||||
|
|
||||||
|
virtual void OnMobCastleDamage(game::Mob* damager, game::TeamCastle* enemyCastle, float damage);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace server
|
} // namespace server
|
||||||
|
|||||||
@@ -338,7 +338,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <basetsd.h>
|
#include <basetsd.h>
|
||||||
typedef SSIZE_T ssize_t;
|
//typedef SSIZE_T ssize_t;
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ public:
|
|||||||
void setCenterY(float y) { m_Center.setY(y); }
|
void setCenterY(float y) { m_Center.setY(y); }
|
||||||
|
|
||||||
void setSize(float width, float height) { setWidth(width); setHeight(height); }
|
void setSize(float width, float height) { setWidth(width); setHeight(height); }
|
||||||
|
void setSize(Point size) { setSize(size.getX(), size.getY()); }
|
||||||
|
Point getSize() { return { m_Width, m_Height }; }
|
||||||
|
|
||||||
void setWidth(float width) { m_Width = width; }
|
void setWidth(float width) { m_Width = width; }
|
||||||
void setHeight(float height) { m_Height = height; }
|
void setHeight(float height) { m_Height = height; }
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ public:
|
|||||||
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
|
virtual void HandlePacket(const RemoveTowerPacket* packet) {}
|
||||||
virtual void HandlePacket(const SendMobsPacket* packet) {}
|
virtual void HandlePacket(const SendMobsPacket* packet) {}
|
||||||
virtual void HandlePacket(const UpgradeTowerPacket* packet) {}
|
virtual void HandlePacket(const UpgradeTowerPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateMobStatesPacket* packet) {}
|
||||||
|
virtual void HandlePacket(const UpdateCastleLifePacket* packet) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace protocol
|
} // namespace protocol
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ enum class PacketType : std::uint8_t {
|
|||||||
UpdatePlayerTeam,
|
UpdatePlayerTeam,
|
||||||
ServerTps,
|
ServerTps,
|
||||||
WorldAddTower,
|
WorldAddTower,
|
||||||
|
UpdateMobStates,
|
||||||
|
UpdateCastleLife,
|
||||||
|
|
||||||
// client <--> server
|
// client <--> server
|
||||||
KeepAlive,
|
KeepAlive,
|
||||||
@@ -45,6 +47,7 @@ struct WorldHeader {
|
|||||||
game::TowerTileColorPalette m_TowerPlacePalette;
|
game::TowerTileColorPalette m_TowerPlacePalette;
|
||||||
game::Color m_WalkablePalette;
|
game::Color m_WalkablePalette;
|
||||||
std::vector<game::Color> m_DecorationPalette;
|
std::vector<game::Color> m_DecorationPalette;
|
||||||
|
game::Color m_Background;
|
||||||
|
|
||||||
game::SpawnColorPalette m_SpawnColorPalette;
|
game::SpawnColorPalette m_SpawnColorPalette;
|
||||||
|
|
||||||
@@ -128,6 +131,7 @@ public:
|
|||||||
const game::TowerTileColorPalette& getTowerTilePalette() const { return m_Header.m_TowerPlacePalette; }
|
const game::TowerTileColorPalette& getTowerTilePalette() const { return m_Header.m_TowerPlacePalette; }
|
||||||
const game::Color& getWalkableTileColor() const { return m_Header.m_WalkablePalette; }
|
const game::Color& getWalkableTileColor() const { return m_Header.m_WalkablePalette; }
|
||||||
const std::vector<game::Color>& getDecorationPalette() const { return m_Header.m_DecorationPalette; }
|
const std::vector<game::Color>& getDecorationPalette() const { return m_Header.m_DecorationPalette; }
|
||||||
|
const game::Color& getBackgroundColor() const { return m_Header.m_Background; }
|
||||||
|
|
||||||
const game::Spawn& getRedSpawn() const { return m_Header.m_RedSpawn; }
|
const game::Spawn& getRedSpawn() const { return m_Header.m_RedSpawn; }
|
||||||
const game::Spawn& getBlueSpawn() const { return m_Header.m_BlueSpawn; }
|
const game::Spawn& getBlueSpawn() const { return m_Header.m_BlueSpawn; }
|
||||||
@@ -513,5 +517,60 @@ public:
|
|||||||
virtual PacketType getType() const { return PacketType::UpgradeTower; }
|
virtual PacketType getType() const { return PacketType::UpgradeTower; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MobState {
|
||||||
|
using Point = utils::shape::Point;
|
||||||
|
private:
|
||||||
|
game::MobID m_MobID;
|
||||||
|
Point m_MobPosition;
|
||||||
|
float m_MobLife;
|
||||||
|
game::Direction m_MobDirection;
|
||||||
|
public:
|
||||||
|
MobState() {}
|
||||||
|
MobState(game::MobID id, Point position, float life, game::Direction direction) :
|
||||||
|
m_MobID(id), m_MobPosition(position), m_MobLife(life), m_MobDirection(direction) {}
|
||||||
|
|
||||||
|
game::MobID getMobId() const { return m_MobID; }
|
||||||
|
Point getMobPosition() const { return m_MobPosition; }
|
||||||
|
float getMobLife() const { return m_MobLife; }
|
||||||
|
game::Direction getMobDirection() const { return m_MobDirection; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class UpdateMobStatesPacket : public Packet {
|
||||||
|
private:
|
||||||
|
std::vector<MobState> m_MobStates;
|
||||||
|
public:
|
||||||
|
UpdateMobStatesPacket() {}
|
||||||
|
virtual ~UpdateMobStatesPacket() {}
|
||||||
|
|
||||||
|
virtual DataBuffer Serialize() const;
|
||||||
|
virtual void Deserialize(DataBuffer& data);
|
||||||
|
virtual void Dispatch(PacketHandler* handler) const;
|
||||||
|
|
||||||
|
void addMobState(MobState mobState) { m_MobStates.push_back(mobState); }
|
||||||
|
|
||||||
|
const std::vector<MobState>& getMobStates() const { return m_MobStates; }
|
||||||
|
|
||||||
|
virtual PacketType getType() const { return PacketType::UpdateMobStates; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class UpdateCastleLifePacket : public Packet {
|
||||||
|
private:
|
||||||
|
std::uint16_t m_CastleLife;
|
||||||
|
game::TeamColor m_Team;
|
||||||
|
public:
|
||||||
|
UpdateCastleLifePacket() {}
|
||||||
|
UpdateCastleLifePacket(std::uint16_t life, game::TeamColor team) : m_CastleLife(life), m_Team(team) {}
|
||||||
|
virtual ~UpdateCastleLifePacket() {}
|
||||||
|
|
||||||
|
virtual DataBuffer Serialize() const;
|
||||||
|
virtual void Deserialize(DataBuffer& data);
|
||||||
|
virtual void Dispatch(PacketHandler* handler) const;
|
||||||
|
|
||||||
|
std::uint16_t getCastleLife() const { return m_CastleLife; }
|
||||||
|
game::TeamColor getTeamColor() const { return m_Team; }
|
||||||
|
|
||||||
|
virtual PacketType getType() const { return PacketType::UpdateCastleLife; }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,8 @@ private:
|
|||||||
std::unique_ptr<WorldShader> m_WorldShader;
|
std::unique_ptr<WorldShader> m_WorldShader;
|
||||||
std::unique_ptr<EntityShader> m_EntityShader;
|
std::unique_ptr<EntityShader> m_EntityShader;
|
||||||
|
|
||||||
|
glm::vec3 m_BackgroundColor;
|
||||||
|
|
||||||
bool m_IsometricView = true;
|
bool m_IsometricView = true;
|
||||||
float m_IsometricShade = m_IsometricView;
|
float m_IsometricShade = m_IsometricView;
|
||||||
glm::vec2 m_CamPos{};
|
glm::vec2 m_CamPos{};
|
||||||
@@ -49,6 +51,8 @@ public:
|
|||||||
void setCamPos(const glm::vec2& newPos);
|
void setCamPos(const glm::vec2& newPos);
|
||||||
void setIsometricView(bool isometric); // false = 2D true = Isometric
|
void setIsometricView(bool isometric); // false = 2D true = Isometric
|
||||||
|
|
||||||
|
void setBackgroundColor(const glm::vec3& color) { m_BackgroundColor = color; }
|
||||||
|
|
||||||
glm::vec2 getCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
|
glm::vec2 getCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
|
||||||
private:
|
private:
|
||||||
void updateIsometricView();
|
void updateIsometricView();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "render/gui/TowerPlacePopup.h"
|
#include "render/gui/TowerPlacePopup.h"
|
||||||
#include "render/gui/MobTooltip.h"
|
#include "render/gui/MobTooltip.h"
|
||||||
|
#include "render/gui/CastleTooltip.h"
|
||||||
|
|
||||||
#include "render/gui/imgui/imgui.h"
|
#include "render/gui/imgui/imgui.h"
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<gui::TowerPlacePopup> m_TowerPlacePopup;
|
std::unique_ptr<gui::TowerPlacePopup> m_TowerPlacePopup;
|
||||||
std::unique_ptr<gui::MobTooltip> m_MobTooltip;
|
std::unique_ptr<gui::MobTooltip> m_MobTooltip;
|
||||||
|
std::unique_ptr<gui::CastleTooltip> m_CastleTooltip;
|
||||||
public:
|
public:
|
||||||
WorldRenderer(game::World* world, client::ClientGame* client);
|
WorldRenderer(game::World* world, client::ClientGame* client);
|
||||||
~WorldRenderer();
|
~WorldRenderer();
|
||||||
@@ -69,8 +71,11 @@ private:
|
|||||||
void renderPopups();
|
void renderPopups();
|
||||||
void renderTowerUpgradePopup();
|
void renderTowerUpgradePopup();
|
||||||
void renderMobTooltip() const;
|
void renderMobTooltip() const;
|
||||||
|
void renderCastleTooltip() const;
|
||||||
void detectClick();
|
void detectClick();
|
||||||
void detectMobHovering() const;
|
void detectMobHovering() const;
|
||||||
|
void detectCastleHovering() const;
|
||||||
|
void renderTooltips() const;
|
||||||
void removeTower();
|
void removeTower();
|
||||||
glm::vec2 getCursorWorldPos() const;
|
glm::vec2 getCursorWorldPos() const;
|
||||||
glm::vec2 getClickWorldPos() const;
|
glm::vec2 getClickWorldPos() const;
|
||||||
|
|||||||
28
include/render/gui/CastleTooltip.h
Normal file
28
include/render/gui/CastleTooltip.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
class TeamCastle;
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
|
||||||
|
namespace gui {
|
||||||
|
|
||||||
|
class CastleTooltip : public GuiWidget {
|
||||||
|
private:
|
||||||
|
const game::TeamCastle* m_Castle;
|
||||||
|
public:
|
||||||
|
CastleTooltip(client::Client* client);
|
||||||
|
|
||||||
|
virtual void render();
|
||||||
|
|
||||||
|
void setCastle(const game::TeamCastle* castle) { m_Castle = castle; }
|
||||||
|
bool isShown() { return m_Castle != nullptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
|
} // namespace td
|
||||||
@@ -10,15 +10,17 @@ namespace gui {
|
|||||||
|
|
||||||
class GuiManager {
|
class GuiManager {
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<GuiWidget>> m_Widgets;
|
std::vector<std::unique_ptr<GuiWidget>> m_Widgets;
|
||||||
public:
|
public:
|
||||||
|
GuiManager(){}
|
||||||
|
|
||||||
void renderWidgets() {
|
void renderWidgets() {
|
||||||
for (auto widget : m_Widgets) {
|
for (auto& widget : m_Widgets) {
|
||||||
widget->render();
|
widget->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addWidgets(const std::shared_ptr<GuiWidget>& widget) {
|
void addWidget(std::unique_ptr<GuiWidget>&& widget) {
|
||||||
m_Widgets.push_back(std::move(widget));
|
m_Widgets.push_back(std::move(widget));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public:
|
|||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
void setMob(const game::Mob* mob) { m_Mob = mob; }
|
void setMob(const game::Mob* mob) { m_Mob = mob; }
|
||||||
|
bool isShown() { return m_Mob != nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "render/gui/GuiManager.h"
|
||||||
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
typedef void* SDL_GLContext;
|
typedef void* SDL_GLContext;
|
||||||
|
|
||||||
@@ -20,15 +22,6 @@ class Client;
|
|||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
|
||||||
namespace gui {
|
|
||||||
|
|
||||||
class MainMenu;
|
|
||||||
class GameMenu;
|
|
||||||
class FrameMenu;
|
|
||||||
class UpdateMenu;
|
|
||||||
|
|
||||||
} // namespace gui
|
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
class Renderer;
|
class Renderer;
|
||||||
@@ -38,11 +31,8 @@ private:
|
|||||||
SDL_Window* m_Window;
|
SDL_Window* m_Window;
|
||||||
SDL_GLContext m_GlContext;
|
SDL_GLContext m_GlContext;
|
||||||
td::render::Renderer* m_Renderer;
|
td::render::Renderer* m_Renderer;
|
||||||
|
td::gui::GuiManager m_GuiManager;
|
||||||
std::unique_ptr<td::client::Client> m_Client;
|
std::unique_ptr<td::client::Client> m_Client;
|
||||||
std::unique_ptr<td::gui::MainMenu> m_MainMenu;
|
|
||||||
std::unique_ptr<td::gui::GameMenu> m_GameMenu;
|
|
||||||
std::unique_ptr<td::gui::FrameMenu> m_FrameMenu;
|
|
||||||
std::unique_ptr<td::gui::UpdateMenu> m_UpdateMenu;
|
|
||||||
public:
|
public:
|
||||||
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
|
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
|
||||||
~TowerGui();
|
~TowerGui();
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "misc/DataBuffer.h"
|
||||||
|
|
||||||
#include <ctime>
|
#define TD_VERSION "alpha-0.2.0"
|
||||||
|
|
||||||
#define TD_VERSION "alpha-0.0.5"
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
Team::Team(TeamColor color) : m_Color(color) {}
|
Team::Team(TeamColor color) : m_Color(color), m_TeamCastle(this) {}
|
||||||
|
|
||||||
void Team::addPlayer(Player* newPlayer) {
|
void Team::addPlayer(Player* newPlayer) {
|
||||||
m_Players.push_back(newPlayer);
|
m_Players.push_back(newPlayer);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ bool World::loadMap(const protocol::WorldBeginDataPacket* worldHeader) {
|
|||||||
m_TowerPlacePalette = worldHeader->getTowerTilePalette();
|
m_TowerPlacePalette = worldHeader->getTowerTilePalette();
|
||||||
m_WalkablePalette = worldHeader->getWalkableTileColor();
|
m_WalkablePalette = worldHeader->getWalkableTileColor();
|
||||||
m_DecorationPalette = worldHeader->getDecorationPalette();
|
m_DecorationPalette = worldHeader->getDecorationPalette();
|
||||||
|
m_Background = worldHeader->getBackgroundColor();
|
||||||
|
|
||||||
getRedTeam().getSpawn() = worldHeader->getRedSpawn();
|
getRedTeam().getSpawn() = worldHeader->getRedSpawn();
|
||||||
getBlueTeam().getSpawn() = worldHeader->getBlueSpawn();
|
getBlueTeam().getSpawn() = worldHeader->getBlueSpawn();
|
||||||
@@ -44,7 +45,10 @@ bool World::loadMap(const protocol::WorldBeginDataPacket* worldHeader) {
|
|||||||
m_SpawnColorPalette = worldHeader->getSpawnPalette();
|
m_SpawnColorPalette = worldHeader->getSpawnPalette();
|
||||||
|
|
||||||
getRedTeam().getCastle() = worldHeader->getRedCastle();
|
getRedTeam().getCastle() = worldHeader->getRedCastle();
|
||||||
|
getRedTeam().getCastle().setTeam(&getRedTeam());
|
||||||
|
|
||||||
getBlueTeam().getCastle() = worldHeader->getBlueCastle();
|
getBlueTeam().getCastle() = worldHeader->getBlueCastle();
|
||||||
|
getBlueTeam().getCastle().setTeam(&getBlueTeam());
|
||||||
|
|
||||||
m_TilePalette = worldHeader->getTilePalette();
|
m_TilePalette = worldHeader->getTilePalette();
|
||||||
|
|
||||||
@@ -102,6 +106,8 @@ bool World::saveMap(const std::string& fileName) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void World::tick(std::uint64_t delta) {
|
void World::tick(std::uint64_t delta) {
|
||||||
|
if (m_Game->getGameState() != GameState::Game) return;
|
||||||
|
|
||||||
tickMobs(delta);
|
tickMobs(delta);
|
||||||
for (TowerPtr tower : m_Towers) {
|
for (TowerPtr tower : m_Towers) {
|
||||||
tower->tick(delta, this);
|
tower->tick(delta, this);
|
||||||
@@ -215,17 +221,6 @@ bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::OnMobDie(Mob* mob) {
|
|
||||||
if (mob->OnDeath(this)) { // check if the mob is actually dead (slimes ...)
|
|
||||||
//reward players
|
|
||||||
Player* sender = m_Game->getPlayerById(mob->getSender());
|
|
||||||
sender->addExp(mob->getStats()->getExpReward());
|
|
||||||
|
|
||||||
Player* killer = m_Game->getPlayerById(mob->getLastDamageTower()->getBuilder());
|
|
||||||
killer->addGold(mob->getStats()->getMoneyCost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::cleanDeadMobs() {
|
void World::cleanDeadMobs() {
|
||||||
// safely remove mobs when unused
|
// safely remove mobs when unused
|
||||||
for (std::size_t i = 0; i < m_Mobs.size(); i++) {
|
for (std::size_t i = 0; i < m_Mobs.size(); i++) {
|
||||||
@@ -289,7 +284,7 @@ void World::OnExplosion(utils::shape::Circle explosion, float centerDamage, Towe
|
|||||||
void World::OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {
|
void World::OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {
|
||||||
enemyCastle->damage(damage);
|
enemyCastle->damage(damage);
|
||||||
if (enemyCastle->getLife() <= 0) {
|
if (enemyCastle->getLife() <= 0) {
|
||||||
// TODO: a team has won
|
m_Game->notifyListeners(&GameListener::OnGameEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,5 +323,9 @@ const Player* World::getPlayerById(PlayerID id) const {
|
|||||||
return m_Game->getPlayerById(id);
|
return m_Game->getPlayerById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TeamList& World::getTeams() const {
|
||||||
|
return m_Game->getTeams();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -40,13 +40,19 @@ void Client::tick(std::uint64_t delta) {
|
|||||||
m_Connected = m_Connexion.updateSocket();
|
m_Connected = m_Connexion.updateSocket();
|
||||||
if (!m_Connected) {
|
if (!m_Connected) {
|
||||||
std::cout << "Disconnected ! (Reason : " << m_Connexion.getDisconnectReason() << ")\n";
|
std::cout << "Disconnected ! (Reason : " << m_Connexion.getDisconnectReason() << ")\n";
|
||||||
|
reset();
|
||||||
} else {
|
} else {
|
||||||
m_Game.tick(delta);
|
m_Game->tick(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::render() {
|
void Client::render() {
|
||||||
m_Game.renderWorld();
|
m_Game->renderWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::reset() {
|
||||||
|
m_Game.reset(0);
|
||||||
|
m_Game = std::make_unique<ClientGame>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::sendMobs(const std::vector<protocol::MobSend>& mobSends) {
|
void Client::sendMobs(const std::vector<protocol::MobSend>& mobSends) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
ClientConnexion::ClientConnexion() : Connexion(&m_Dispatcher) {
|
ClientConnexion::ClientConnexion() : Connexion(&m_Dispatcher), m_ServerTPS(0) {
|
||||||
registerHandlers();
|
registerHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ void ClientGame::HandlePacket(const protocol::UpdateMoneyPacket* packet) {
|
|||||||
|
|
||||||
void ClientGame::HandlePacket(const protocol::DisconnectPacket* packet) {
|
void ClientGame::HandlePacket(const protocol::DisconnectPacket* packet) {
|
||||||
m_GameState = game::GameState::Disconnected;
|
m_GameState = game::GameState::Disconnected;
|
||||||
|
m_Renderer->setBackgroundColor({ 0, 0, 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientGame::HandlePacket(const protocol::WorldDataPacket* packet) {
|
void ClientGame::HandlePacket(const protocol::WorldDataPacket* packet) {
|
||||||
|
|||||||
@@ -13,10 +13,17 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet
|
|||||||
GetDispatcher()->RegisterHandler(protocol::PacketType::SpawnMob, this);
|
GetDispatcher()->RegisterHandler(protocol::PacketType::SpawnMob, this);
|
||||||
GetDispatcher()->RegisterHandler(protocol::PacketType::UpgradeTower, this);
|
GetDispatcher()->RegisterHandler(protocol::PacketType::UpgradeTower, this);
|
||||||
GetDispatcher()->RegisterHandler(protocol::PacketType::RemoveTower, this);
|
GetDispatcher()->RegisterHandler(protocol::PacketType::RemoveTower, this);
|
||||||
|
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateCastleLife, this);
|
||||||
|
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateMobStates, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
|
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
|
||||||
loadMap(packet);
|
loadMap(packet);
|
||||||
|
if (m_Game->getGameState() == game::GameState::Game) {
|
||||||
|
const game::Color& backgroundColor = getBackgroundColor();
|
||||||
|
m_Game->getRenderer()->setBackgroundColor({ static_cast<float>(backgroundColor.r / 255.0f), static_cast<float>(backgroundColor.g / 255.0f),
|
||||||
|
static_cast<float>(backgroundColor.b / 255.0f) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldClient::HandlePacket(const protocol::WorldDataPacket* packet) {
|
void WorldClient::HandlePacket(const protocol::WorldDataPacket* packet) {
|
||||||
@@ -48,5 +55,22 @@ void WorldClient::HandlePacket(const protocol::RemoveTowerPacket* packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldClient::HandlePacket(const protocol::UpdateMobStatesPacket* packet) {
|
||||||
|
for (auto mobState : packet->getMobStates()) {
|
||||||
|
game::MobID mobId = mobState.getMobId();
|
||||||
|
auto it = std::find_if(getMobList().begin(), getMobList().end(), [mobId](game::MobPtr mob) { return mob->getMobID() == mobId; });
|
||||||
|
if (it != getMobList().end()) {
|
||||||
|
game::MobPtr& mob = *it;
|
||||||
|
mob->setCenter(mobState.getMobPosition());
|
||||||
|
mob->setDirection(mobState.getMobDirection());
|
||||||
|
mob->setHealth(mobState.getMobLife());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldClient::HandlePacket(const protocol::UpdateCastleLifePacket* packet) {
|
||||||
|
getTeam(packet->getTeamColor()).getCastle().setLife(packet->getCastleLife());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -37,10 +37,8 @@ void Lobby::tick() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (utils::getTime() - m_StartTimerTime >= LobbyWaitingTime) {
|
if (utils::getTime() - m_StartTimerTime >= LobbyWaitingTime) {
|
||||||
protocol::UpdateGameStatePacket packet(game::GameState::Game);
|
m_Server->getGame().notifyListeners(&game::GameListener::OnGameBegin);
|
||||||
m_Server->broadcastPacket(&packet);
|
|
||||||
m_GameStarted = true;
|
m_GameStarted = true;
|
||||||
m_Server->lauchGame();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ Server::Server(const std::string& worldFilePath) : m_ServerRunning(false) {
|
|||||||
m_Game.getWorld()->loadMapFromFile(worldFilePath);
|
m_Game.getWorld()->loadMapFromFile(worldFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::lauchGame() {
|
Server::~Server() {
|
||||||
m_Game.startGame();
|
if (m_Thread.joinable())
|
||||||
|
m_Thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::startThread() {
|
void Server::startThread() {
|
||||||
@@ -29,13 +30,16 @@ void Server::startThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
clean();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::close() {
|
||||||
|
stopThread();
|
||||||
|
}
|
||||||
|
|
||||||
void Server::stopThread() {
|
void Server::stopThread() {
|
||||||
m_ServerRunning = false;
|
m_ServerRunning = false;
|
||||||
if (m_Thread.joinable())
|
|
||||||
m_Thread.join();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::start(std::uint16_t port) {
|
bool Server::start(std::uint16_t port) {
|
||||||
@@ -54,19 +58,24 @@ bool Server::start(std::uint16_t port) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::stop() {
|
void Server::clean() {
|
||||||
if (!m_ServerRunning)
|
|
||||||
return;
|
|
||||||
stopThread();
|
|
||||||
|
|
||||||
protocol::DisconnectPacket packet("Server closed");
|
|
||||||
broadcastPacket(&packet);
|
|
||||||
|
|
||||||
m_Listener.close();
|
m_Listener.close();
|
||||||
m_Listener.destroy();
|
m_Listener.destroy();
|
||||||
|
|
||||||
m_Connections.clear();
|
m_Connections.clear();
|
||||||
getPlayers().clear();
|
getPlayers().clear();
|
||||||
|
|
||||||
|
std::cout << "Server successfully stopped !\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::stop() {
|
||||||
|
if (!m_ServerRunning)
|
||||||
|
return;
|
||||||
|
|
||||||
|
protocol::DisconnectPacket packet("Server closed");
|
||||||
|
broadcastPacket(&packet);
|
||||||
|
|
||||||
|
stopThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::tick(std::uint64_t delta) {
|
void Server::tick(std::uint64_t delta) {
|
||||||
|
|||||||
@@ -4,14 +4,22 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
ServerGame::ServerGame(server::Server* server) : game::Game(&m_ServerWorld), m_Server(server), m_ServerWorld(server, this) {
|
ServerGame::ServerGame(server::Server* server) : game::Game(&m_ServerWorld), m_Server(server), m_ServerWorld(server, this),
|
||||||
|
m_GoldMineTimer{ 1000, std::bind(&ServerGame::updateGoldMines, this) },
|
||||||
|
m_MobStatesTimer{ 5000, std::bind(&ServerGame::updateMobStates, this) },
|
||||||
|
m_EndGameCooldown{ 1000 * 10 } {
|
||||||
|
bindListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerGame::tick(std::uint64_t delta) {
|
void ServerGame::tick(std::uint64_t delta) {
|
||||||
if (m_GameState == game::GameState::Game) {
|
if (m_GameState == game::GameState::Game) {
|
||||||
Game::tick(delta);
|
Game::tick(delta);
|
||||||
|
m_MobStatesTimer.update(delta);
|
||||||
updatePlayerStats();
|
updatePlayerStats();
|
||||||
|
} else if (m_GameState == game::GameState::EndGame) {
|
||||||
|
if (m_EndGameCooldown.update(delta)) {
|
||||||
|
notifyListeners(&game::GameListener::OnGameClose);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +59,14 @@ void ServerGame::updateGoldMines() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerGame::updateMobStates() {
|
||||||
|
protocol::UpdateMobStatesPacket packet;
|
||||||
|
for (auto mob : m_World->getMobList()) {
|
||||||
|
packet.addMobState({ mob->getMobID(), mob->getCenter(), mob->getHealth(), mob->getDirection() });
|
||||||
|
}
|
||||||
|
m_Server->broadcastPacket(&packet);
|
||||||
|
}
|
||||||
|
|
||||||
void ServerGame::balanceTeams() {
|
void ServerGame::balanceTeams() {
|
||||||
for (auto& playerInfo : Game::m_Players) {
|
for (auto& playerInfo : Game::m_Players) {
|
||||||
game::Player& player = playerInfo.second;
|
game::Player& player = playerInfo.second;
|
||||||
@@ -70,5 +86,31 @@ void ServerGame::balanceTeams() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerGame::OnGameStateUpdate(game::GameState newState) {
|
||||||
|
setGameState(newState);
|
||||||
|
protocol::UpdateGameStatePacket packet(newState);
|
||||||
|
m_Server->broadcastPacket(&packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerGame::OnGameBegin() {
|
||||||
|
notifyListeners(&game::GameListener::OnGameStateUpdate, game::GameState::Game);
|
||||||
|
startGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerGame::OnGameEnd() {
|
||||||
|
notifyListeners(&game::GameListener::OnGameStateUpdate, game::GameState::EndGame);
|
||||||
|
m_EndGameCooldown.applyCooldown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerGame::OnGameClose() {
|
||||||
|
notifyListeners(&game::GameListener::OnGameStateUpdate, game::GameState::Closed);
|
||||||
|
// Disconnect clients
|
||||||
|
protocol::DisconnectPacket packet("Game finished");
|
||||||
|
m_Server->broadcastPacket(&packet);
|
||||||
|
|
||||||
|
// Closing server
|
||||||
|
m_Server->close();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ void ServerWorld::spawnMobs(game::MobType type, std::uint8_t level, game::Player
|
|||||||
float minSpawnY = spawnCenterY - spawnHeight / 2.0f + mobSize.y / 2.0f;
|
float minSpawnY = spawnCenterY - spawnHeight / 2.0f + mobSize.y / 2.0f;
|
||||||
float maxSpawnY = spawnCenterY + spawnHeight / 2.0f - mobSize.y / 2.0f;
|
float maxSpawnY = spawnCenterY + spawnHeight / 2.0f - mobSize.y / 2.0f;
|
||||||
|
|
||||||
float mobX = utils::getRandomReal<float>(minSpawnX, maxSpawnX);
|
float mobX = utils::getRandomReal<float>(minSpawnX + MobSpawnBorder, maxSpawnX - MobSpawnBorder);
|
||||||
float mobY = utils::getRandomReal<float>(minSpawnY, maxSpawnY);
|
float mobY = utils::getRandomReal<float>(minSpawnY + MobSpawnBorder, maxSpawnY - MobSpawnBorder);
|
||||||
|
|
||||||
spawnMobAt(m_CurrentMobID, type, level, sender, mobX, mobY, enemyMobSpawn->getDirection());
|
spawnMobAt(m_CurrentMobID, type, level, sender, mobX, mobY, enemyMobSpawn->getDirection());
|
||||||
|
|
||||||
@@ -55,5 +55,24 @@ game::TowerPtr ServerWorld::placeTowerAt(game::TowerType type, std::int32_t x, s
|
|||||||
return tower;
|
return tower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerWorld::OnMobDie(game::Mob* mob) {
|
||||||
|
if (mob->OnDeath(this)) { // check if the mob is actually dead (slimes ...)
|
||||||
|
//reward players
|
||||||
|
game::Player* sender = m_Game->getPlayerById(mob->getSender());
|
||||||
|
sender->addExp(mob->getStats()->getExpReward());
|
||||||
|
|
||||||
|
game::Player* killer = m_Game->getPlayerById(mob->getLastDamageTower()->getBuilder());
|
||||||
|
killer->addGold(mob->getStats()->getMoneyCost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerWorld::OnMobCastleDamage(game::Mob* damager, game::TeamCastle* enemyCastle, float damage) {
|
||||||
|
// calling base class event
|
||||||
|
World::OnMobCastleDamage(damager, enemyCastle, damage);
|
||||||
|
|
||||||
|
protocol::UpdateCastleLifePacket packet(enemyCastle->getLife(), enemyCastle->getTeam()->getColor());
|
||||||
|
m_Server->broadcastPacket(&packet);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace server
|
} // namespace server
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ static std::map<PacketType, PacketCreator> packets = {
|
|||||||
{PacketType::RemoveTower, []() -> PacketPtr {return std::make_unique<RemoveTowerPacket>(); } },
|
{PacketType::RemoveTower, []() -> PacketPtr {return std::make_unique<RemoveTowerPacket>(); } },
|
||||||
{PacketType::SendMobs, []() -> PacketPtr {return std::make_unique<SendMobsPacket>(); } },
|
{PacketType::SendMobs, []() -> PacketPtr {return std::make_unique<SendMobsPacket>(); } },
|
||||||
{PacketType::UpgradeTower, []() -> PacketPtr {return std::make_unique<UpgradeTowerPacket>(); } },
|
{PacketType::UpgradeTower, []() -> PacketPtr {return std::make_unique<UpgradeTowerPacket>(); } },
|
||||||
|
{PacketType::UpdateCastleLife, []() -> PacketPtr {return std::make_unique<UpdateCastleLifePacket>(); } },
|
||||||
|
{PacketType::UpdateMobStates, []() -> PacketPtr {return std::make_unique<UpdateMobStatesPacket>(); } },
|
||||||
};
|
};
|
||||||
|
|
||||||
PacketPtr createPacket(PacketType type, DataBuffer& buffer) {
|
PacketPtr createPacket(PacketType type, DataBuffer& buffer) {
|
||||||
|
|||||||
@@ -91,14 +91,16 @@ DataBuffer WorldBeginDataPacket::SerializeCustom() const {
|
|||||||
|
|
||||||
memcpy((std::uint8_t*)data.data() + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
memcpy((std::uint8_t*)data.data() + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
||||||
|
|
||||||
|
data << m_Header.m_Background;
|
||||||
|
|
||||||
const game::Spawn& redSpawn = m_Header.m_RedSpawn, blueSpawn = m_Header.m_BlueSpawn;
|
const game::Spawn& redSpawn = m_Header.m_RedSpawn, blueSpawn = m_Header.m_BlueSpawn;
|
||||||
const game::TeamCastle& redCastle = m_Header.m_RedCastle, blueCastle = m_Header.m_BlueCastle;
|
const game::TeamCastle& redCastle = m_Header.m_RedCastle, blueCastle = m_Header.m_BlueCastle;
|
||||||
|
|
||||||
data << redSpawn << redCastle;
|
data << redSpawn << static_cast<utils::shape::Rectangle>(redCastle);
|
||||||
data << blueSpawn << blueCastle;
|
data << blueSpawn << static_cast<utils::shape::Rectangle>(blueCastle);
|
||||||
|
|
||||||
// tile palette
|
// tile palette
|
||||||
data << m_Header.m_TilePalette.size();
|
data << static_cast<std::uint64_t>(m_Header.m_TilePalette.size());
|
||||||
|
|
||||||
for (game::TilePtr tile : m_Header.m_TilePalette) {
|
for (game::TilePtr tile : m_Header.m_TilePalette) {
|
||||||
data << tile;
|
data << tile;
|
||||||
@@ -123,14 +125,16 @@ DataBuffer WorldBeginDataPacket::Serialize() const {
|
|||||||
|
|
||||||
memcpy((std::uint8_t*)data.data() + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
memcpy((std::uint8_t*)data.data() + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
||||||
|
|
||||||
|
data << m_Header.m_World->getBackgroundColor();
|
||||||
|
|
||||||
const game::Spawn& redSpawn = m_Header.m_World->getRedTeam().getSpawn(), blueSpawn = m_Header.m_World->getBlueTeam().getSpawn();
|
const game::Spawn& redSpawn = m_Header.m_World->getRedTeam().getSpawn(), blueSpawn = m_Header.m_World->getBlueTeam().getSpawn();
|
||||||
const game::TeamCastle& redCastle = m_Header.m_World->getRedTeam().getCastle(), blueCastle = m_Header.m_World->getBlueTeam().getCastle();
|
const game::TeamCastle& redCastle = m_Header.m_World->getRedTeam().getCastle(), blueCastle = m_Header.m_World->getBlueTeam().getCastle();
|
||||||
|
|
||||||
data << redSpawn << redCastle;
|
data << redSpawn << static_cast<utils::shape::Rectangle>(redCastle);
|
||||||
data << blueSpawn << blueCastle;
|
data << blueSpawn << static_cast<utils::shape::Rectangle>(blueCastle);
|
||||||
|
|
||||||
// tile palette
|
// tile palette
|
||||||
data << m_Header.m_World->getTilePalette().size();
|
data << static_cast<std::uint64_t>(m_Header.m_World->getTilePalette().size());
|
||||||
|
|
||||||
for (game::TilePtr tile : m_Header.m_World->getTilePalette()) {
|
for (game::TilePtr tile : m_Header.m_World->getTilePalette()) {
|
||||||
data << tile;
|
data << tile;
|
||||||
@@ -155,8 +159,15 @@ void WorldBeginDataPacket::Deserialize(DataBuffer& data) {
|
|||||||
|
|
||||||
data.SetReadOffset(data.GetReadOffset() + decoPalletteSizeByte);
|
data.SetReadOffset(data.GetReadOffset() + decoPalletteSizeByte);
|
||||||
|
|
||||||
data >> m_Header.m_RedSpawn >> m_Header.m_RedCastle;
|
data >> m_Header.m_Background;
|
||||||
data >> m_Header.m_BlueSpawn >> m_Header.m_BlueCastle;
|
|
||||||
|
utils::shape::Rectangle redCastle, blueCastle;
|
||||||
|
|
||||||
|
data >> m_Header.m_RedSpawn >> redCastle;
|
||||||
|
data >> m_Header.m_BlueSpawn >> blueCastle;
|
||||||
|
|
||||||
|
m_Header.m_RedCastle.setShape(redCastle);
|
||||||
|
m_Header.m_BlueCastle.setShape(blueCastle);
|
||||||
|
|
||||||
std::uint64_t tilePaletteSize;
|
std::uint64_t tilePaletteSize;
|
||||||
data >> tilePaletteSize;
|
data >> tilePaletteSize;
|
||||||
@@ -524,6 +535,34 @@ void UpgradeTowerPacket::Deserialize(DataBuffer& data) {
|
|||||||
data >> m_TowerID >> m_TowerLevel;
|
data >> m_TowerID >> m_TowerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataBuffer UpdateCastleLifePacket::Serialize() const {
|
||||||
|
DataBuffer data;
|
||||||
|
data << getID() << m_CastleLife << m_Team;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateCastleLifePacket::Deserialize(DataBuffer& data) {
|
||||||
|
data >> m_CastleLife >> m_Team;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataBuffer UpdateMobStatesPacket::Serialize() const {
|
||||||
|
DataBuffer data;
|
||||||
|
data << getID() << static_cast<std::uint64_t>(m_MobStates.size());
|
||||||
|
for (auto mobState : m_MobStates) {
|
||||||
|
data << mobState;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateMobStatesPacket::Deserialize(DataBuffer& data) {
|
||||||
|
std::uint64_t mobCount;
|
||||||
|
data >> mobCount;
|
||||||
|
m_MobStates.resize(mobCount);
|
||||||
|
for (std::uint64_t mobIndex = 0; mobIndex < mobCount; mobIndex++) {
|
||||||
|
data >> m_MobStates[mobIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
REGISTER_DISPATCH_CLASS(PlayerLoginPacket);
|
REGISTER_DISPATCH_CLASS(PlayerLoginPacket);
|
||||||
REGISTER_DISPATCH_CLASS(WorldBeginDataPacket);
|
REGISTER_DISPATCH_CLASS(WorldBeginDataPacket);
|
||||||
REGISTER_DISPATCH_CLASS(WorldDataPacket);
|
REGISTER_DISPATCH_CLASS(WorldDataPacket);
|
||||||
@@ -546,6 +585,8 @@ REGISTER_DISPATCH_CLASS(WorldAddTowerPacket);
|
|||||||
REGISTER_DISPATCH_CLASS(RemoveTowerPacket);
|
REGISTER_DISPATCH_CLASS(RemoveTowerPacket);
|
||||||
REGISTER_DISPATCH_CLASS(SendMobsPacket);
|
REGISTER_DISPATCH_CLASS(SendMobsPacket);
|
||||||
REGISTER_DISPATCH_CLASS(UpgradeTowerPacket);
|
REGISTER_DISPATCH_CLASS(UpgradeTowerPacket);
|
||||||
|
REGISTER_DISPATCH_CLASS(UpdateCastleLifePacket);
|
||||||
|
REGISTER_DISPATCH_CLASS(UpdateMobStatesPacket);
|
||||||
|
|
||||||
} // namespace protocol
|
} // namespace protocol
|
||||||
} // namespace td
|
} // namespace td
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
Renderer::Renderer() {
|
Renderer::Renderer() : m_BackgroundColor(0, 0, 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ void Renderer::updateIsometricFade() {
|
|||||||
|
|
||||||
void Renderer::prepare() {
|
void Renderer::prepare() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(m_BackgroundColor.r, m_BackgroundColor.g, m_BackgroundColor.b, 0);
|
||||||
updateIsometricFade();
|
updateIsometricFade();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ WorldRenderer::WorldRenderer(game::World* world, client::ClientGame* client) : m
|
|||||||
m_Renderer->setCamMovement({});
|
m_Renderer->setCamMovement({});
|
||||||
m_TowerPlacePopup = std::make_unique<gui::TowerPlacePopup>(m_Client->getClient());
|
m_TowerPlacePopup = std::make_unique<gui::TowerPlacePopup>(m_Client->getClient());
|
||||||
m_MobTooltip = std::make_unique<gui::MobTooltip>(m_Client->getClient());
|
m_MobTooltip = std::make_unique<gui::MobTooltip>(m_Client->getClient());
|
||||||
m_Client->getWorld().getWorldNotifier().bindListener(this);
|
m_CastleTooltip = std::make_unique<gui::CastleTooltip>(m_Client->getClient());
|
||||||
|
m_Client->getWorldClient().getWorldNotifier().bindListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldRenderer::updateCursorPos() {
|
void WorldRenderer::updateCursorPos() {
|
||||||
@@ -100,6 +101,8 @@ void WorldRenderer::renderTowers() const {
|
|||||||
void WorldRenderer::renderTileSelect() const {
|
void WorldRenderer::renderTileSelect() const {
|
||||||
if (ImGui::IsAnyItemHovered()) return;
|
if (ImGui::IsAnyItemHovered()) return;
|
||||||
|
|
||||||
|
if(m_MobTooltip->isShown() || m_CastleTooltip->isShown()) return;
|
||||||
|
|
||||||
Renderer::Model tileSelectModel;
|
Renderer::Model tileSelectModel;
|
||||||
tileSelectModel.vao = m_SelectTileVao.get();
|
tileSelectModel.vao = m_SelectTileVao.get();
|
||||||
tileSelectModel.positon = { (int)m_CursorPos.x, (int)m_CursorPos.y };
|
tileSelectModel.positon = { (int)m_CursorPos.x, (int)m_CursorPos.y };
|
||||||
@@ -119,7 +122,7 @@ void WorldRenderer::render() {
|
|||||||
renderMobs();
|
renderMobs();
|
||||||
renderTowers();
|
renderTowers();
|
||||||
renderTileSelect();
|
renderTileSelect();
|
||||||
renderMobTooltip();
|
renderTooltips();
|
||||||
renderPopups();
|
renderPopups();
|
||||||
detectClick();
|
detectClick();
|
||||||
}
|
}
|
||||||
@@ -128,6 +131,11 @@ WorldRenderer::~WorldRenderer() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldRenderer::renderTooltips() const {
|
||||||
|
renderMobTooltip();
|
||||||
|
renderCastleTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
void WorldRenderer::moveCam(float relativeX, float relativeY, float aspectRatio) {
|
void WorldRenderer::moveCam(float relativeX, float relativeY, float aspectRatio) {
|
||||||
if (m_WorldVao == nullptr)
|
if (m_WorldVao == nullptr)
|
||||||
return;
|
return;
|
||||||
@@ -245,6 +253,13 @@ void WorldRenderer::renderMobTooltip() const {
|
|||||||
m_MobTooltip->render();
|
m_MobTooltip->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldRenderer::renderCastleTooltip() const {
|
||||||
|
if (ImGui::IsAnyItemHovered()) return;
|
||||||
|
|
||||||
|
detectCastleHovering();
|
||||||
|
m_CastleTooltip->render();
|
||||||
|
}
|
||||||
|
|
||||||
void WorldRenderer::detectMobHovering() const {
|
void WorldRenderer::detectMobHovering() const {
|
||||||
glm::vec2 cursorWorldPos = getCursorWorldPos();
|
glm::vec2 cursorWorldPos = getCursorWorldPos();
|
||||||
for (game::MobPtr mob : m_World->getMobList()) {
|
for (game::MobPtr mob : m_World->getMobList()) {
|
||||||
@@ -256,6 +271,17 @@ void WorldRenderer::detectMobHovering() const {
|
|||||||
m_MobTooltip->setMob(nullptr);
|
m_MobTooltip->setMob(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldRenderer::detectCastleHovering() const {
|
||||||
|
glm::vec2 cursorWorldPos = getCursorWorldPos();
|
||||||
|
for (const game::Team& team : m_World->getTeams()) {
|
||||||
|
if (team.getCastle().collidesWith({ cursorWorldPos.x, cursorWorldPos.y })) {
|
||||||
|
m_CastleTooltip->setCastle(&team.getCastle());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_CastleTooltip->setCastle(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldRenderer::OnTowerAdd(game::TowerPtr tower) {
|
void WorldRenderer::OnTowerAdd(game::TowerPtr tower) {
|
||||||
WorldLoader::RenderData renderData = WorldLoader::loadTowerModel(tower);
|
WorldLoader::RenderData renderData = WorldLoader::loadTowerModel(tower);
|
||||||
m_TowersCache.addData(tower->getID(), renderData.positions, renderData.colors);
|
m_TowersCache.addData(tower->getID(), renderData.positions, renderData.colors);
|
||||||
|
|||||||
27
src/render/gui/CastleTooltip.cpp
Normal file
27
src/render/gui/CastleTooltip.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include "render/gui/CastleTooltip.h"
|
||||||
|
#include "render/gui/imgui/imgui.h"
|
||||||
|
|
||||||
|
#include "render/WorldRenderer.h"
|
||||||
|
|
||||||
|
#include "game/client/Client.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace gui {
|
||||||
|
|
||||||
|
CastleTooltip::CastleTooltip(client::Client* client) : GuiWidget(client) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CastleTooltip::render() {
|
||||||
|
if (m_Castle == nullptr) return;
|
||||||
|
|
||||||
|
ImGui::BeginTooltip();
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, render::WorldRenderer::getImGuiTeamColor(m_Castle->getTeam()->getColor()));
|
||||||
|
ImGui::Text("Castle : ");
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::Text("\tCastle HP : %i/%i", static_cast<int>(m_Castle->getLife()), game::TeamCastle::CastleMaxLife);
|
||||||
|
ImGui::EndTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
|
} // namespace td
|
||||||
@@ -14,6 +14,8 @@ GameMenu::GameMenu(client::Client* client) : GuiWidget(client), m_SummonMenu(std
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GameMenu::render() {
|
void GameMenu::render() {
|
||||||
|
if(!m_Client->isConnected()) return;
|
||||||
|
|
||||||
if (getClient()->getGame().getGameState() == td::game::GameState::Lobby) {
|
if (getClient()->getGame().getGameState() == td::game::GameState::Lobby) {
|
||||||
ImGui::Begin("Lobby");
|
ImGui::Begin("Lobby");
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ MainMenu::~MainMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::render() {
|
void MainMenu::render() {
|
||||||
|
if (m_Server != nullptr && !m_Server->isRunning()) {
|
||||||
|
m_Server.reset(0); // destroying server if it stoped
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_Client->isConnected()) return;
|
||||||
|
|
||||||
ImGui::Begin("Main Menu");
|
ImGui::Begin("Main Menu");
|
||||||
if (ImGui::Button("Rejoindre une partie##join")) {
|
if (ImGui::Button("Rejoindre une partie##join")) {
|
||||||
ImGui::OpenPopup("Rejoindre une partie##join_popup");
|
ImGui::OpenPopup("Rejoindre une partie##join_popup");
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ namespace td {
|
|||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
void TowerGui::initWidgets() {
|
void TowerGui::initWidgets() {
|
||||||
m_MainMenu = std::make_unique<td::gui::MainMenu>(m_Client.get());
|
m_GuiManager.addWidget(std::make_unique<td::gui::MainMenu>(m_Client.get()));
|
||||||
m_GameMenu = std::make_unique<td::gui::GameMenu>(m_Client.get());
|
m_GuiManager.addWidget(std::make_unique<td::gui::GameMenu>(m_Client.get()));
|
||||||
m_FrameMenu = std::make_unique<td::gui::FrameMenu>(m_Client.get());
|
m_GuiManager.addWidget(std::make_unique<td::gui::FrameMenu>(m_Client.get()));
|
||||||
m_UpdateMenu = std::make_unique<td::gui::UpdateMenu>(m_Client.get());
|
m_GuiManager.addWidget(std::make_unique<td::gui::UpdateMenu>(m_Client.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TowerGui::TowerGui(SDL_Window* sdl_window, SDL_GLContext glContext, td::render::Renderer* renderer) : m_Window(sdl_window),
|
TowerGui::TowerGui(SDL_Window* sdl_window, SDL_GLContext glContext, td::render::Renderer* renderer) : m_Window(sdl_window),
|
||||||
@@ -69,13 +69,8 @@ void TowerGui::render() {
|
|||||||
beginFrame();
|
beginFrame();
|
||||||
|
|
||||||
m_Client->render();
|
m_Client->render();
|
||||||
if (m_Client->isConnected())
|
|
||||||
m_GameMenu->render();
|
|
||||||
else
|
|
||||||
m_MainMenu->render();
|
|
||||||
|
|
||||||
m_FrameMenu->render();
|
m_GuiManager.renderWidgets();
|
||||||
m_UpdateMenu->render();
|
|
||||||
|
|
||||||
endFrame();
|
endFrame();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
/*
|
|
||||||
* EntityShader.cpp
|
|
||||||
*
|
|
||||||
* Created on: 4 nov. 2020
|
|
||||||
* Author: simon
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "render/shaders/EntityShader.h"
|
#include "render/shaders/EntityShader.h"
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
|||||||
Reference in New Issue
Block a user