Fire

Let's continue with the particle function.
First, we have to think about how our particles should behave. One of the important things is to avoid easily spottable movement-patterns. Remember, the user should not 'see' how the effect is 'constructed'. Therefore, we will include random values in our movement functions.

The movement on the z-axis can be a slow, steady upward movement.
But different particles should have different speeds, this adds to the randomness and the blazing of our fire. To achieve this, we assign my_speed.z a positive value with a random component:

my_speed.z = 0.7 + random(0.4);

Since this value is only assigned at the particle initialisation, it remains constant for the lifetime of it's 'mother-particle'.

The movement of the particles on the other two axes is more complicated. We want to simulate a natural, flowing movement, so using Sinus and Cosinus functions is a good solution.
If we use a steadily increasing input value for the sin/cos functions (my_age screams for this job) the output values produce exactly what we want. (the sinus curve is nice, soft, wavy curve)
We just have to divide the output values down to a smaller value, to avoid rapid unnatural movements that result from too high speeds on the x and y axes.

But we need some randomness here too, otherwise our particles would allways change their directions together (they would always have the same x and y speeds) which would lead to an easily spottable movement pattern. 
The easiest solution is to store two random values for each particle in it's 'my_color.red' and 'my_color.green' particle-skills, these values are then used as an offset in the sinus and cosinus functions respectively. (we can freely use the my_color skills, since our particles have a bitmap graphic and their real color is not visible anyway):

my_color.red = random(150);
my_color.green = random(150);

We can also incorporate some randomness into the particle size assignment:

my_size = 700 + random(300);

We also set the 'my_flare' and 'my_bright' flags to ON, since we want our particles to use the alpha map and to be 'glowing'. We use my_flare instead of my_transparent, because my_transparent can sometimes cause the alpha channel to remain unused on some video cards (riva tnt2 for example - this leads to blocky quadratic particles that ruin the effect). This problem only occurs randomly, but we can totally rule it out by using my_flare instead of my_transparent.

The particles are killed at an age of 30:

if (my_age > 30) {
        MY_ACTION = NULL;
}

next page >>