Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Game #3, CometCrusher > Time for action — creating some explosions

Time for action — creating some explosions

Time for action — creating some explosions To spawn an explosion, create an method called SpawnExplosion. The parameters will be the particle amount, and the center position of the explosion. Method SpawnExplosion:Int(c:Int, xp:Float, yp:Float) Add a FOR loop from 1 to the amount of particles. For Local i:Int = 1 To c Create a local object of the particle from the sprite atlas. Local explo:ftObject = eng.CreateImage(atlas, 0,112,16,16, xp, yp) Scale and rotate it randomly. explo.SetScale(Rnd(3,15)/10) explo.SetAngle(Rnd(0,359)) Add a random spin and speed. explo.SetSpin(Rnd(-4,4)) explo.SetSpeed(Rnd(1,2)) Reset the layer to layerFX and create an object timer with the ID tmObjRemove to remove the particle after a random time between 100 to 2000 milliseconds. explo.SetLayer(layerFX) eng.CreateObjTimer(explo, tmObjRemove, Rnd(100,2000)) Close the FOR loop and play the sndExplo sound. Next sndExplo.Play() Close the method. Return 0 End What just happened? Again, this method helps you to spawn some nice explosions. It also creates a timer that will ensure that each particle is removed after its lifetime. Give me that gun—spawning a shot This game is about blasting some rocks into pieces. And what is the best tool for it? The deadly cannon of our lovely spaceship. So we need to shoot something.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint