[Add] Health bar now shows only when character is being attacked.

This commit is contained in:
Tamir Atias 2012-01-16 17:53:18 +02:00
parent 4481a46889
commit ca3eb4ece7
3 changed files with 11 additions and 1 deletions

View File

@ -119,8 +119,10 @@ void Character::Render(void) {
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][_animationStage]); ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][_animationStage]);
} }
if(_healthBarDuration.IsStarted() && (_healthBarDuration.GetTicks() < 5000)) {
_healthBar.Draw(); _healthBar.Draw();
} }
}
void Character::Update(void) { void Character::Update(void) {
Move(); Move();
@ -142,6 +144,10 @@ void Character::Update(void) {
_healthBar.SetProgress((float)_health / 100.0f); _healthBar.SetProgress((float)_health / 100.0f);
} }
void Character::OnAttack(void) {
_healthBarDuration.Start();
}
void Character::Move(void) { void Character::Move(void) {
x += xVel; x += xVel;
tileX = (int)(((x + (w / 2)) / TILE_WIDTH)); tileX = (int)(((x + (w / 2)) / TILE_WIDTH));

View File

@ -45,6 +45,8 @@ public:
void Render(void); void Render(void);
void Update(void); void Update(void);
void OnAttack(void);
inline void* operator new(size_t size) { inline void* operator new(size_t size) {
return gMemManager.Allocate(size); return gMemManager.Allocate(size);
} }
@ -101,6 +103,7 @@ protected:
static const int ANIM_ATTACK = 3; static const int ANIM_ATTACK = 3;
Bar _healthBar; Bar _healthBar;
Timer _healthBarDuration;
private: private:
static const int ANIMATION_SPEED = 200; static const int ANIMATION_SPEED = 200;

View File

@ -92,6 +92,7 @@ void WorldManager::OnPlayerAttack(Character* player) {
} }
npc->SetHealth(npc->GetHealth() - 5); npc->SetHealth(npc->GetHealth() - 5);
npc->OnAttack();
if(npc->GetHealth() <= 0) { if(npc->GetHealth() <= 0) {
i = _npcs.erase(i); i = _npcs.erase(i);