Statek miga
przy uderzeniu w meteoryt
This commit is contained in:
@@ -17,12 +17,17 @@ public:
|
|||||||
void moveRight() override;
|
void moveRight() override;
|
||||||
void moveUp() override;
|
void moveUp() override;
|
||||||
void moveDown() override;
|
void moveDown() override;
|
||||||
|
void onHit();
|
||||||
|
void update();
|
||||||
std::vector<Rocket>& getRockets();
|
std::vector<Rocket>& getRockets();
|
||||||
private:
|
private:
|
||||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||||
std::vector<Rocket> rockets;
|
std::vector<Rocket> rockets;
|
||||||
sf::Texture rocketTexture;
|
sf::Texture rocketTexture;
|
||||||
sf::Texture bulletTexture;
|
sf::Texture bulletTexture;
|
||||||
|
bool isBlinking = false;
|
||||||
|
sf::Color originalColor;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ unsigned int Actor::getHP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Actor::dealDamage() {
|
void Actor::dealDamage() {
|
||||||
if(damageDealClock.getElapsedTime().asSeconds() > 1) {
|
if(damageDealClock.getElapsedTime().asSeconds() > 1.5) {
|
||||||
if(hp > 0) {
|
if(hp > 0) {
|
||||||
hp--;
|
hp--;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,13 +105,14 @@ void Plansza::update() {
|
|||||||
update_hearts();
|
update_hearts();
|
||||||
ship.updateBullets();
|
ship.updateBullets();
|
||||||
|
|
||||||
|
ship.update();
|
||||||
window->draw(ship.getSprite());
|
window->draw(ship.getSprite());
|
||||||
|
|
||||||
|
|
||||||
// trochę dziwny sposób ale jednak działa
|
// trochę dziwny sposób ale jednak działa
|
||||||
for (auto &meteor: meteors) {
|
for (auto &meteor: meteors) {
|
||||||
if (ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
if (ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||||
ship.dealDamage();
|
ship.onHit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
||||||
hp = 3;
|
hp = 3;
|
||||||
damageDealClock.restart();
|
damageDealClock.restart();
|
||||||
|
originalColor = actorSprite.getColor();
|
||||||
};
|
};
|
||||||
|
|
||||||
void Player::shoot() {
|
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) {
|
void Player::setFirerate(unsigned int firerate) {
|
||||||
this->firerate = firerate;
|
this->firerate = firerate;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user