-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParticleSystem.cpp
36 lines (31 loc) · 1.04 KB
/
ParticleSystem.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
/**
* Defines implementation of ParticleSystem class
*
* Author: Skylar Payne
* Date: 03/16/2014
* File: ParticleSystem.cpp
**/
#include "ParticleSystem.h"
#include "ParticleComponent.h"
#include "Entity.h"
void ParticleSystem::Update(sf::Time dt)
{
for(unsigned int id : _EntitiesToUpdate) {
Entity* e = this->GetEntity(id);
ParticleComponent* pc = e->GetComponent<ParticleComponent>("particle");
for(std::size_t i = 0; i < pc->_particleInfo.size(); ++i) {
ParticleInfo& p = pc->_particleInfo[i];
p.life -= dt;
if(p.life <= sf::Time::Zero)
pc->resetParticle(i);
pc->_particles._vertices[i].position += p.velocity * dt.asSeconds();
float ratio = p.life.asSeconds() / pc->_lifeTime.asSeconds();
pc->_particles._vertices[i].color.a = static_cast<sf::Uint8>(ratio * 255);
}
}
}
bool ParticleSystem::ValidateEntity(unsigned int ID)
{
Entity* e = this->GetEntity(ID);
return e->HasComponent("Particle");
}