Game Development Reference
In-Depth Information
Figure
65
- Damage indicators drawn along an ellipse.
struct DamageIndicator
{
math::vector3 direction;
float duration;
float angle;
render::color color;
};
A
DamageIndicator
holds the data necessary to display an occurrence of damage on the
HUD. We are interested in knowing the direction the damage came from. We can use the
damage direction to calculate an angle value which we will use to rotate our sprite accord-
ingly.
When damage occurs we will create a
DamageIndicator
instance and we will add it into
our list of indicators.
void DamageEvent(const math::vector3& direction)
{
DamageIndicator indicator;
indicator.direction = direction * m_transform;
indicator.duration = 0.5f;
indicator.color = render::color::RED;
indicator.angle = atan2(indicator.direction.y(), indicator.direction.x()) + 3*(math::Pi/4);
m_indicators.push_back(indicator);
}
Thematrix
m_transform
isaconstantrotationbyR(π/2)itiscreatedusingthematrixfunc-
tion: