-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulletsManager.cpp
36 lines (29 loc) · 971 Bytes
/
BulletsManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "BulletsManager.hpp"
void BulletsManager::addBullet(sf::Texture& texture, float x, float y, float direction, sf::String const shooter, int const team) {
bullets.push_back(Bullet(texture, x, y, direction, shooter, team));
}
void BulletsManager::removeBullet(unsigned int const a) {
bullets.erase(BulletsManager::bullets.begin() + a);
}
void BulletsManager::eraseAllBullets() {
std::vector<Bullet> emptyVector;
bullets.swap(emptyVector);
}
Bullet& BulletsManager::getBullet(unsigned int const a) {
return bullets[a];
}
unsigned int BulletsManager::bulletsCount() {
return bullets.size();
}
void BulletsManager::draw(sf::RenderWindow& window) {
for(auto& bullet : bullets) bullet.draw(window);
}
void BulletsManager::update(float dt) {
for(int a(bulletsCount() - 1); a >= 0 ; a--) {
Bullet& bullet = getBullet(a);
bullet.update(dt);
if(!bullet.alive()) {
removeBullet(a);
}
}
}