Files
Tower-Defense/include/game/Team.h
2021-12-12 13:32:39 +01:00

93 lines
1.8 KiB
C++

#pragma once
#include "Types.h"
#include "misc/Shapes.h"
#include <vector>
#include <memory>
#include <cmath>
namespace td {
namespace game {
class Player;
enum class TeamColor : std::int8_t {
None = -1,
Red,
Blue
};
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);
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