feat: improved tower place + tower upgrade

This commit is contained in:
2021-11-05 17:35:39 +01:00
parent 524af9ad5f
commit f863fb4942
6 changed files with 87 additions and 32 deletions

View File

@@ -202,7 +202,7 @@ bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) co
for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) {
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower) {
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower || getTower({worldPos.x + x, worldPos.y + y}) != nullptr) {
return false;
}
}
@@ -214,6 +214,8 @@ bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) co
}
bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const {
if(!CanPlaceLittleTower(worldPos, playerID)) return false;
TilePtr tile = getTile(worldPos.x, worldPos.y);
const Player& player = m_Game->getPlayers()[playerID];
@@ -228,7 +230,7 @@ bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const
for (int x = -2; x < 3; x++) {
for (int y = -2; y < 3; y++) {
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower) {
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower || getTower({worldPos.x + x, worldPos.y + y}) != nullptr) {
return false;
}
}
@@ -257,7 +259,7 @@ void World::cleanDeadMobs() {
}
}
TowerPtr World::GetTower(const glm::vec2& position) {
TowerPtr World::getTower(const glm::vec2& position) const{
for (TowerPtr tower : m_Towers) {
if (tower->getSize() == TowerSize::Big) {
if (tower->getX() - 2 <= position.x && tower->getX() + 3 >= position.x &&