The method we have created to spawn smoke will be called once a plane gets hit. The more hits it takes, the higher the chance of emitting a smoke particle.
1. Create a new method called
SpawnSmoke
inside thegame
class. The parameters are the plane object and the number of hits.Method SpawnSmoke:Int(plane:ftObject, hits:Int)
2. Check whether a random number ranging from
0
to100
will be greater than100-hits
times10
.If Rnd(0,100)>(100-hits*10) Then
3. If yes, set the default layer to
layerGame
.eng.SetDefaultLayer(layerGame)
4. Determine a vector that is located in the back of the plane. The distance is
20
pixels and the angle is calculated randomly taking the hits into account.Local vec:Float[] = plane.GetVector(20,180+Rnd(-10*hits,10*hits),True)
5. Randomly determine an
x
offset for the nextCreateImage
call from the sprite atlas. This is used to choose the smoke images randomly.Local xoff:Float = Int(Rnd(0,3))
6. Create a local image object that...