[5SD033]Blog 5 – Particle Generator

By: Martin Carlsson
Group: 10

One of the artifacts I have been working on this week is our particle generator. The reason we wanted a particle generator is mainly to improve the player feedback in the game.

First of, the particle generator serves as a indicator for the air level. When the air level is high, the particles are smaller. When the air level is low, the particles are much larger. The hope is that this will be enough of an indicator along with our hud elements and screen flash to make sure the player notices what is going on.

Bubbles.gif
The bubbles grow in size as the air meter goes down. I am not 100% happy with all the variables the generator produces. Such as some particles having a bit too long of a lifetime compared to others and the size of the bubbles when the air meter hits 0.

Secondly, the particles give the player feedback after defeating enemies and points out power ups. Such as the bubble trail from the bubble power up, or the blood effect from killing the swordfish. This gives the player a bit more feedback and enforces our more realistic theme, rather than only having a dead fish floating upside down.

Blood and bubble trail.gif
Seen in the gif is the bubble power up bubble trail and the blood trail from killing swordfish. The blood effect lacks a texture at the moment and I might redo it by using sf::Blendmode.  As I would like the effect to be persistent in the water, sort of staining the water instead.         (beware: gif does not show the colors of things correctly!)

The design of the particle system is very basic. It essentially includes an emitter, a generator and a std::vector of particles.

The emitter tells the generator to create new particles. The emitter has a max particle amount variable and will tell the generator to create new particles until the max has been met.

To create the particles, the generator takes: Size, position and color.

The speed, direction angle and lifetime of the particles are randomly determined by the generator. The particles themselves are objects of the class Particles. The class Particles is sf::Drawable and contains a sprite and the variables from the generator.

The particles get stored in a std::vector in the particle handler. The particle handler does what it’s named. It handles everything about the particles.It contains the emitter, the generator and it updates the particles. When a particle has completed its lifetime, it gets removed and another particle is available to be generated.

The game state then draws the particles and voila, we have particles.

The way this is implemented is certainly not optimized or advanced, but it serves the needs of our project.

Thank you for reading!

 

About Martin Carlsson

2015 Programming