Compare commits
7 Commits
alpha-0.0.
...
alpha-0.1.
| Author | SHA1 | Date | |
|---|---|---|---|
| 208892d266 | |||
| 4384806cf0 | |||
| 1a091baeaf | |||
| 43f21ffd44 | |||
| 24617c539f | |||
| 4611a198c9 | |||
| d40ffe8f6c |
@@ -19,7 +19,7 @@ typedef std::map<std::uint8_t, Player> PlayerList;
|
|||||||
class Game {
|
class Game {
|
||||||
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 +49,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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -172,6 +180,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 +214,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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ 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);
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,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 +129,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; }
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
27
include/render/gui/CastleTooltip.h
Normal file
27
include/render/gui/CastleTooltip.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
|
} // namespace td
|
||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "misc/DataBuffer.h"
|
||||||
|
|
||||||
#include <ctime>
|
#define TD_VERSION "alpha-0.1.1"
|
||||||
|
|
||||||
#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();
|
||||||
|
|
||||||
@@ -328,5 +332,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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet
|
|||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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() {
|
||||||
@@ -119,7 +120,7 @@ void WorldRenderer::render() {
|
|||||||
renderMobs();
|
renderMobs();
|
||||||
renderTowers();
|
renderTowers();
|
||||||
renderTileSelect();
|
renderTileSelect();
|
||||||
renderMobTooltip();
|
renderTooltips();
|
||||||
renderPopups();
|
renderPopups();
|
||||||
detectClick();
|
detectClick();
|
||||||
}
|
}
|
||||||
@@ -128,6 +129,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 +251,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 +269,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
|
||||||
@@ -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