Złączono i wszystko działa, ale trzeba zrobić mocny refactor Planszy bo za dużo niewiadomo skąd biorących się pętli

This commit is contained in:
2024-12-13 20:05:11 +01:00
parent fdf67f4bc2
commit 80a4b1b397
5 changed files with 30 additions and 83 deletions

View File

@@ -8,7 +8,7 @@
#include <SFML/Graphics/Text.hpp>
Player::Player(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
hp = 3;
}
Player* Player::getInstance(int x, int y, const sf::Texture& texture) {
@@ -21,7 +21,6 @@ Player* Player::getInstance(int x, int y, const sf::Texture& texture) {
void Player::loadTexture() {
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
hp = 3;
damageDealClock.restart();
originalColor = actorSprite.getColor();
}
@@ -64,43 +63,10 @@ void Player::update() {
void Player::takeDamage() {
if (!isImmortal) {
if (health > 0) {
health--;
std::cout << "Player hit! Remaining health: " << health << "\n";
if (hp > 0) {
hp--;
isImmortal = true; // Aktywuj chwilową nieśmiertelność
immortalityClock.restart();
if (health <= 0) {
std::cout << "Player has been destroyed!\n";
std::cout << "You lost the game!\n";
}
}
}
}
bool Player::isAlive() const {
return health > 0;
}
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
}
}
}