Statek miga

przy uderzeniu w meteoryt
This commit is contained in:
2024-12-06 15:16:57 +01:00
parent 2f9e0ba236
commit 71f8ebe285
4 changed files with 30 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ Player::Player(int x, int y, std::string path) : Actor(x, y, std::move(path)) {
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
hp = 3;
damageDealClock.restart();
originalColor = actorSprite.getColor();
};
void Player::shoot() {
@@ -25,6 +26,27 @@ void Player::alternate_shoot() {
}
}
void Player::onHit() {
dealDamage();
isBlinking = true;
}
void Player::update() {
if (isBlinking) {
auto elapsed = damageDealClock.getElapsedTime().asMilliseconds();
if (elapsed < 1000) { // miganie przez 1 sekundę
if ((elapsed / 100) % 2 == 0) {
actorSprite.setColor(sf::Color(255, 255, 255, 128)); // półprzeźroczysty
} else {
actorSprite.setColor(originalColor); // oryginalny kolor
}
} else {
isBlinking = false;
actorSprite.setColor(originalColor); // przywróć oryginalny kolor
}
}
}
void Player::setFirerate(unsigned int firerate) {
this->firerate = firerate;
}