6 Module PARTICLES
gullradriel edited this page 2026-10-29 20:54:40 +01:00

GRAPHICS: 3D particles utilities

Structures

Name
struct PARTICLE_SYSTEM
Structure of a particle system.
struct PARTICLE_EMITTER
Structure of a particle emitter.
struct PARTICLE
Structure of a single particle.

Functions

Name
int remove_emitter(PARTICLE_SYSTEM * psys, const PARTICLE_EMITTER * em)
remove an emitter from the particle system and free it
int move_particles(PARTICLE_SYSTEM * psys, double vx, double vy, double vz)
move all particles by a velocity offset
int manage_particle_ex(PARTICLE_SYSTEM * psys, double delta_t)
manage particles with custom delta time
int manage_particle(PARTICLE_SYSTEM * psys)
manage particles using internal timer
int init_particle_system(PARTICLE_SYSTEM ** psys, int max, double x, double y, double z, int max_sprites)
initialize a particle system
int free_particle_system(PARTICLE_SYSTEM ** psys)
free a particle system
int free_emitters(PARTICLE_SYSTEM * psys)
free all emitters in the particle system
int draw_particle(PARTICLE_SYSTEM * psys, double xpos, double ypos, int w, int h, double range)
draw particles on screen
int add_particle_ex(PARTICLE_SYSTEM * psys, int spr, int mode, int off_x, int off_y, int lifetime, int size, ALLEGRO_COLOR color, double vx, double vy, double vz, double ax, double ay, double az)
add a particle to the system (extended version)
int add_particle_at(PARTICLE_SYSTEM * psys, int spr, int mode, double px, double py, double pz, int lifetime, int size_start, int size_end, ALLEGRO_COLOR color_start, ALLEGRO_COLOR color_end, double vx, double vy, double vz, double ax, double ay, double az)
add a particle at an absolute world position (not relative to psys->source)
int add_particle(PARTICLE_SYSTEM * psys, int spr, int mode, int lifetime, int size, ALLEGRO_COLOR color, PHYSICS object)
add a particle to the system
PARTICLE_EMITTER * add_emitter(PARTICLE_SYSTEM * psys)
add a new emitter to the particle system.

Defines

Name
TRANS_PART
transparent particle
TEXT_PART
bitmap particle
STAR_PART
star particle
SNOW_PART
snow particle
SINUS_PART
sinus based moving particle
PIXEL_PART
pixel particle
NORMAL_PART
classic moving particle
FIRE_PART
fire particle
CIRCLE_PART
circle particle
BITMAP_PART
bitmap particle

Functions Documentation

function remove_emitter

int remove_emitter(
    PARTICLE_SYSTEM * psys,
    const PARTICLE_EMITTER * em
)

remove an emitter from the particle system and free it

Parameters:

  • psys the targeted particle system
  • em the emitter to remove

Return: TRUE or FALSE

function move_particles

int move_particles(
    PARTICLE_SYSTEM * psys,
    double vx,
    double vy,
    double vz
)

move all particles by a velocity offset

Parameters:

  • psys the targeted particle system
  • vx x move
  • vy y move
  • vz z move

Return: TRUE or FALSE

move all particles of a particle system by a given offset

move all particles by a velocity offset

function manage_particle_ex

int manage_particle_ex(
    PARTICLE_SYSTEM * psys,
    double delta_t
)

manage particles with custom delta time

Parameters:

  • psys the targeted particle system
  • delta_t delta time to use, in microseconds

Return: TRUE or FALSE

update particles positions using provided delta time

manage particles with custom delta time

function manage_particle

int manage_particle(
    PARTICLE_SYSTEM * psys
)

manage particles using internal timer

Parameters:

  • psys the targeted particle system

Return: TRUE or FALSE

update particles positions using particle system internal timer

manage particles using internal timer

function init_particle_system

int init_particle_system(
    PARTICLE_SYSTEM ** psys,
    int max,
    double x,
    double y,
    double z,
    int max_sprites
)

initialize a particle system

Parameters:

  • psys a pointer to a NULL initialized PARTICLE_SYSTEM pointer
  • max maximum number of particles in the system. Set to zero or negative to disable the limitation
  • x x position of the emitter
  • y y position of the emitter
  • z z position of the emitter
  • max_sprites maximum number of sprites used in the system. Value from UNLIMITED_LIST_ITEMS (0) to MAX_LIST_ITEMS (SIZE_MAX).

Return: TRUE or FALSE

function free_particle_system

int free_particle_system(
    PARTICLE_SYSTEM ** psys
)

free a particle system

Parameters:

  • psys a pointer to the particle system to destroy

Return: TRUE or FALSE

destroy and free a particle system

free a particle system

function free_emitters

int free_emitters(
    PARTICLE_SYSTEM * psys
)

