Particle Effects

Since there is only about a week left on this project and we have a working game that is almost finished, we are just adding things for fun (and sometimes because they are useful). This week I have been writing the code for adding particle effects in the game. We will use these effects when our charging enemies are loading their charge, right before our whack-a-mole boss comes out of the ground, when Barney (the avatar) dies and more things like that.

I started by writing the code for the particles in the class Particle. They consist of a sprite (a picture), a lifetime timer, a speed and a star position. When it is created it gets a random direction in which it will travel the whole time it exists. You can add some code making it move in another way, perhaps like an arc, but I think it looks quite well when it moves in just one direction, since its lifetime is pretty short. After the lifetime timer is up the particles sprite starts to fade until it is totally transparent.

running

To manage these particles I created a ParticleManager class which consists of a vector containing Particle pointers and three functions that adds, update and draw the particles. When adding particles you decide which kind of particle you want to create, this decides which sprite to use for the specific particle. Then you also decide how many of that kind you want to add and where you want it to spawn. Then the manager adds the particles to the vector and loops through the vector in every update to update the positions and timers for all of them, and draw them to the screen.

When creating lots of these at once it could look like a dust cloud coming from the ground, but in my example pictures I have used a placeholder-sprite of a muffin. For example we will add these when our kiting-boss dies and his ball of manure and grass will sort of explode into pieces.

The rest of the week I will be adding these particles where they are supposed to be, which means I have to add the manager to all the enemies, bosses and the avatar. I have to adjust the amount of particles that are created each time so it won’t take over the screen and steal the attention from the other things going on and so they won’t be unnoticed.

too_much    too_few


Leave a comment