Smoke
Generating smoke is very simple if you have
completed the fire tutorial. We just need some little tweaking in order to
make our fire code suitable for smoke.
- Ofcourse, we
will be using a different bitmap.
- my_bright is not
needed, since smoke is not glowing or burning,
- emitting one particle
at each counter initialisation is enough for creating a
nice pillar of smoke.
- the particle size is a bit higher
- the movement speeds are a bit slower
- particle lifespan is longer
Here is the complete code for the smoke effect, try
using it in combination with a fire:
BMAP
smoke_map,<smoke.tga>;
// load smoke bitmap
action
particle1 {
while(1)
{ // emit
forever
my.skill13
-=
1; // decrease
counter
if
(my.skill13 <=
0) { // if counter reaches
0:
my.skill13 =
my.skill8 / TIME; // initialise
counter
my.skill10 = my.x
+ random(6) - 3; //
X-pos
my.skill11 = my.y
+ random(6) - 3; //
Y-pos
my.skill12 =
my.z; //
Z-pos
emit(1,my.skill10,test_particle1);
// create
particle
}
wait(1);
}
}
function test_particle1(){
if (my_age ==
0) {
// initialise particle
my_alpha
=
0;
my_speed.z
=
0.7+random(1);
//
set
z-speed
my_color.red
= random
(80);
// store random offset
for sin
my_color.green = random
(80);
// store random
offset for
cos
my_size =
1100+random(200); // set
size
my_map =
smoke_map;
// set
bitmap
my_flare =
on;
// transparent
END;
}
if (my_age > 80) {
MY_ACTION = NULL;
} // if
age reaches 80, kill particle
if
(my_age
> 17)
{ // if age >
17
my_alpha =
40-MY_AGE/2;
// fade-out
} else { my_alpha
= my_age
*
2;
} // else ... fade-in
my_speed.x = sin(my_age * 6 +
my_color.red) / 2.5;
// vary x-speed
my_speed.y = cos(my_age * 7 +
my_color.green) / 2; // vary
y-speed
}