/// <summary> /// Draws the enemy /// </summary> void Enemy::draw() { // Draw Enemy this->window.draw(*this->sprite); // Calculates the health bar percentage float percent = (100.0f / getStartHealth()) * getHealth(); float barWidth = (this->sprite->getGlobalBounds().width) / 100.0f; // Draws the health bar sf::RectangleShape healthBar; healthBar.setSize(sf::Vector2f((barWidth * percent) / 2, 2)); healthBar.setPosition( this->sprite->getGlobalBounds().left + (barWidth * 25), this->sprite->getGlobalBounds().top - 5); healthBar.setFillColor(sf::Color::Green); window.draw(healthBar); /*sf::FloatRect bounds = this->sprite->getGlobalBounds(); sf::RectangleShape af(sf::Vector2f(bounds.width,bounds.height)); af.setPosition(bounds.left, bounds.top); af.setOutlineColor(sf::Color(141,23,22,23)); af.setFillColor(sf::Color(255,255,255,150)); this->window.draw(af);*/ }
/// <summary> /// Function for activating a power up /// </summary> /// <param name="powType">Type of the powwer up to activate</param> void Player::powerUp(Powerup::PowerUpType powType) { // Health Pack Powerup if (powType == Powerup::PowerUpType::HEALTH_INCREMENT) { if (getHealth() < getStartHealth()) { setHealth(getHealth() + 1); } } // Pulsating gun Powerup else if (powType == Powerup::PowerUpType::PULSATING_GUN) { pulsateGun = true; pwrUpTime = sf::milliseconds(0); pulseTime = sf::milliseconds(0); } }
/// <summary> /// Defines emotes processing for the enemy /// </summary> void Enemy::emotes() { // Emote queue's emotes if (!emoteQueue.empty()) { if (emoteQueue.front().first > (int)((100.0f / getStartHealth()) * getHealth())) { std::string soundToPlay = emoteQueue.front().second; emoteQueue.pop_front(); resourceHandler->getSoundByEmoteName(soundToPlay).play(); } } // Pathqueue's emotes if (this->currentPath.emote != nullptr) { this->currentPath.emote->play(); this->currentPath.emote = nullptr; } }