Basics

that brings us to the particle function:
So ... how and when do we tell the particle how it should look?
The 'when' part of the question is easily answered, we have to assign the desired look to the particle right at it's birth. 
Since all the particles have an own attribute named my_age which shows the current age of the particle, it's easy to initialise the particle right at it's birth. 
We just have to check if it's age is 0. ( if (my_age == 0) { )

In this initialisation routine, we can also assign a movement to the particle, by defining it's speed on the three axes respectively. (x/y/z). We can assign the speed values by using the  'my_speed.x', 'my_speed.y' and 'my_speed.z' particle-attributes. We will assign random values here for our first test.

The next step is to assign a bitmap to the particle. 
We define a bitmap named blue_map (that contains the image blue1.tga ) and then assign in to the particles in our particle function. Blue1.tga is a blue star with a transparency channel and lies in the 'tutorial_templates directory.
We also set the size of the particles (300 in this case) in their my_size attribute.

All these assignments happen only once (in our 'initialisation routine'), so the values remain constant for the whole lifetime of the particle.

The next thing we have to think about is the lifespan of the particles. Since the emitter action creates an endless flow of particles, we have to kill the particles when they reach a certain age in order to avoid an overpopulation of particles in our level. So we just have to check the my_age attribute every frame and kill the particle by assigning NULL to it's function if it reaches a certain age.
Here is the code for the particle function:

BMAP blue_map,<blue1.tga>;       // loads blue1.tga into the blue_map object
function test_particle1() {
  if (my_age == 0) {                       // if particle is just born...
    my_speed.x = random(1) - 0.5;  // set speed.x 
    my_speed.y = random(1) - 0.5;  // set speed.y
    my_speed.z = random(1) - 0.5;  // set speed.z
    my_size = 300;                        // set size
    my_map = blue_map;               // assign bitmap
    my_flare = ON;                         // set to transparent
    END;
  }
  if (my_age > 39) {                      // delete particle at an age of 40
    MY_ACTION = NULL;
  }
}
You can find this code in the 'tutorial_templates' directory. It's named 'tut1.wdl'. The corresponding WMP file is also in the directory, just open it, build the level and start it to see our first particle effect in action.

next page >>