-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectileSystem.h
More file actions
39 lines (33 loc) · 962 Bytes
/
Copy pathProjectileSystem.h
File metadata and controls
39 lines (33 loc) · 962 Bytes
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
37
38
39
#pragma once
#include "Projectile.h"
#include <vector>
#include "AssetManager.h"
class ProjectileSystem {
public:
std::vector<std::shared_ptr<Projectile>> projectiles;
// Update all projectiles
void update(double dt) {
for (auto& p : projectiles)
p->update(dt);
removeDead();
}
// Draw all projectiles
void render(SpriteRenderer& renderer, AssetManager& assets) {
for (auto& p : projectiles) {
auto* tex = assets.getTexture(p->spriteName);
renderer.Draw(tex->id, p->getWorldMatrix());
}
}
// Add any projectile type
void addProjectile(const std::shared_ptr<Projectile>& proj) {
projectiles.push_back(proj);
}
private:
void removeDead() {
projectiles.erase(
std::remove_if(projectiles.begin(), projectiles.end(),
[](auto& p) { return p->isDead(); }),
projectiles.end()
);
}
};