effect (function, var number, VECTOR* pos, VECTOR* vel)

effect_local (function, var number, VECTOR* pos, VECTOR* vel)

effect_layer (function, var number, VECTOR* pos, VECTOR* vel)

Creates a swarm of little moving bitmap particles, for rocket trails, explosions, laser beams, photon torpedos, rain, snowstorms, tornados or the like. The pos vector gives the starting position of the swarm, number gives the number of particles, vel gives either the initial speed or the beam length, and the function defines the behavior of each particle. The function is called permanently during the lifespan of each single particle and can change the position, speed, color, size, transparency, and bitmap of the particle, in a similar way as with normal entities. It can even create new 'children' particles. This gives the flexibility to use particle effects of every description.

   
     
Particle effect
Beam effect

Parameters:

function Particle function; runs every frame.
number Number of particles to create.
pos Position of the particle emitter.
vel Initial speed vector or beam length.

Remarks:

Speed:

Fast

Demo (lite-C):

// helper function: sets the vector to random direction and length
function vec_randomize (VECTOR* vec, var range)
{
   vec_set(vec,vector(random(1)-0.5,random(1)-0.5,random(1)-0.5));
   vec_normalize(vec,random(range));
}

// helper function: fades out a particle
function p_alphafade(PARTICLE *p)
{
    p.alpha -= p.skill_a*time_step;
    if (p.alpha <= 0) p.lifespan = 0;
}

function p_fountain(PARTICLE* p)
{
   VECTOR vTemp;
   vec_randomize(vTemp,2);
   vec_add(p.vel_x,vTemp);
   vec_set(p.blue,vector(random(255),random(255),255));
   set(p, MOVE | BRIGHT | TRANSLUCENT);
   p.alpha = 100;
   p.size = 2;
   p.gravity = 0.2;
   p.skill_a = 3; // fade factor
   p.event = p_alphafade;
}

function main()
{
  level_load(NULL);
  video_window(NULL,NULL,0,"Particle demo");
  vec_set(camera.x,vector(-150,0,50));
  vec_set(sky_color,vector(50,0,0)); // dark blue

  while(1)
  {
     effect(p_fountain,maxv(1,40*time_step),vector(0,0,0),vector(0,0,5));
     wait(1);
  }
}

See also:

lifespan, vel_x, gravity, size, alpha, bmap, event, skills, MOVE, BEAM, ent_decal, particles library

► latest version online