feat: add basic tower mecanic

This commit is contained in:
2021-09-28 19:19:54 +02:00
parent 26d1dd9d36
commit 1e35146c4b
8 changed files with 104 additions and 26 deletions

View File

@@ -10,6 +10,11 @@
namespace td {
namespace game {
class World;
class Mob;
typedef std::shared_ptr<Mob> MobPtr;
enum class TowerType : std::uint8_t {
Archer = 0,
Ice,
@@ -88,19 +93,21 @@ private:
PlayerID m_Builder;
protected:
utils::Timer m_Timer;
public: // converting seconds to millis
public:
Tower(TowerID id, TowerType type, std::uint16_t x, std::uint16_t y, PlayerID builder) : m_ID(id), m_Type(type), m_X(x), m_Y(y), m_Builder(builder),
m_Timer(getStats()->getDamageRate()) {
m_Timer(getStats()->getDamageRate() * 1000) { // converting seconds to millis
}
virtual TowerType getType() const = 0;
virtual TowerSize getSize() const = 0;
virtual void tick(std::uint64_t delta) = 0;
virtual void tick(std::uint64_t delta, World* world) = 0;
void upgrade(std::uint8_t level, TowerPath path) {
m_Level.setLevel(level);
m_Level.setPath(path);
m_Timer.setInterval(getStats()->getDamageRate() * 1000); // converting seconds to millis
m_Timer.reset();
}
std::uint16_t getID() const { return m_ID; }
@@ -109,6 +116,7 @@ public: // conve
const TowerLevel& getLevel() const { return m_Level; }
const TowerStats* getStats() const { return getTowerStats(m_Type, m_Level); }
bool isMobInRange(MobPtr mob);
};
typedef std::shared_ptr<Tower> TowerPtr;
@@ -145,7 +153,7 @@ public:
virtual TowerSize getSize() const { return TowerSize::Little; }
virtual TowerType getType() const = 0;
virtual void tick(std::uint64_t delta) = 0;
virtual void tick(std::uint64_t delta, World* world) = 0;
};
class ArcherTower : public LittleTower {
@@ -153,7 +161,9 @@ public:
ArcherTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Archer; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
private:
void shootArrow(MobPtr target);
};
class IceTower : public LittleTower {
@@ -161,7 +171,7 @@ public:
IceTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Ice; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class MageTower : public LittleTower {
@@ -169,7 +179,7 @@ public:
MageTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Mage; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class PoisonTower : public LittleTower {
@@ -177,7 +187,7 @@ public:
PoisonTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Poison; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class QuakeTower : public LittleTower {
@@ -185,7 +195,7 @@ public:
QuakeTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Quake; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class ArtilleryTower : public LittleTower {
@@ -193,7 +203,7 @@ public:
ArtilleryTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Artillery; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class SorcererTower : public LittleTower {
@@ -201,7 +211,7 @@ public:
SorcererTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Sorcerer; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class ZeusTower : public LittleTower {
@@ -209,7 +219,7 @@ public:
ZeusTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : LittleTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Zeus; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
// ---------- Big Towers ----------
@@ -221,7 +231,7 @@ public:
virtual TowerSize getSize() const { return TowerSize::Big; }
virtual TowerType getType() const = 0;
virtual void tick(std::uint64_t delta) = 0;
virtual void tick(std::uint64_t delta, World* world) = 0;
};
class TurretTower : public BigTower {
@@ -229,7 +239,7 @@ public:
TurretTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Turret; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class NecromancerTower : public BigTower {
@@ -237,7 +247,7 @@ public:
NecromancerTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Necromancer; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
class LeachTower : public BigTower {
@@ -245,7 +255,7 @@ public:
LeachTower(TowerID id, std::uint16_t x, std::uint16_t y, PlayerID builder) : BigTower(id, getType(), x, y, builder) {}
virtual TowerType getType() const { return TowerType::Leach; }
virtual void tick(std::uint64_t delta);
virtual void tick(std::uint64_t delta, World* world);
};
} // namespace game

View File

@@ -184,6 +184,7 @@ public:
const TowerList& getTowers() const { return m_Towers; };
private:
void moveMobs(std::uint64_t delta);
void cleanDeadMobs();
};
} // namespace game

View File

@@ -15,7 +15,7 @@ private:
bool m_GameStarted = false;
std::uint64_t m_StartTimerTime = 0;
std::vector<std::uint8_t> m_Players;
utils::Timer m_Timer;
utils::AutoTimer m_Timer;
public:
Lobby(Server* server);

View File

@@ -13,7 +13,7 @@ class ServerGame : public game::Game {
private:
Server* m_Server;
ServerWorld m_ServerWorld;
utils::Timer m_GoldMineTimer{ 1000, std::bind(&ServerGame::updateGoldMines, this) };
utils::AutoTimer m_GoldMineTimer{ 1000, std::bind(&ServerGame::updateGoldMines, this) };
public:
ServerGame(Server* server);
~ServerGame() {}