-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_particle.h
The idea is that future versions of libdarnit will allow for triangles etc. as particles. For now, only dots and textured quads are supported.
typedef enum {
DARNIT_PARTICLE_TYPE_POINT,
DARNIT_PARTICLE_TYPE_TEXTURED,
} DARNIT_PARTICLE_TYPE;TEXTURED is a tile from a tilesheet, that is affected by set color transition. To use textured particles, you need to call d_particle_tilesheet.
The particle engine supports multiple spawning modes.
typedef enum {
DARNIT_PARTICLE_MODE_OFF,
DARNIT_PARTICLE_MODE_SHOWER,
DARNIT_PARTICLE_MODE_PULSAR,
DARNIT_PARTICLE_MODE_AUTOPULSAR
} DARNIT_PARTICLE_MODE;- DARNIT_PARTICLE_MODE_OFF - No particles will spawn. default.
- DARNIT_PARTICLE_MODE_SHOWER - Particles will spawn in a constant stream
- DARNIT_PARTICLE_MODE_PULSAR - Particles will pulse out when a pulse is triggered by d_particle_pulse.
- DARNIT_PARTICLE_MODE_AUTOPULSAR - Particles will spawn in pulses at a constant rate
This is a particle emitter. Functions marked out with !!! Needs to be called with something before anything will render on screen. Functions marked (!!!) is needed for some particles types. For an example of how to use particle emitters, see particle test in libdarnit.
- DARNIT_PARTICLE *d_particle_new(int max_particles, DARNIT_PARTICLE_TYPE type); !!!
- void d_particle_draw(DARNIT_PARTICLE *p); !!!
- void d_particle_color_target(DARNIT_PARTICLE *p, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
- void d_particle_color_start(DARNIT_PARTICLE *p, unsigned char r, unsigned char g, unsigned char b, unsigned char a); !!!
- void d_particle_emitter_move(DARNIT_PARTICLE *p, int x, int y); !!
- void d_particle_emitter_angle(DARNIT_PARTICLE *p, int angle_min, int angle_max);
- void d_particle_emitter_velocity(DARNIT_PARTICLE *p, int velocity_min, int velocity_max); !!!
- void d_particle_emitter_gravity(DARNIT_PARTICLE *p, int gravity_xvel, int gravity_yvel);
- void d_particle_life(DARNIT_PARTICLE *p, int msec); !!!
- void d_particle_mode(DARNIT_PARTICLE *p, DARNIT_PARTICLE_MODE mode); !!!
- void d_particle_spawnrate(DARNIT_PARTICLE *p, int spawnrate);
- void d_particle_point_size(DARNIT_PARTICLE *p, int point_size);
- int d_particle_used(DARNIT_PARTICLE *p);
- void d_particle_tilesheet(DARNIT_PARTICLE *p, const char *fname, int tile_w, int tile_h, int tile); (!!!)
- void d_particle_pulse(DARNIT_PARTICLE *p);
- void d_particle_clear_all(DARNIT_PARTICLE *p);
- DARNIT_PARTICLE *d_particle_free(DARNIT_PARTICLE *p);
DARNIT_PARTICLE *d_particle_new(int max_particles, DARNIT_PARTICLE_TYPE type);
Creates a new particle emitter.
Arguments
- max_particles - The maximum amount of particles that can be visible at one time
- type - The type of the particles emitted
Return value
Returns NULL on failure. Everything else is a valid DARNIT_PARTICLE.
void d_particle_draw(DARNIT_PARTICLE *p);
Draws and emits particles. Should be called once per frame.
Arguments
- p - The particle emitter to draw
Return value None.
void d_particle_color_target(DARNIT_PARTICLE, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Sets the final color for a particle, which is reached right before it's deleted.
Arguments
- p - The particle emitter to set final color for
- r - The red color channel for final color (range: 0..255)
- g - The green color channel for final color (range: 0..255)
- b - The blue color channel for final color (range: 0..255)
- a - The alpha channel for final color (range: 0..255, 0 is completely transparent)
Return value None.
void d_particle_color_start(DARNIT_PARTICLE *p, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Sets the initial color for a particle, which is gets right when it's spawned
Arguments
- p - The particle emitter to set start color for
- r - The red color channel for start color (range: 0..255)
- g - The green color channel for start color (range: 0..255)
- b - The blue color channel for start color (range: 0..255)
- a - The alpha channel for start color (range: 0..255, 0 is completely transparent)
Return value None.
void d_particle_emitter_move(DARNIT_PARTICLE *p, int x, int y);
Moves a particle emitter, but does not affect any of the already spawned particles
Arguments
- p - The particle emitter to move
- x - The X-position to move the particle emitter to
- y - The Y-position to move the particle emitter to
Return value None.
void d_particle_emitter_angle(DARNIT_PARTICLE *p, int angle_min, int angle_max);
Sets the angle that the emitter can emit particles in. Default is 0 for min and 1 for max (which yields a thin line of particles.)
Arguments
- p - The particle emitter to set angle for
- angle_min - The minimum angle that a particle can be emitted at. Angle is in 1/10th of a degree
- angle_max - The maximum angle that a particle can be emitted at. Angle is in 1/10th of a degree
Return value None.
void d_particle_emitter_velocity(DARNIT_PARTICLE *p, int velocity_min, int velocity_max);
Sets the minimum and maximum velocity a particle can have when spawning. Default is minimum 0 and maximum 1.
Arguments
- p - The particle spawner to set spawning velocity for
- velocity_min - The minimum spawning velocity for a particle, in pixels/second
- velocity_max - The maximum spawning velocity for a particle, in pixels/second
Return value None.
void d_particle_emitter_gravity(DARNIT_PARTICLE *p, int gravity_xvel, int gravity_yvel);
Sets the acceleration on the particles emitted.
Arguments
- p - The particle emitter to apply gravity to
- gravity_xvel - The acceleration on particles, X-direction, unit is pixels/s²
- gravity_yvel - The acceleration on particles, Y-direction, unit is pixels/s²
Return value None.
void d_particle_life(DARNIT_PARTICLE *p, int msec);
Sets the life length of a particle, before it despawns.
Arguments
- p - The particle emitter to set particle life for
- msec - The particle life in milliseconds
Return value None.
void d_particle_mode(DARNIT_PARTICLE *p, DARNIT_PARTICLE_MODE mode);
Sets the emitter mode for the particle emitter.
Arguments
- p - The particle emitter to set emit mode for
- mode - The mode for the particle emitter
Return value None.
void d_particle_spawnrate(DARNIT_PARTICLE *p, int spawnrate);
Overrides the default spawnrate for particles when the emitter is in shower mode.
Arguments
- p - The particle emitter to override spawnrate for
- spawnrate - The spawnrate in particles/second. Set to -1 to use defaults. Default is max_particles/particle_life.
Return value None.
void d_particle_point_size(DARNIT_PARTICLE *p, int point_size);
When the particle emitter emits points, this sets the size of them.
Arguments
- p - The particle emitter to change point size for
- point_size - The point size to use in pixels
Return value None.
- int d_particle_used(DARNIT_PARTICLE *p);
Returns the number of active particles
Arguments
- p - The particle emitter to get usage for
Return value
The number of particles in use. For pulsars, this will be 0 when all particles have died down, and is ready for a new pulse.
void d_particle_tilesheet(DARNIT_PARTICLE *p, const char *fname, int tile_w, int tile_h, int tile);
Loads a tilesheet for the particle engine to use. Tile sizes will only be used if a tilesheet with fname isn't already loaded.
Arguments
- p - The particle emitter to load a tilesheet for
- fname - File name of the tilesheet
- tile_w - Tile width for the tilesheet
- tile_h - Tile height for the tilesheet
- tile - The tile number to use for the particle
Return value None.
void d_particle_pulse(DARNIT_PARTICLE *p);
Sends a pulse to a particle emitter. If the particle emitter is in non-auto emitting mode, it will pulse.
Arguments
- p - The particle emitter to pulse
Return value None.
void d_particle_clear_all(DARNIT_PARTICLE *p);
Tells a particle emitter to immediately clear all visible particle so that the particle emitter can be re-used without a "cool down".
Arguments
- p - The particle emitter to clear
Return value None.
DARNIT_PARTICLE *d_particle_free(DARNIT_PARTICLE *p);
Free's a particle emitter and immediatly destroys any spawned particles.
Arguments
- p - The particle emitter to free
Return value
Returns NULL for compact pointer clearing.