feat: implement basic tower placement

This commit is contained in:
2021-09-19 13:43:45 +02:00
parent bcde4278ab
commit 52a143769e
17 changed files with 318 additions and 52 deletions

View File

@@ -1,14 +1,16 @@
#include "game/client/ClientGame.h"
#include "protocol/PacketDispatcher.h"
//#include "game/Team.h"
#include "game/client/Client.h"
#include <iostream>
namespace td {
namespace client {
ClientGame::ClientGame(protocol::PacketDispatcher* dispatcher, render::Renderer* renderer): protocol::PacketHandler(dispatcher),
game::Game(&m_WorldClient), m_Renderer(renderer), m_WorldClient(this), m_WorldRenderer(&m_WorldClient, m_Renderer){
ClientGame::ClientGame(Client* client): protocol::PacketHandler(client->getConnexion().GetDispatcher()),
game::Game(&m_WorldClient), m_Client(client), m_Renderer(client->getRenderer()), m_WorldClient(this),
m_WorldRenderer(&m_WorldClient, this){
GetDispatcher()->RegisterHandler(protocol::PacketType::ConnectionInfo, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerJoin, this);
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerList, this);
@@ -111,5 +113,54 @@ void ClientGame::renderWorld(){
}
}
void ClientGame::PlaceTower(game::TowerType type, const glm::vec2& position){
protocol::PlaceTowerPacket packet(position.x, position.y, type);
m_Client->getConnexion().sendPacket(&packet);
}
bool ClientGame::CanPlaceLittleTower(const glm::vec2& worldPos){
game::TilePtr tile = m_WorldClient.getTile(worldPos.x, worldPos.y);
if(tile == nullptr){
return false;
}
if(tile->getType() == game::TileType::Tower){
for(int x = -1; x < 2; x++){
for(int y = -1; y < 2; y++){
game::TilePtr adjacentTile = m_WorldClient.getTile(worldPos.x + x, worldPos.y + y);
if(adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower){
return false;
}
}
}
return true;
}
return false;
}
bool ClientGame::CanPlaceBigTower(const glm::vec2& worldPos){
game::TilePtr tile = m_WorldClient.getTile(worldPos.x, worldPos.y);
if(tile == nullptr){
return false;
}
if(tile->getType() == game::TileType::Tower){
for(int x = -2; x < 3; x++){
for(int y = -2; y < 3; y++){
game::TilePtr adjacentTile = m_WorldClient.getTile(worldPos.x + x, worldPos.y + y);
if(adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower){
return false;
}
}
}
return true;
}
return false;
}
} // namespace client
} // namespace td