-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticle_state.cpp
More file actions
26 lines (21 loc) · 808 Bytes
/
particle_state.cpp
File metadata and controls
26 lines (21 loc) · 808 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
#include "include/state_management.h"
void particle_update(Particle& p) {
p.vel.y += 0.1;
p.pos.x += p.vel.x;
p.pos.y += p.vel.y;
p.ttl--;
// Increase opacity based on the remaining ttl
float alpha = 1.0f - (static_cast<float>(p.ttl) / static_cast<float>(p.max_ttl));
p.clr.a = static_cast<uint8_t>(alpha * 255);
// Decrease size based on the remaining ttl
p.size = static_cast<int>(p.original_size * (1.0f - (alpha/2.0f)));
}
void update_particles(GameState& g) {
for (auto& p : g.particles) {
particle_update(p);
}
// Remove dead particles
g.particles.erase(std::remove_if(g.particles.begin(), g.particles.end(),
[](const Particle& p) { return p.ttl <= 0; }),
g.particles.end());
}