New Projectiles class
Refactor of Bullet class Different method of shooting.
This commit is contained in:
30
main.cpp
30
main.cpp
@@ -102,6 +102,11 @@ int main()
|
||||
mainWindow.draw(bullet.getSprite());
|
||||
}
|
||||
|
||||
for (auto& rocket : ship.getRockets()) {
|
||||
rocket.update();
|
||||
mainWindow.draw(rocket.getSprite());
|
||||
}
|
||||
|
||||
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
||||
plansza.update_meteors();
|
||||
ship.updateBullets();
|
||||
@@ -143,14 +148,31 @@ int main()
|
||||
|
||||
for (auto meteorIt = plansza.getMeteors().begin(); meteorIt != plansza.getMeteors().end(); ) {
|
||||
bool meteorHit = false;
|
||||
for (auto bulletIt = ship.getBullets().begin(); bulletIt != ship.getBullets().end(); ) {
|
||||
if (meteorIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||
bulletIt = ship.getBullets().erase(bulletIt);
|
||||
for (auto rocketIt = ship.getBullets().begin(); rocketIt != ship.getBullets().end(); ) {
|
||||
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
ship.getBullets().erase(rocketIt);
|
||||
meteorIt = plansza.getMeteors().erase(meteorIt);
|
||||
meteorHit = true;
|
||||
break;
|
||||
} else {
|
||||
++bulletIt;
|
||||
++rocketIt;
|
||||
}
|
||||
}
|
||||
if (!meteorHit) {
|
||||
++meteorIt;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto meteorIt = plansza.getMeteors().begin(); meteorIt != plansza.getMeteors().end(); ) {
|
||||
bool meteorHit = false;
|
||||
for (auto rocketIt = ship.getRockets().begin(); rocketIt != ship.getRockets().end(); ) {
|
||||
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
ship.getRockets().erase(rocketIt);
|
||||
meteorIt = plansza.getMeteors().erase(meteorIt);
|
||||
meteorHit = true;
|
||||
break;
|
||||
} else {
|
||||
++rocketIt;
|
||||
}
|
||||
}
|
||||
if (!meteorHit) {
|
||||
|
||||
Reference in New Issue
Block a user