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 — spawning an explosion

  1. Add the method SpawnExplosion to the engine class. The parameters are the number of particles and their position.
    Method SpawnExplosion:Int(amount:Int, xp:Int, yp:Int)
    
  2. Set the default layer to g.layerGFX.
    SetDefaultLayer(g.layerGFX)
    
  3. Start a FOR loop as a counter ranging from 1 to amount.
    For Local i:Int = 1 To amount
    
  4. Create a new particle object.
    Local explo:ftObject = CreateImage(g.atlas, 128, 0,32,32, xp, yp)
    
  5. Set its scale, angle, spin, and speed randomly.
    explo.SetScale(Rnd(2,12)/10)
    explo.SetAngle(Rnd(0,359))
    explo.SetSpin(Rnd(-4,4))
    explo.SetSpeed(Rnd(1,2))
    
  6. Play the explosion sound.
    g.sndExplo.Play()
    
  7. Create an object timer, so that the particles will be removed after a random time. The timer ID is g.tmObjRemove ...

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