Compare commits
13 Commits
alpha-0.1.
...
alpha-0.1.
| Author | SHA1 | Date | |
|---|---|---|---|
| f70661694b | |||
| 36a1ab0572 | |||
| 409268b604 | |||
| 174d144d26 | |||
| 360258e4cf | |||
| 2148c0050c | |||
| 61166023df | |||
| e7bf22cea6 | |||
| f09f79198d | |||
| 8c19d3cc3c | |||
| 208892d266 | |||
| 4384806cf0 | |||
| 1a091baeaf |
@@ -12,11 +12,25 @@ enum class GameState : std::uint8_t {
|
||||
Game,
|
||||
EndGame,
|
||||
Disconnected,
|
||||
Closed
|
||||
};
|
||||
|
||||
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:
|
||||
World* m_World;
|
||||
TeamList m_Teams = { Team{TeamColor::Red}, Team{TeamColor::Blue} };
|
||||
|
||||
@@ -56,6 +56,13 @@ struct Color {
|
||||
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 {
|
||||
virtual TileType getType() const = 0;
|
||||
};
|
||||
@@ -134,6 +141,7 @@ protected:
|
||||
TowerTileColorPalette m_TowerPlacePalette;
|
||||
Color m_WalkablePalette;
|
||||
std::vector<Color> m_DecorationPalette;
|
||||
Color m_Background;
|
||||
|
||||
std::unordered_map<ChunkCoord, ChunkPtr> m_Chunks;
|
||||
|
||||
@@ -152,8 +160,6 @@ protected:
|
||||
public:
|
||||
World(Game* game);
|
||||
|
||||
static constexpr std::uint8_t CastleWidth = 5, CastleHeight = 5;
|
||||
|
||||
bool loadMap(const protocol::WorldBeginDataPacket* worldHeader);
|
||||
bool loadMap(const protocol::WorldDataPacket* worldData);
|
||||
|
||||
@@ -172,6 +178,7 @@ public:
|
||||
const TowerTileColorPalette& getTowerTileColorPalette() const { return m_TowerPlacePalette; }
|
||||
const Color& getWalkableTileColor() const { return m_WalkablePalette; }
|
||||
const std::vector<Color>& getDecorationPalette() const { return m_DecorationPalette; }
|
||||
const Color& getBackgroundColor() const { return m_Background; }
|
||||
|
||||
const TilePalette& getTilePalette() const { return m_TilePalette; }
|
||||
|
||||
@@ -225,7 +232,6 @@ public:
|
||||
// MobListener
|
||||
|
||||
virtual void OnMobDamage(Mob* target, float damage, Tower* source);
|
||||
virtual void OnMobDie(Mob* mob);
|
||||
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage);
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,16 +19,16 @@ class Client {
|
||||
private:
|
||||
render::Renderer* m_Renderer;
|
||||
ClientConnexion m_Connexion;
|
||||
ClientGame m_Game;
|
||||
std::unique_ptr<ClientGame> m_Game;
|
||||
bool m_Connected;
|
||||
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; }
|
||||
render::Renderer* getRenderer() const { return m_Renderer; }
|
||||
|
||||
ClientGame& getGame() { return m_Game; }
|
||||
ClientGame& getGame() { return *m_Game; }
|
||||
ClientConnexion& getConnexion() { return m_Connexion; }
|
||||
|
||||
void tick(std::uint64_t delta);
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
void placeTower(game::TowerType type, const glm::vec2& position);
|
||||
void upgradeTower(game::TowerID tower, game::TowerLevel level);
|
||||
void removeTower(game::TowerID tower);
|
||||
private:
|
||||
void reset();
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
Client* getClient() const { return m_Client; }
|
||||
|
||||
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::PlayerJoinPacket* packet);
|
||||
|
||||
@@ -61,12 +61,11 @@ private:
|
||||
bool m_ServerRunning;
|
||||
public:
|
||||
Server(const std::string& worldFilePath);
|
||||
virtual ~Server() {}
|
||||
virtual ~Server();
|
||||
|
||||
bool start(std::uint16_t port);
|
||||
void stop();
|
||||
|
||||
void lauchGame();
|
||||
void stop(); // force the server to stop
|
||||
void close(); // at the end of a game
|
||||
|
||||
void removeConnexion(std::uint8_t connexionID);
|
||||
|
||||
@@ -74,6 +73,8 @@ public:
|
||||
|
||||
float getTPS() const { return m_TickCounter.getTPS(); }
|
||||
|
||||
bool isRunning() { return m_ServerRunning; }
|
||||
|
||||
const ServerGame& getGame() const { return m_Game; }
|
||||
ServerGame& getGame() { return m_Game; }
|
||||
|
||||
@@ -88,6 +89,7 @@ private:
|
||||
void accept();
|
||||
void updateSockets();
|
||||
|
||||
void clean();
|
||||
void startThread();
|
||||
void stopThread();
|
||||
void tick(std::uint64_t delta);
|
||||
|
||||
@@ -9,11 +9,12 @@ namespace server {
|
||||
|
||||
class Server;
|
||||
|
||||
class ServerGame : public game::Game {
|
||||
class ServerGame : public game::Game, public game::GameListener {
|
||||
private:
|
||||
Server* m_Server;
|
||||
ServerWorld m_ServerWorld;
|
||||
utils::AutoTimer m_GoldMineTimer{ 1000, std::bind(&ServerGame::updateGoldMines, this) };
|
||||
utils::CooldownTimer m_EndGameCooldown{ 1000 * 10 };
|
||||
public:
|
||||
ServerGame(Server* server);
|
||||
~ServerGame() {}
|
||||
@@ -22,6 +23,13 @@ public:
|
||||
|
||||
virtual void tick(std::uint64_t delta);
|
||||
void startGame();
|
||||
|
||||
// GameListener
|
||||
|
||||
virtual void OnGameStateUpdate(game::GameState newState);
|
||||
virtual void OnGameBegin();
|
||||
virtual void OnGameEnd();
|
||||
virtual void OnGameClose();
|
||||
private:
|
||||
void balanceTeams();
|
||||
void updateGoldMines();
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
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);
|
||||
|
||||
virtual void OnMobDie(game::Mob* mob);
|
||||
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
||||
@@ -338,7 +338,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include <basetsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
//typedef SSIZE_T ssize_t;
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
|
||||
@@ -45,6 +45,7 @@ struct WorldHeader {
|
||||
game::TowerTileColorPalette m_TowerPlacePalette;
|
||||
game::Color m_WalkablePalette;
|
||||
std::vector<game::Color> m_DecorationPalette;
|
||||
game::Color m_Background;
|
||||
|
||||
game::SpawnColorPalette m_SpawnColorPalette;
|
||||
|
||||
@@ -128,6 +129,7 @@ public:
|
||||
const game::TowerTileColorPalette& getTowerTilePalette() const { return m_Header.m_TowerPlacePalette; }
|
||||
const game::Color& getWalkableTileColor() const { return m_Header.m_WalkablePalette; }
|
||||
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& getBlueSpawn() const { return m_Header.m_BlueSpawn; }
|
||||
|
||||
@@ -29,6 +29,8 @@ private:
|
||||
std::unique_ptr<WorldShader> m_WorldShader;
|
||||
std::unique_ptr<EntityShader> m_EntityShader;
|
||||
|
||||
glm::vec3 m_BackgroundColor;
|
||||
|
||||
bool m_IsometricView = true;
|
||||
float m_IsometricShade = m_IsometricView;
|
||||
glm::vec2 m_CamPos{};
|
||||
@@ -49,6 +51,8 @@ public:
|
||||
void setCamPos(const glm::vec2& newPos);
|
||||
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);
|
||||
private:
|
||||
void updateIsometricView();
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
virtual void render();
|
||||
|
||||
void setCastle(const game::TeamCastle* castle) { m_Castle = castle; }
|
||||
bool isShown() { return m_Castle != nullptr; }
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -10,15 +10,17 @@ namespace gui {
|
||||
|
||||
class GuiManager {
|
||||
private:
|
||||
std::vector<std::shared_ptr<GuiWidget>> m_Widgets;
|
||||
std::vector<std::unique_ptr<GuiWidget>> m_Widgets;
|
||||
public:
|
||||
GuiManager(){}
|
||||
|
||||
void renderWidgets() {
|
||||
for (auto widget : m_Widgets) {
|
||||
for (auto& widget : m_Widgets) {
|
||||
widget->render();
|
||||
}
|
||||
}
|
||||
|
||||
void addWidgets(const std::shared_ptr<GuiWidget>& widget) {
|
||||
void addWidget(std::unique_ptr<GuiWidget>&& widget) {
|
||||
m_Widgets.push_back(std::move(widget));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
virtual void render();
|
||||
|
||||
void setMob(const game::Mob* mob) { m_Mob = mob; }
|
||||
bool isShown() { return m_Mob != nullptr; }
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "render/gui/GuiManager.h"
|
||||
|
||||
struct SDL_Window;
|
||||
typedef void* SDL_GLContext;
|
||||
|
||||
@@ -20,15 +22,6 @@ class Client;
|
||||
|
||||
} // namespace client
|
||||
|
||||
namespace gui {
|
||||
|
||||
class MainMenu;
|
||||
class GameMenu;
|
||||
class FrameMenu;
|
||||
class UpdateMenu;
|
||||
|
||||
} // namespace gui
|
||||
|
||||
namespace render {
|
||||
|
||||
class Renderer;
|
||||
@@ -38,11 +31,8 @@ private:
|
||||
SDL_Window* m_Window;
|
||||
SDL_GLContext m_GlContext;
|
||||
td::render::Renderer* m_Renderer;
|
||||
td::gui::GuiManager m_GuiManager;
|
||||
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:
|
||||
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
|
||||
~TowerGui();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "misc/DataBuffer.h"
|
||||
|
||||
#define TD_VERSION "alpha-0.1.0"
|
||||
#define TD_VERSION "alpha-0.1.2"
|
||||
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
@@ -37,6 +37,7 @@ bool World::loadMap(const protocol::WorldBeginDataPacket* worldHeader) {
|
||||
m_TowerPlacePalette = worldHeader->getTowerTilePalette();
|
||||
m_WalkablePalette = worldHeader->getWalkableTileColor();
|
||||
m_DecorationPalette = worldHeader->getDecorationPalette();
|
||||
m_Background = worldHeader->getBackgroundColor();
|
||||
|
||||
getRedTeam().getSpawn() = worldHeader->getRedSpawn();
|
||||
getBlueTeam().getSpawn() = worldHeader->getBlueSpawn();
|
||||
@@ -105,6 +106,8 @@ bool World::saveMap(const std::string& fileName) const {
|
||||
}
|
||||
|
||||
void World::tick(std::uint64_t delta) {
|
||||
if (m_Game->getGameState() != GameState::Game) return;
|
||||
|
||||
tickMobs(delta);
|
||||
for (TowerPtr tower : m_Towers) {
|
||||
tower->tick(delta, this);
|
||||
@@ -218,17 +221,6 @@ bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const
|
||||
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() {
|
||||
// safely remove mobs when unused
|
||||
for (std::size_t i = 0; i < m_Mobs.size(); i++) {
|
||||
@@ -292,7 +284,7 @@ void World::OnExplosion(utils::shape::Circle explosion, float centerDamage, Towe
|
||||
void World::OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {
|
||||
enemyCastle->damage(damage);
|
||||
if (enemyCastle->getLife() <= 0) {
|
||||
// TODO: a team has won
|
||||
m_Game->notifyListeners(&GameListener::OnGameEnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,19 @@ void Client::tick(std::uint64_t delta) {
|
||||
m_Connected = m_Connexion.updateSocket();
|
||||
if (!m_Connected) {
|
||||
std::cout << "Disconnected ! (Reason : " << m_Connexion.getDisconnectReason() << ")\n";
|
||||
reset();
|
||||
} else {
|
||||
m_Game.tick(delta);
|
||||
m_Game->tick(delta);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
ClientConnexion::ClientConnexion() : Connexion(&m_Dispatcher) {
|
||||
ClientConnexion::ClientConnexion() : Connexion(&m_Dispatcher), m_ServerTPS(0) {
|
||||
registerHandlers();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ void ClientGame::HandlePacket(const protocol::UpdateMoneyPacket* packet) {
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::DisconnectPacket* packet) {
|
||||
m_GameState = game::GameState::Disconnected;
|
||||
m_Renderer->setBackgroundColor({ 0, 0, 0 });
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
||||
@@ -37,10 +37,8 @@ void Lobby::tick() {
|
||||
return;
|
||||
|
||||
if (utils::getTime() - m_StartTimerTime >= LobbyWaitingTime) {
|
||||
protocol::UpdateGameStatePacket packet(game::GameState::Game);
|
||||
m_Server->broadcastPacket(&packet);
|
||||
m_Server->getGame().notifyListeners(&game::GameListener::OnGameBegin);
|
||||
m_GameStarted = true;
|
||||
m_Server->lauchGame();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ Server::Server(const std::string& worldFilePath) : m_ServerRunning(false) {
|
||||
m_Game.getWorld()->loadMapFromFile(worldFilePath);
|
||||
}
|
||||
|
||||
void Server::lauchGame() {
|
||||
m_Game.startGame();
|
||||
Server::~Server() {
|
||||
if (m_Thread.joinable())
|
||||
m_Thread.join();
|
||||
}
|
||||
|
||||
void Server::startThread() {
|
||||
@@ -29,13 +30,16 @@ void Server::startThread() {
|
||||
}
|
||||
|
||||
}
|
||||
clean();
|
||||
});
|
||||
}
|
||||
|
||||
void Server::close() {
|
||||
stopThread();
|
||||
}
|
||||
|
||||
void Server::stopThread() {
|
||||
m_ServerRunning = false;
|
||||
if (m_Thread.joinable())
|
||||
m_Thread.join();
|
||||
}
|
||||
|
||||
bool Server::start(std::uint16_t port) {
|
||||
@@ -54,19 +58,24 @@ bool Server::start(std::uint16_t port) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::stop() {
|
||||
if (!m_ServerRunning)
|
||||
return;
|
||||
stopThread();
|
||||
|
||||
protocol::DisconnectPacket packet("Server closed");
|
||||
broadcastPacket(&packet);
|
||||
|
||||
void Server::clean() {
|
||||
m_Listener.close();
|
||||
m_Listener.destroy();
|
||||
|
||||
m_Connections.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) {
|
||||
|
||||
@@ -5,13 +5,17 @@ namespace td {
|
||||
namespace server {
|
||||
|
||||
ServerGame::ServerGame(server::Server* server) : game::Game(&m_ServerWorld), m_Server(server), m_ServerWorld(server, this) {
|
||||
|
||||
bindListener(this);
|
||||
}
|
||||
|
||||
void ServerGame::tick(std::uint64_t delta) {
|
||||
if (m_GameState == game::GameState::Game) {
|
||||
Game::tick(delta);
|
||||
updatePlayerStats();
|
||||
} else if (m_GameState == game::GameState::EndGame) {
|
||||
if (m_EndGameCooldown.update(delta)) {
|
||||
notifyListeners(&game::GameListener::OnGameClose);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,5 +74,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 td
|
||||
|
||||
@@ -55,5 +55,16 @@ game::TowerPtr ServerWorld::placeTowerAt(game::TowerType type, std::int32_t x, s
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace td
|
||||
|
||||
@@ -91,6 +91,8 @@ DataBuffer WorldBeginDataPacket::SerializeCustom() const {
|
||||
|
||||
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::TeamCastle& redCastle = m_Header.m_RedCastle, blueCastle = m_Header.m_BlueCastle;
|
||||
|
||||
@@ -123,6 +125,8 @@ DataBuffer WorldBeginDataPacket::Serialize() const {
|
||||
|
||||
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::TeamCastle& redCastle = m_Header.m_World->getRedTeam().getCastle(), blueCastle = m_Header.m_World->getBlueTeam().getCastle();
|
||||
|
||||
@@ -155,6 +159,8 @@ void WorldBeginDataPacket::Deserialize(DataBuffer& data) {
|
||||
|
||||
data.SetReadOffset(data.GetReadOffset() + decoPalletteSizeByte);
|
||||
|
||||
data >> m_Header.m_Background;
|
||||
|
||||
utils::shape::Rectangle redCastle, blueCastle;
|
||||
|
||||
data >> m_Header.m_RedSpawn >> redCastle;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
Renderer::Renderer() {
|
||||
Renderer::Renderer() : m_BackgroundColor(0, 0, 0) {
|
||||
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void Renderer::updateIsometricFade() {
|
||||
|
||||
void Renderer::prepare() {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClearColor(m_BackgroundColor.r, m_BackgroundColor.g, m_BackgroundColor.b, 0);
|
||||
updateIsometricFade();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ WorldRenderer::WorldRenderer(game::World* world, client::ClientGame* client) : m
|
||||
m_TowerPlacePopup = std::make_unique<gui::TowerPlacePopup>(m_Client->getClient());
|
||||
m_MobTooltip = std::make_unique<gui::MobTooltip>(m_Client->getClient());
|
||||
m_CastleTooltip = std::make_unique<gui::CastleTooltip>(m_Client->getClient());
|
||||
m_Client->getWorld().getWorldNotifier().bindListener(this);
|
||||
m_Client->getWorldClient().getWorldNotifier().bindListener(this);
|
||||
}
|
||||
|
||||
void WorldRenderer::updateCursorPos() {
|
||||
@@ -101,6 +101,8 @@ void WorldRenderer::renderTowers() const {
|
||||
void WorldRenderer::renderTileSelect() const {
|
||||
if (ImGui::IsAnyItemHovered()) return;
|
||||
|
||||
if(m_MobTooltip->isShown() || m_CastleTooltip->isShown()) return;
|
||||
|
||||
Renderer::Model tileSelectModel;
|
||||
tileSelectModel.vao = m_SelectTileVao.get();
|
||||
tileSelectModel.positon = { (int)m_CursorPos.x, (int)m_CursorPos.y };
|
||||
|
||||
@@ -14,6 +14,8 @@ GameMenu::GameMenu(client::Client* client) : GuiWidget(client), m_SummonMenu(std
|
||||
}
|
||||
|
||||
void GameMenu::render() {
|
||||
if(!m_Client->isConnected()) return;
|
||||
|
||||
if (getClient()->getGame().getGameState() == td::game::GameState::Lobby) {
|
||||
ImGui::Begin("Lobby");
|
||||
|
||||
|
||||
@@ -18,6 +18,12 @@ MainMenu::~MainMenu() {
|
||||
}
|
||||
|
||||
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");
|
||||
if (ImGui::Button("Rejoindre une partie##join")) {
|
||||
ImGui::OpenPopup("Rejoindre une partie##join_popup");
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace td {
|
||||
namespace render {
|
||||
|
||||
void TowerGui::initWidgets() {
|
||||
m_MainMenu = std::make_unique<td::gui::MainMenu>(m_Client.get());
|
||||
m_GameMenu = std::make_unique<td::gui::GameMenu>(m_Client.get());
|
||||
m_FrameMenu = 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::MainMenu>(m_Client.get()));
|
||||
m_GuiManager.addWidget(std::make_unique<td::gui::GameMenu>(m_Client.get()));
|
||||
m_GuiManager.addWidget(std::make_unique<td::gui::FrameMenu>(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),
|
||||
@@ -69,13 +69,8 @@ void TowerGui::render() {
|
||||
beginFrame();
|
||||
|
||||
m_Client->render();
|
||||
if (m_Client->isConnected())
|
||||
m_GameMenu->render();
|
||||
else
|
||||
m_MainMenu->render();
|
||||
|
||||
m_FrameMenu->render();
|
||||
m_UpdateMenu->render();
|
||||
m_GuiManager.renderWidgets();
|
||||
|
||||
endFrame();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/*
|
||||
* EntityShader.cpp
|
||||
*
|
||||
* Created on: 4 nov. 2020
|
||||
* Author: simon
|
||||
*/
|
||||
|
||||
#include "render/shaders/EntityShader.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
Reference in New Issue
Block a user