goku
goku game engine_en
goku game engine_en
  • Chapter 1: Introduction to SDL2, Rust, and goku
  • Chapter2: The Base Structure: SpriteSheet
  • Chapter 3: Animated Textures
  • Chapter 4: Handling Textures: TextureManager
  • Chapter 5: Bringing Textures to Life: GameObject
  • Chapter 6: The Foundation: Tile System
  • Chapter 7: Moving the View: Camera
  • Chapter 8: Particle System
  • Chapter 9: The User Interface Layer
  • Chapter 10: The Button Element
  • Chapter 11: The Text Box Element
  • Chapter 12: The Checkbox Element
  • Chapter 13: The Slider Element
  • Chapter 14: The Audio System
  • Chapter 15: The AI System
  • Chapter 16: The Window System
  • Chapter 17: User Input Handling
  • Chapter 18: Rendering a Parallax Background
  • Chapter 19: Timing and Frame Rate Management
  • Chapter 20: Conclusion
Powered by GitBook
On this page

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.

PreviousChapter 7: Moving the View: CameraNextChapter 9: The User Interface Layer

Last updated 1 year ago