This commit is contained in:
2025-07-16 00:32:40 +02:00
parent d1690192db
commit aaf76a3ff0
41 changed files with 2963 additions and 599 deletions

86
include/td/game/Team.h Normal file
View File

@@ -0,0 +1,86 @@
#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() {
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:
const Team* m_Team;
float m_Life;
public:
static constexpr int CastleMaxLife = 1000;
TeamCastle(const Team* team) : m_Team(team), m_Life(CastleMaxLife) {
SetWidth(5);
SetHeight(5);
}
TeamCastle() : TeamCastle(nullptr) {}
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 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;
};
typedef std::array<Team, 2> TeamList;
} // namespace game
} // namespace td