Multiple fixes

Obracające się meteoryty, koniec gry przy natrafieniu na meteoryt.
Poprawione sprajty statku, meteorytu i pocisku
This commit is contained in:
2024-11-21 15:50:25 +01:00
parent b16fd9fad5
commit 2bdfbb193c
9 changed files with 42 additions and 16 deletions

View File

@@ -17,7 +17,8 @@ int main()
backgroundTexture.loadFromFile("../assets/img/space.jpg"); // wczytywanie tła
sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła
Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
// TODO: Przenieść tworzenie statku wewnątrz klasy Plansza
Player ship(window.getSize().x/2,window.getSize().y - 100, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
ship.setMovingSpeed(8);
ship.setFirerate(200);
@@ -83,6 +84,24 @@ int main()
ship.updateBullets();
window.draw(ship.getSprite());
// trochę dziwny sposób ale jednak działa
for (auto& meteor : plansza.getMeteors()) {
if(ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
std::cout << "You lost the game!\n";
window.close();
exit(-2); // Kod -2 oznacza uderzenie się w meteoryt
}
}
// TODO: Poprawić kolizję pocisku z meteorem, tak aby był kasowany tylko ten konkretny meteoryt
// for (auto meteorIt = plansza.getMeteors().begin(); meteorIt != plansza.getMeteors().end(); ++meteorIt) {
// for (auto& bullet : ship.getBullets()) {
// if (meteorIt->getSprite().getGlobalBounds().intersects(bullet.getSprite().getGlobalBounds())) {
// meteorIt = plansza.getMeteors().erase(meteorIt);
// break; // Exit the inner loop to avoid invalidating the iterator
// }
// }
// }
window.display();
}