add hit "animation"

This commit is contained in:
2023-01-02 16:37:18 +01:00
parent 1200a6e087
commit fcda12e321
7 changed files with 109 additions and 83 deletions

View File

@@ -89,6 +89,7 @@ private:
Direction m_Direction;
std::vector<EffectDuration> m_Effects;
const Tower* m_LastDamage; // the last tower that damaged the mob
float m_HitCooldown;
utils::Timer m_EffectFireTimer;
utils::Timer m_EffectPoisonTimer;
@@ -99,7 +100,7 @@ private:
public:
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
m_HitCooldown(0), m_EffectFireTimer(1000), m_EffectPoisonTimer(1000),
m_EffectHealTimer(1000), m_CastleTarget(nullptr), m_AttackTimer(1000) {
}
@@ -123,8 +124,16 @@ public:
const Tower* GetLastDamageTower() { return m_LastDamage; }
bool HasReachedEnemyCastle() { return m_CastleTarget != nullptr; }
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); }
void Damage(float dmg, const Tower* damager) {
m_Health = std::max(0.0f, m_Health - dmg);
m_LastDamage = damager;
m_HitCooldown = 0.1;
}
void Heal(float heal) {
m_Health = std::min(static_cast<float>(GetStats()->GetMaxLife()), m_Health + heal);
}
void SetMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
bool IsImmuneTo(TowerType type);
@@ -133,6 +142,8 @@ public:
void AddEffect(EffectType type, float durationSec, Tower* tower);
bool HasEffect(EffectType type);
bool HasTakenDamage() { return m_HitCooldown > 0; }
float GetTileX() { return GetCenterX() - static_cast<float>(static_cast<std::int32_t>(GetCenterX())); } // returns a float between 0 and 1 excluded
float GetTileY() { return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY())); } // returns a float between 0 and 1 excluded

View File

@@ -16,6 +16,7 @@ public:
struct Model {
GL::VertexArray* vao;
Vec2f positon;
Vec3f color = { 1, 1, 1 };
};
private:
std::unique_ptr<shader::WorldShader> m_WorldShader;

View File

@@ -13,6 +13,7 @@ private:
unsigned int m_LocationAspectRatio = 0;
unsigned int m_LocationTranslation = 0;
unsigned int m_LocationViewtype = 0;
unsigned int m_LocationColorEffect = 0;
protected:
virtual void GetAllUniformLocation();
public:
@@ -24,6 +25,7 @@ public:
void SetAspectRatio(float aspectRatio);
void SetModelPos(const Vec2f& modelPos);
void SetIsometricView(float isometric);
void SetColorEffect(const Vec3f& color);
};
} // namespace shader