Files
2025-07-31 13:48:26 +02:00

103 lines
2.0 KiB
C++

#pragma once
#include <td/Types.h>
#include <td/misc/Shapes.h>
#include <vector>
#include <memory>
#include <cmath>
namespace td {
namespace game {
class Player;
class Spawn : public utils::shape::Rectangle {
private:
Direction m_Direction;
public:
Spawn() : m_Direction(Direction::PositiveX) {
SetWidth(5);
SetHeight(5);
}
Direction GetDirection() const { return m_Direction; }
void SetDirection(Direction direction) { m_Direction = direction; }
};
class Team;
class TeamCastle : public utils::shape::Rectangle {
private:
float m_Life;
public:
static constexpr int CastleMaxLife = 1000;
TeamCastle() : m_Life(CastleMaxLife) {
SetWidth(5);
SetHeight(5);
}
float GetLife() const { return m_Life; }
void SetLife(float life) { m_Life = life; }
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 {
private:
std::vector<Player*> m_Players;
TeamColor m_Color;
Spawn m_Spawn;
TeamCastle m_TeamCastle;
public:
Team(TeamColor color) : m_Color(color) {}
void AddPlayer(Player* newPlayer);
void RemovePlayer(const Player* player);
TeamColor GetColor() const;
const Spawn& GetSpawn() const { return m_Spawn; }
Spawn& GetSpawn() { return m_Spawn; }
const TeamCastle& GetCastle() const { return m_TeamCastle; }
TeamCastle& GetCastle() { return m_TeamCastle; }
std::uint8_t GetPlayerCount() const;
};
struct TeamList {
std::array<Team, 2> m_Teams;
TeamList() : m_Teams{Team{TeamColor::Red}, Team{TeamColor::Blue}}{
}
Team& operator[](std::size_t a_Index) {
return m_Teams[a_Index];
}
Team& operator[](TeamColor a_Index) {
return m_Teams[static_cast<std::size_t>(a_Index)];
}
const Team& operator[](std::size_t a_Index) const {
return m_Teams[a_Index];
}
const Team& operator[](TeamColor a_Index) const {
return m_Teams[static_cast<std::size_t>(a_Index)];
}
};
} // namespace game
} // namespace td