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 — creating the explosion

The method to emit explosion particles works in a similar way to the one that emits smoke.

  1. Insert a method called SpawnExplosion in the game class. The parameters are the x and y positions, and the amount of particles to create.
    Method SpawnExplosion:Int(x:Float, y:Float, amount:Int)
    
  2. Set the default layer to the game layer.
    eng.SetDefaultLayer(layerGame)
    
  3. Start a FOR loop for the local i variable ranging from 1 to the amount parameter of the method.
    For Local i:Int = 1 To amount
    
  4. Determine a random x offset that is used when an image object for the explosion particle is created.
    Local xoff:Float = Int(Rnd(0,3))
    
  5. Create a local object for the particle image. It will be placed at the coordinates given to the method. ...

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