free all emitters in the particle system

Parameters:

  • psys the targeted particle system

Return: TRUE or FALSE

function draw_particle

int draw_particle(
    PARTICLE_SYSTEM * psys,
    double xpos,
    double ypos,
    int w,
    int h,
    double range
)

draw particles on screen

Parameters:

  • psys the targeted particle system
  • xpos camera x position
  • ypos camera y position
  • w width of the current display
  • h height of the current display
  • range display border tolerance, if( ( x < -range ) || ( x > ( w + range ) ) || ( y< -range ) || ( y > ( h + range ) ) ) next ;

Return: TRUE or FALSE

draw particles of a particle system

draw particles on screen

function add_particle_ex

int add_particle_ex(
    PARTICLE_SYSTEM * psys,
    int spr,
    int mode,
    int off_x,
    int off_y,
    int lifetime,
    int size,
    ALLEGRO_COLOR color,
    double vx,
    double vy,
    double vz,
    double ax,
    double ay,
    double az
)

add a particle to the system (extended version)

Parameters:

  • psys targeted particle system
  • spr sprite id of the particle, if any. Set to negative if there is no sprite for the particle
  • mode particle mode, NORMAL_PART:if sprite id then use sprite, else draw a pixel,SINUS_PART: snow moving effect,PIXEL_PART: rectfill with size
  • off_x x offset from particle source x position
  • off_y y offset from particle source y position
  • lifetime duration of the particle in msecs
  • size size of the particle, in pixels
  • color color of the particle
  • vx x speed of the particle
  • vy vy speed of the particle
  • vz z speed of the particle
  • ax x acceleration of the particle
  • ay y acceleration of the particle
  • az z acceleration of the particle

Return: TRUE or FALSE

add a particle to a particle system, all in line version (you have to set the PHYSICS object parameter in the function parameter instead of providing a PHYSICS object)

add a particle to the system (extended version)

function add_particle_at

int add_particle_at(
    PARTICLE_SYSTEM * psys,
    int spr,
    int mode,
    double px,
    double py,
    double pz,
    int lifetime,
    int size_start,
    int size_end,
    ALLEGRO_COLOR color_start,
    ALLEGRO_COLOR color_end,
    double vx,
    double vy,
    double vz,
    double ax,
    double ay,
    double az
)

add a particle at an absolute world position (not relative to psys->source)

Parameters:

  • psys targeted particle system
  • spr sprite id (-1 for none)
  • mode particle draw mode
  • px absolute x position
  • py absolute y position
  • pz absolute z position
  • lifetime duration in msecs
  • size_start particle size at birth
  • size_end particle size at death
  • color_start particle start color
  • color_end particle end color (lerped over lifetime)
  • vx x velocity
  • vy y velocity
  • vz z velocity
  • ax x acceleration
  • ay y acceleration
  • az z acceleration

Return: TRUE or FALSE

function add_particle

int add_particle(
    PARTICLE_SYSTEM * psys,
    int spr,
    int mode,
    int lifetime,
    int size,
    ALLEGRO_COLOR color,
    PHYSICS object
)

add a particle to the system

Parameters:

  • psys targeted particle system
  • spr sprite id of the particle, if any. Set to negative if there is no sprite for the particle
  • mode particle mode, NORMAL_PART:if sprite id then use sprite, else draw a pixel,SINUS_PART: snow moving effect,PIXEL_PART: rectfill with size
  • lifetime duration of the particle in msecs
  • size size of the particle, in pixels
  • color color of the particle
  • object PHYSICS object in which you set the particle initial position, speed, acceleration, rotation

Return: TRUE or FALSE

add a particle to a particle system

add a particle to the system

function add_emitter

PARTICLE_EMITTER * add_emitter(
    PARTICLE_SYSTEM * psys
)

add a new emitter to the particle system.

Parameters:

  • psys the targeted particle system

Return: pointer to the new emitter for caller to configure, or NULL on error

add a new emitter to the particle system

Returns pointer for caller to configure, or NULL on error.

add a new emitter to the particle system.

Macros Documentation

define TRANS_PART

#define TRANS_PART 2

transparent particle

define TEXT_PART

#define TEXT_PART 9

bitmap particle

define STAR_PART

#define STAR_PART 5

star particle

define SNOW_PART

#define SNOW_PART 3

snow particle

define SINUS_PART

#define SINUS_PART 1

sinus based moving particle

define PIXEL_PART

#define PIXEL_PART 7

pixel particle

define NORMAL_PART

#define NORMAL_PART 0

classic moving particle

define FIRE_PART

#define FIRE_PART 4

fire particle

define CIRCLE_PART

#define CIRCLE_PART 6

circle particle

define BITMAP_PART

#define BITMAP_PART 8

bitmap particle