COMP 160 Lab 6: Particle Systems

Particle systems are a technique to simulate "fuzzy" animations — fire, explosions, smoke, flowing water, clouds, snow, falling leaves, magic spells, etc. The same technique can be used for things like hair or grass, but this can be computationally expensive, and there's little use for such application in our 2D games.

The particle system will be controlled by an emitter. The emitter will generate particles originating from the emitter's location, and give them velocity, rotation, and lifetimes. In a 3D game, an emitter will commonly be an object in the world, and the particles will be generated normal, or perpendicular, to the face(s). This lab will use an small point emitter, in 2D space.

The parameters given to the particles by the emitter will typically be "fuzzy" — rather than specifying an exact value that the emitter gives each particle, the emitter will have a central value, and a range on each side that it can be. For example, the lifetime of each particle in a flame emitter might be 50 frames ±20%.

But what is a particle, exactly? Many 3D games use textured billboard quads. That's jargon for "a quadrilateral facing the player with an image on it". While 3D games use other methods as well, this is essentially what we will be doing. The sprites you have been drawing up until this point are not very different from a textured billboard quad: they're quadrilaterals (rectangles) that always face the player, with an image (texture) on them. (In truth, there are differences between textures drawn with our SpriteBatch and a billboard quad — but we can accomplish our particle system either way, so we will be using the SpriteBatch to make 2D particles, rather than pretending the 3D quads are 2D.)

For motivation, first run this 2D Particle Sample from App Hub. Note: The manner in which this is implemented is very different from your lab assignment. You are free to use it (or something similar) on your final project, but it will not be particularly useful for completing the lab.

Assignment

Implement three particle types: Fire, Water, and Smoke (activated by the B, X, and Y buttons, respectively). The provided code gives you a skeleton Emitter class, and draws a 4×4 red dot at the Emitter's location, to help you track it. The Emitter can be moved around the game with the left thumbstick, and the position can be reset with the A button.

Complete the provided code with these features.

Useful Tips