aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-01-06 15:57:35 -0500
committerClyne Sullivan <tullivan99@gmail.com>2017-01-06 15:57:35 -0500
commit81ffc208ba15e77c1771f798907ee7e2a6331b3d (patch)
tree6c7ad1011a7ea7d956a76c860d546317d4f418a3 /src
parenta77877d65dfa1ee74407d94e221f2c737fdf20dd (diff)
explosions (crashes)
Diffstat (limited to 'src')
-rw-r--r--src/particle.cpp31
-rw-r--r--src/player.cpp4
-rw-r--r--src/ui.cpp1
3 files changed, 31 insertions, 5 deletions
diff --git a/src/particle.cpp b/src/particle.cpp
index 3e140ae..52a5635 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -10,20 +10,20 @@ ParticleSystem::ParticleSystem(int count, bool m)
parts.reserve(count);
}
-void ParticleSystem::add(const vec2& pos, const ParticleType& type)
+void ParticleSystem::add(const vec2& pos, const ParticleType& type, const int& timeleft)
{
// TODO not enforce max
if (/*max &&*/ parts.size() + 1 >= parts.capacity())
return;
- parts.emplace_back(pos, type);
+ parts.emplace_back(pos, type, timeleft);
}
-void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f)
+void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f, const int& timeleft)
{
int togo = count;
while (togo-- > 0)
- parts.emplace_back(f(), type);
+ parts.emplace_back(f(), type, timeleft);
}
void ParticleSystem::render(void) const
@@ -113,6 +113,29 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
p.velocity.y -= 0.001f;
break;
case ParticleType::Confetti:
+ if (p.velocity.x > -0.01 && p.velocity.x < 0.01) {
+ p.velocity.x = randGet() % 12 / 30.0f - 0.2f;
+ } else {
+ p.velocity.x += (p.velocity.x > 0) ? -0.002f : 0.002f;
+ }
+ p.velocity.y = -0.15f;
+ break;
+ case ParticleType::SmallBlast:
+ if (p.velocity.x == 0) {
+ int degree = randGet() % 100;
+ p.velocity.x = cos(degree) / 4.0f;
+ p.velocity.y = sin(degree) / 4.0f;
+ } else {
+ p.velocity.x += (p.velocity.x > 0) ? -0.001f : 0.001f;
+ p.velocity.x += (p.velocity.y > 0) ? -0.001f : 0.001f;
+ if ((p.velocity.x > -0.01 && p.velocity.x < 0.01) &&
+ (p.velocity.y > -0.01 && p.velocity.y < 0.01)) {
+ p.timeLeft = 0;
+ if (p.timeLeft <= 0)
+ parts.erase(part);
+ }
+ }
+
break;
}
diff --git a/src/player.cpp b/src/player.cpp
index a88734a..0e75e05 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -4,6 +4,7 @@
#include <ui.hpp>
#include <gametime.hpp>
#include <world.hpp>
+#include <particle.hpp>
void PlayerSystem::create(void)
{
@@ -107,6 +108,9 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
} else if (kc == getControl(3)) {
if (game::canSprint)
speed = 2.0f;
+
+ game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::SmallBlast,
+ [&](){ return vec2(loc.x, loc.y); }, 1000);
} else if (kc == getControl(4)) {
speed = .5;
} else if (kc == getControl(5)) {
diff --git a/src/ui.cpp b/src/ui.cpp
index 6383cca..09a87bf 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1284,7 +1284,6 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
case SDLK_b:
if (debug)
posFlag ^= true;
-
break;
case SDLK_F12:
// Make the BYTE array, factor of 3 because it's RBG.