add hit "animation"
This commit is contained in:
@@ -89,6 +89,7 @@ private:
|
|||||||
Direction m_Direction;
|
Direction m_Direction;
|
||||||
std::vector<EffectDuration> m_Effects;
|
std::vector<EffectDuration> m_Effects;
|
||||||
const Tower* m_LastDamage; // the last tower that damaged the mob
|
const Tower* m_LastDamage; // the last tower that damaged the mob
|
||||||
|
float m_HitCooldown;
|
||||||
|
|
||||||
utils::Timer m_EffectFireTimer;
|
utils::Timer m_EffectFireTimer;
|
||||||
utils::Timer m_EffectPoisonTimer;
|
utils::Timer m_EffectPoisonTimer;
|
||||||
@@ -99,7 +100,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Mob(MobID id, MobLevel level, PlayerID sender) : m_Sender(sender), m_Level(level),
|
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) {
|
m_EffectHealTimer(1000), m_CastleTarget(nullptr), m_AttackTimer(1000) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -123,8 +124,16 @@ public:
|
|||||||
const Tower* GetLastDamageTower() { return m_LastDamage; }
|
const Tower* GetLastDamageTower() { return m_LastDamage; }
|
||||||
bool HasReachedEnemyCastle() { return m_CastleTarget != nullptr; }
|
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 Damage(float dmg, const Tower* damager) {
|
||||||
void Heal(float heal) { m_Health = std::min(static_cast<float>(GetStats()->GetMaxLife()), m_Health + heal); }
|
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
|
void SetMobReachedCastle(TeamCastle* castle) { m_CastleTarget = castle; } // used when mob is in front of the castle
|
||||||
|
|
||||||
bool IsImmuneTo(TowerType type);
|
bool IsImmuneTo(TowerType type);
|
||||||
@@ -133,6 +142,8 @@ public:
|
|||||||
void AddEffect(EffectType type, float durationSec, Tower* tower);
|
void AddEffect(EffectType type, float durationSec, Tower* tower);
|
||||||
bool HasEffect(EffectType type);
|
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 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
|
float GetTileY() { return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY())); } // returns a float between 0 and 1 excluded
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
struct Model {
|
struct Model {
|
||||||
GL::VertexArray* vao;
|
GL::VertexArray* vao;
|
||||||
Vec2f positon;
|
Vec2f positon;
|
||||||
|
Vec3f color = { 1, 1, 1 };
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ private:
|
|||||||
unsigned int m_LocationAspectRatio = 0;
|
unsigned int m_LocationAspectRatio = 0;
|
||||||
unsigned int m_LocationTranslation = 0;
|
unsigned int m_LocationTranslation = 0;
|
||||||
unsigned int m_LocationViewtype = 0;
|
unsigned int m_LocationViewtype = 0;
|
||||||
|
unsigned int m_LocationColorEffect = 0;
|
||||||
protected:
|
protected:
|
||||||
virtual void GetAllUniformLocation();
|
virtual void GetAllUniformLocation();
|
||||||
public:
|
public:
|
||||||
@@ -24,6 +25,7 @@ public:
|
|||||||
void SetAspectRatio(float aspectRatio);
|
void SetAspectRatio(float aspectRatio);
|
||||||
void SetModelPos(const Vec2f& modelPos);
|
void SetModelPos(const Vec2f& modelPos);
|
||||||
void SetIsometricView(float isometric);
|
void SetIsometricView(float isometric);
|
||||||
|
void SetColorEffect(const Vec3f& color);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace shader
|
} // namespace shader
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ bool Mob::IsTouchingCastle(const TeamCastle& enemyCastle) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Mob::Tick(std::uint64_t delta, World* world) {
|
void Mob::Tick(std::uint64_t delta, World* world) {
|
||||||
|
m_HitCooldown = std::max(0.0f, m_HitCooldown - static_cast<float>(delta / 1000.0f));
|
||||||
UpdateEffects(delta, world);
|
UpdateEffects(delta, world);
|
||||||
Move(delta, world);
|
Move(delta, world);
|
||||||
AttackCastle(delta, world);
|
AttackCastle(delta, world);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ void Renderer::RenderVAO(const GL::VertexArray& vao) {
|
|||||||
void Renderer::RenderModel(const Model& model) {
|
void Renderer::RenderModel(const Model& model) {
|
||||||
m_EntityShader->Start();
|
m_EntityShader->Start();
|
||||||
m_EntityShader->SetModelPos(model.positon);
|
m_EntityShader->SetModelPos(model.positon);
|
||||||
|
m_EntityShader->SetColorEffect(model.color);
|
||||||
model.vao->Bind();
|
model.vao->Bind();
|
||||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(model.vao->GetVertexCount()));
|
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(model.vao->GetVertexCount()));
|
||||||
model.vao->Unbind();
|
model.vao->Unbind();
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ void WorldRenderer::RenderMobs() const {
|
|||||||
Renderer::Model model;
|
Renderer::Model model;
|
||||||
model.vao = m_MobVao.get();
|
model.vao = m_MobVao.get();
|
||||||
model.positon = { mob->GetCenterX(), mob->GetCenterY() };
|
model.positon = { mob->GetCenterX(), mob->GetCenterY() };
|
||||||
|
model.color = mob->HasTakenDamage() ? Vec3f{ 1, 0.5, 0.5 } : Vec3f{ 1, 1, 1 };
|
||||||
m_Renderer->RenderModel(model);
|
m_Renderer->RenderModel(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,13 +39,16 @@ flat in int pass_color;
|
|||||||
|
|
||||||
out vec4 out_color;
|
out vec4 out_color;
|
||||||
|
|
||||||
|
uniform vec3 ColorEffect;
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
||||||
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
||||||
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
||||||
float a = float(pass_color & 0xFF) / 255.0;
|
float a = float(pass_color & 0xFF) / 255.0;
|
||||||
out_color = vec4(r, g, b, a);
|
vec3 intermediate_color = vec3(r, g, b) * ColorEffect;
|
||||||
|
out_color = vec4(intermediate_color, a);
|
||||||
|
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
@@ -81,13 +84,16 @@ flat in int pass_color;
|
|||||||
|
|
||||||
out vec4 out_color;
|
out vec4 out_color;
|
||||||
|
|
||||||
|
uniform vec3 ColorEffect;
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
||||||
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
||||||
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
||||||
float a = float(pass_color & 0xFF) / 255.0;
|
float a = float(pass_color & 0xFF) / 255.0;
|
||||||
out_color = vec4(r, g, b, a);
|
vec3 intermediate_color = vec3(r, g, b) * ColorEffect;
|
||||||
|
out_color = vec4(intermediate_color, a);
|
||||||
|
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
@@ -105,6 +111,7 @@ void EntityShader::GetAllUniformLocation() {
|
|||||||
m_LocationCam = static_cast<unsigned int>(GetUniformLocation("camPos"));
|
m_LocationCam = static_cast<unsigned int>(GetUniformLocation("camPos"));
|
||||||
m_LocationTranslation = static_cast<unsigned int>(GetUniformLocation("translation"));
|
m_LocationTranslation = static_cast<unsigned int>(GetUniformLocation("translation"));
|
||||||
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
|
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
|
||||||
|
m_LocationColorEffect = static_cast<unsigned int>(GetUniformLocation("ColorEffect"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityShader::SetCamPos(const Vec2f& camPos) {
|
void EntityShader::SetCamPos(const Vec2f& camPos) {
|
||||||
@@ -122,7 +129,9 @@ void EntityShader::SetModelPos(const Vec2f& modelPos) {
|
|||||||
void EntityShader::SetIsometricView(float isometric) {
|
void EntityShader::SetIsometricView(float isometric) {
|
||||||
LoadFloat(m_LocationViewtype, isometric);
|
LoadFloat(m_LocationViewtype, isometric);
|
||||||
}
|
}
|
||||||
|
void EntityShader::SetColorEffect(const Vec3f& color) {
|
||||||
|
LoadVector(m_LocationColorEffect, color);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace shader
|
} // namespace shader
|
||||||
} // namespace td
|
} // namespace td
|
||||||
Reference in New Issue
Block a user