Niby strzela, ale bez kolizji

This commit is contained in:
2024-12-09 17:36:57 +01:00
parent 44f4556fda
commit 13066709a7
10 changed files with 128 additions and 6 deletions

View File

@@ -159,7 +159,7 @@ void Plansza::update() {
}
// Ruch i renderowanie przeciwników
for (auto it = enemies.begin(); it != enemies.end();) {
it->moveDown(); // Przeciwnicy poruszają się w dół
it->update(); // Aktualizacja kierunku i ruchu przeciwnika
it->shoot();
// Rysowanie przeciwników
@@ -173,6 +173,28 @@ void Plansza::update() {
}
}
for (auto& enemy : enemies) { // Lista przeciwników w grze
enemy.shoot();
enemy.updateBullets();
for (auto& bullet : enemy.getBullets()) {
bullet.update();
window->draw(bullet.getSprite());
}
}
// Usuwanie pocisków, które są poza ekranem
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end(); ) {
for (auto bulletIt = enemyIt->getBullets().begin(); bulletIt != enemyIt->getBullets().end();) {
if (bulletIt->isOutOfBounds()) {
bulletIt = enemyIt->getBullets().erase(bulletIt); // Usuwamy pocisk, który wyszedł poza ekran
} else {
++bulletIt;
}
}
++enemyIt;
}
// Kolizje między pociskami gracza a przeciwnikami
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
bool hit = false;