Chapter 8: Particle System

This code provides the struct and methods for creating a particle system. In graphics programming, a particle system is a technique used to simulate certain fuzzy phenomena, which are otherwise very hard to reproduce with conventional rendering techniques. Examples of such phenomena include fire, smoke, sparks, and rain.

We start by defining a Particle struct, which represents a single particle in our particle system. Each particle has properties like x and y for the position, x_vel and y_vel for velocity, life to determine how long it exists, size, color, and alpha (transparency).

We then implement methods new for creating a new Particle instance, update to change the state of the particle every frame (like position, life and alpha), and render to draw the particle on the screen. In the update function, there's a condition to respawn particles at the top of the screen if they reach the bottom.

Following this, we have different functions to spawn different types of particles - spawn_particles_sparks, spawn_particles_fires, and spawn_particles_rain. Each function takes in the position, the number of particles to spawn and modifies the particles based on the type.

Last updated