[Add] Health bar now shows only when character is being attacked.
This commit is contained in:
parent
4481a46889
commit
ca3eb4ece7
@ -119,7 +119,9 @@ void Character::Render(void) {
|
||||
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][_animationStage]);
|
||||
}
|
||||
|
||||
_healthBar.Draw();
|
||||
if(_healthBarDuration.IsStarted() && (_healthBarDuration.GetTicks() < 5000)) {
|
||||
_healthBar.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Character::Update(void) {
|
||||
@ -142,6 +144,10 @@ void Character::Update(void) {
|
||||
_healthBar.SetProgress((float)_health / 100.0f);
|
||||
}
|
||||
|
||||
void Character::OnAttack(void) {
|
||||
_healthBarDuration.Start();
|
||||
}
|
||||
|
||||
void Character::Move(void) {
|
||||
x += xVel;
|
||||
tileX = (int)(((x + (w / 2)) / TILE_WIDTH));
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
void Render(void);
|
||||
void Update(void);
|
||||
|
||||
void OnAttack(void);
|
||||
|
||||
inline void* operator new(size_t size) {
|
||||
return gMemManager.Allocate(size);
|
||||
}
|
||||
@ -101,6 +103,7 @@ protected:
|
||||
static const int ANIM_ATTACK = 3;
|
||||
|
||||
Bar _healthBar;
|
||||
Timer _healthBarDuration;
|
||||
|
||||
private:
|
||||
static const int ANIMATION_SPEED = 200;
|
||||
|
@ -92,6 +92,7 @@ void WorldManager::OnPlayerAttack(Character* player) {
|
||||
}
|
||||
|
||||
npc->SetHealth(npc->GetHealth() - 5);
|
||||
npc->OnAttack();
|
||||
|
||||
if(npc->GetHealth() <= 0) {
|
||||
i = _npcs.erase(i);
|
||||
|
Loading…
Reference in New Issue
Block a user