O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — emitting the smoke

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 the game 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 to 100 will be greater than 100-hits times 10.
    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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required