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

@@ -1,5 +1,7 @@
#include "../headers/Actor.h"
#include <iostream>
Actor::Actor(int x, int y, std::string path) {
loadTexture(path);
position.x = x;
@@ -29,13 +31,17 @@ std::vector<Bullet> &Actor::getBullets() {
}
void Actor::updateBullets() {
for (auto& bullet : bullets) {
if(bullet.isOutOfBounds()) {
bullets.erase(bullets.begin());
for (auto it = bullets.begin(); it != bullets.end(); ) {
if (it->isOutOfBounds()) {
it = bullets.erase(it); // Usuwa element i zwraca iterator na następny element
} else {
++it; // Przechodzi do następnego elementu
}
}
std::cout << "Liczba pociskow: " << bullets.size() << std::endl;
}
void Actor::setMovingSpeed(float speed) {
moving_speed = speed;
}