feat: implement shapes for entities

This commit is contained in:
2021-11-21 20:00:35 +01:00
parent a716e46c64
commit 070749e685
11 changed files with 92 additions and 70 deletions

View File

@@ -2,6 +2,7 @@
#include "Towers.h"
#include "Types.h"
#include "Team.h"
#include <vector>
#include <memory>
@@ -75,7 +76,7 @@ const MobStats* getMobStats(MobType type, std::uint8_t level);
const TowerImmunities& getMobTowerImmunities(MobType type, std::uint8_t level);
const EffectImmunities& getMobEffectImmunities(MobType type, std::uint8_t level);
class Mob {
class Mob : public utils::shape::Rectangle{
protected:
float m_Health;
private:
@@ -84,13 +85,12 @@ private:
MobLevel m_Level;
Direction m_Direction;
std::vector<EffectDuration> m_Effects;
const Tower* m_LastDamage; // the tower that damaged the mob
const Tower* m_LastDamage; // the last tower that damaged the mob
utils::Timer m_EffectFireTimer;
utils::Timer m_EffectPoisonTimer;
utils::Timer m_EffectHealTimer;
float m_X = 0, m_Y = 0;
public:
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
m_EffectFireTimer(1000), m_EffectPoisonTimer(1000), m_EffectHealTimer(1000) {
@@ -101,7 +101,7 @@ public:
virtual void tick(std::uint64_t delta);
virtual void OnDeath(World* world) {}
virtual bool OnDeath(World* world) { return true; }
const TowerImmunities& getTowerImmunities() const { return getMobTowerImmunities(getType(), m_Level); }
const EffectImmunities& getEffectImmunities() const { return getMobEffectImmunities(getType(), m_Level); }
@@ -116,12 +116,6 @@ public:
void damage(float dmg, const Tower* damager) { m_Health = std::max(0.0f, m_Health - dmg); m_LastDamage = damager; }
void heal(float heal) { m_Health = std::min(static_cast<float>(getStats()->getMaxLife()), m_Health + heal); }
float getX() const { return m_X; }
void setX(float x) { m_X = x; }
float getY() const { return m_Y; }
void setY(float y) { m_Y = y; }
bool isImmuneTo(TowerType type);
bool isImmuneTo(EffectType type);

View File

@@ -2,6 +2,8 @@
#include "Types.h"
#include "misc/Shapes.h"
#include <vector>
#include <memory>
#include <cmath>
@@ -17,14 +19,33 @@ enum class TeamColor : std::int8_t {
Blue
};
struct Spawn {
Direction direction;
std::int32_t x, y;
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; }
};
struct TeamCastle {
std::int32_t x, y;
std::uint16_t life = 1000;
struct TeamCastle : public utils::shape::Rectangle{
private:
float m_Life;
public:
TeamCastle() : m_Life(1000) {
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); }
};
class Team {

View File

@@ -5,6 +5,8 @@
#include <memory>
#include "misc/Time.h"
#include "misc/Shapes.h"
#include "game/Types.h"
namespace td {
@@ -85,17 +87,16 @@ const TowerStats* getTowerStats(TowerType type, TowerLevel level);
typedef std::uint16_t TowerID;
class Tower {
class Tower : public utils::shape::Point {
private:
TowerID m_ID;
TowerType m_Type;
std::int32_t m_X, m_Y;
TowerLevel m_Level{};
PlayerID m_Builder;
protected:
utils::CooldownTimer m_Timer;
public:
Tower(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) : m_ID(id), m_Type(type), m_X(x), m_Y(y), m_Builder(builder),
Tower(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) : utils::shape::Point(x, y), m_ID(id), m_Type(type), m_Builder(builder),
m_Timer(getStats()->getDamageRate() * 1000) { // converting seconds to millis
}
@@ -112,8 +113,6 @@ public:
}
std::uint16_t getID() const { return m_ID; }
std::int32_t getX() const { return m_X; }
std::int32_t getY() const { return m_Y; }
const TowerLevel& getLevel() const { return m_Level; }
const TowerStats* getStats() const { return getTowerStats(m_Type, m_Level); }
PlayerID getBuilder() const { return m_Builder; }

View File

@@ -134,6 +134,8 @@ protected:
public:
World(Game* game);
static constexpr std::uint8_t CastleWidth = 5, CastleHeight = 5;
bool loadMap(const protocol::WorldBeginDataPacket* worldHeader);
bool loadMap(const protocol::WorldDataPacket* worldData);
@@ -191,6 +193,7 @@ public:
virtual void OnArrowShot(MobPtr target, Tower* shooter);
private:
void moveMobs(std::uint64_t delta);
void moveMob(MobPtr mob, std::uint64_t delta);
void tickMobs(std::uint64_t delta);
void cleanDeadMobs();
};