-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlimeSplash.cpp
More file actions
44 lines (39 loc) · 1.33 KB
/
Copy pathSlimeSplash.cpp
File metadata and controls
44 lines (39 loc) · 1.33 KB
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
40
41
42
43
44
#include "SlimeSplash.h"
void SlimeSplash::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.texture = NULL;
target.draw(particles, states);
}
SlimeSplash::SlimeSplash(unsigned int count, sf::Color color, float MaxSpeed, float MinSpeed,bool faceRight)
:particles(sf::Points, count),particlesInfo(count),MaxSpeed(MaxSpeed),MinSpeed(MinSpeed)
{
for (size_t i = 0; i < count; i++) {
float angle = rand()%60;
if (!faceRight) angle = 180 - angle;
angle *= 22.f / 7.f / 180.f;
float speed = (rand()%int(this->MaxSpeed-this->MinSpeed))+this->MinSpeed;
particlesInfo[i].velocity = sf::Vector2f(cos(angle) * speed, sin(angle) * speed);
particlesInfo[i].lifeTime = sf::microseconds(rand()%3000+2000);
}
}
SlimeSplash::~SlimeSplash()
{
}
void SlimeSplash::Update(const float deltaTime)
{
for (size_t i = 0; i < particlesInfo.size() ; i++) {
Particle p = particlesInfo[i];
p.lifeTime -= sf::seconds(deltaTime);
if (p.lifeTime <= sf::Time::Zero) p.lifeTime = sf::Time::Zero;
if (p.lifeTime <= sf::seconds(1.5f)) {
float ratio = p.lifeTime.asSeconds() / 1.5f;
particles[i].color.a = static_cast<sf::Uint8>(255*ratio);
}
particles[i].position += particlesInfo[i].velocity*deltaTime;
particles[i].position.y += 9.80665f * 3;
}
}
/*void SlimeSplash::Render(sf::RenderTarget* target)
{
target->draw(particles);
}*/