aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/components.hpp3
-rw-r--r--include/particle.hpp7
-rw-r--r--src/particle.cpp49
-rw-r--r--src/player.cpp1
-rw-r--r--src/world.cpp7
-rw-r--r--xml/!town.xml2
6 files changed, 43 insertions, 26 deletions
diff --git a/include/components.hpp b/include/components.hpp
index 1deaf69..8e245a7 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -44,10 +44,11 @@ struct Direction {
* @param x The velocity of the object on the x axis.
* @param y The velocity of the object on the y axis.
*/
- Direction(float x = 0.0f, float y = 0.0f): x(x), y(y) {}
+ Direction(float x = 0.0f, float y = 0.0f): x(x), y(y), grounded(false) {}
float x; /**< Velocity the object is moving in the x direction, this is added to the position */
float y; /**< Velocity the object is moving in the y direction, this is added to the position */
+ bool grounded;
};
/**
diff --git a/include/particle.hpp b/include/particle.hpp
index 3fcd409..92ab7e4 100644
--- a/include/particle.hpp
+++ b/include/particle.hpp
@@ -11,7 +11,8 @@
enum class ParticleType : char {
Drop,
Confetti,
- SmallBlast
+ SmallBlast,
+ SmallPoof
};
struct Particle {
@@ -28,10 +29,10 @@ struct Particle {
class ParticleSystem : public entityx::System<ParticleSystem> {
private:
std::vector<Particle> parts;
- bool max;
+ unsigned int maximum;
public:
- ParticleSystem(int count = 2048, bool m = false);
+ ParticleSystem(unsigned int max = 2048);
void add(const vec2& pos, const ParticleType& type, const int& timeleft = 3000,
const unsigned char& color = 0);
diff --git a/src/particle.cpp b/src/particle.cpp
index b0b98ae..3a286c4 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -4,19 +4,17 @@
#include <render.hpp>
#include <world.hpp>
-ParticleSystem::ParticleSystem(int count, bool m)
- : max(m)
+ParticleSystem::ParticleSystem(unsigned int max)
+ : maximum(max)
{
- parts.reserve(count);
+ parts.reserve(maximum);
}
-void ParticleSystem::add(const vec2& pos, const ParticleType& type, const int& timeleft, const unsigned char& color)
+void ParticleSystem::add(const vec2& pos, const ParticleType& type, const int& timeleft,
+ const unsigned char& color)
{
- // TODO not enforce max
- if (/*max &&*/ parts.size() + 1 >= parts.capacity())
- return;
-
- parts.emplace_back(pos, type, timeleft, vec2(color / 8 * 0.25f, color % 8 * 0.125f + 0.0625f));
+ if (parts.size() < maximum)
+ parts.emplace_back(pos, type, timeleft, vec2(color / 8 * 0.25f, color % 8 * 0.125f + 0.0625f));
}
void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f,
@@ -24,22 +22,21 @@ void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std
{
int togo = count;
while (togo-- > 0)
- parts.emplace_back(f(), type, timeleft, vec2(color / 8 * 0.25f, color % 8 * 0.125f + 0.0625f));
+ add(f(), type, timeleft, color);
}
void ParticleSystem::render(void)
{
static GLuint particleVBO = 9999;
+ static const Texture palette ("assets/colorIndex.png");
// six vertices, 3d coord + 2d tex coord = 5
constexpr auto entrySize = (6 * 5) * sizeof(GLfloat);
- static const Texture palette ("assets/colorIndex.png");
if (particleVBO == 9999) {
// generate VBO
glGenBuffers(1, &particleVBO);
glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
- glBufferData(GL_ARRAY_BUFFER, parts.capacity() * entrySize, nullptr,
- GL_STREAM_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, maximum * entrySize, nullptr, GL_STREAM_DRAW);
}
// clear dead particles
@@ -51,7 +48,7 @@ void ParticleSystem::render(void)
int offset = 0;
for (const auto& p : parts) {
- static const auto hl = game::HLINE;
+ static const auto& hl = game::HLINE;
GLfloat coords[30] = {
p.location.x, p.location.y, -1, p.color.x, p.color.y,
p.location.x, p.location.y + hl, -1, p.color.x, p.color.y,
@@ -70,7 +67,6 @@ void ParticleSystem::render(void)
Render::worldShader.enable();
// set coords
- glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE,
5 * sizeof(GLfloat), 0);
// set tex coords
@@ -78,12 +74,11 @@ void ParticleSystem::render(void)
5 * sizeof(GLfloat), reinterpret_cast<void*>(3 * sizeof(GLfloat)));
palette.use();
- //if(glGetError() != GL_NO_ERROR)abort();
glDrawArrays(GL_TRIANGLES, 0, parts.size() * 6);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
Render::worldShader.disable();
Render::worldShader.unuse();
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -113,6 +108,7 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
p.velocity.x += (p.velocity.x > 0) ? -0.002f : 0.002f;
}
p.velocity.y = -0.15f;
+ p.timeLeft = 1000;
break;
case ParticleType::SmallBlast:
if (p.velocity.x == 0) {
@@ -121,7 +117,7 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
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;
+ p.velocity.y += (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;
@@ -129,6 +125,15 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
}
break;
+ case ParticleType::SmallPoof:
+ if (p.velocity.x == 0) {
+ p.velocity.y = 0.1f;
+ p.velocity.x = randGet() % 12 / 30.0f - 0.2f;
+ } else {
+ p.velocity.x += (p.velocity.x > 0) ? -0.001f : 0.001f;
+ p.velocity.y -= 0.0015f;
+ }
+ break;
}
// really update movement
@@ -137,8 +142,12 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
// world collision
auto height = worldSystem.isAboveGround(p.location);
- if (height != 0)
- p.location.y = height + 5, p.velocity.y = randGet() % 10 / 40.0f;
+ if (height != 0) {
+ if (p.type == ParticleType::Drop || p.type == ParticleType::SmallPoof)
+ p.location.y = height + 5, p.velocity.y = randGet() % 10 / 40.0f;
+ else
+ p.timeLeft = 0;
+ }
}
}
diff --git a/src/player.cpp b/src/player.cpp
index bdfc9fc..62ff6fe 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -86,6 +86,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
if ((kc == SDLK_SPACE) && game::canJump && ((vel.y > -0.01) & (vel.y < 0.01))) {
loc.y += HLINES(2);
vel.y = .4;
+ vel.grounded = false;
} else if (!ui::dialogBoxExists || ui::dialogPassive) {
if (kc == getControl(0)) {
if (!ui::fadeIntensity)
diff --git a/src/world.cpp b/src/world.cpp
index f54af3e..b6149e8 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -22,6 +22,7 @@ using namespace std::literals::chrono_literals;
#include <components.hpp>
#include <player.hpp>
#include <weather.hpp>
+#include <particle.hpp>
// local library headers
#include <tinyxml2.h>
@@ -1156,7 +1157,11 @@ void WorldSystem::detect(entityx::TimeDelta dt)
} else {
loc.y = data[line].groundHeight - 0.001f * dt;
vel.y = 0;
- // TODO ground flag
+ if (!vel.grounded) {
+ vel.grounded = true;
+ game::engine.getSystem<ParticleSystem>()->addMultiple(20, ParticleType::SmallPoof,
+ [&](){ return vec2(loc.x + randGet() % static_cast<int>(dim.width * game::HLINE), loc.y);}, 500, 30);
+ }
}
}
diff --git a/xml/!town.xml b/xml/!town.xml
index c197d8d..0a28124 100644
--- a/xml/!town.xml
+++ b/xml/!town.xml
@@ -4,7 +4,7 @@
<World>
<style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
<generation width="320"/>
- <weather>Rainy</weather>
+ <weather>Snowy</weather>
<time>6000</time>
<link right="!town2.xml"/>
<spawnx>-300</spawnx>