void Creep::takeDamage(int damage, Damage_Type damageType) { if (applyDamage(damage, damageType)) { displayHealthBar(); } if (m_health <= 0) { kill(damageType); } }
// Update method used when notify is called on classes it observes void DrawableCreepSquad::update() { creepSquad = CreepSquad::getCreeps(); for (int i = 0; i < (int)creepSquad.size(); ++i) { // set position of the sprite if (creepSquad[i]->getHitPoints() > 0) { sf::Sprite* creepSprite = creepSquad[i]->getSprite(); creepSprite->setPosition(creepSquad[i]->getLocationY() * 24.0f, creepSquad[i]->getLocationX() * 24.0f); // display health bar displayHealthBar(creepSquad[i]); //check if creep is slowed if (creepSquad[i]->isSlowedDown() && creepSquad[i]->getSprite()->getColor() != sf::Color::Blue) creepSquad[i]->getSprite()->setColor(sf::Color::Blue); } } }
void GreenCreep::update(float deltaTime) { Creep::update(deltaTime); if (!FlagUtil::isFlagSet(m_creepCondition, ON_FIRE) && m_health < m_maxHealth) { m_fRecoveryTime += deltaTime; if (m_fRecoveryTime > m_fTimeToRecover) { m_fRecoveryTime -= m_fTimeToRecover; m_health += m_iRecoveryRate; if (m_health > m_maxHealth) { m_health = m_maxHealth; } displayHealthBar(); } } }