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 some comets

  1. As always, inside the game class, create a new method called CreateComets. Its parameter will be the amount of comets that have to be created.
    Method SpawnComets:Int (ccount:Int)
    
  2. Add a FOR loop from 1 to the amount of comets you want to create.
    For Local i:Int = 1 To ccount
    
  3. Call up the method CreateComet with the size set to large, and random values for position, angle, and speed.
    obj = CreateComet(cmLarge,Rnd(64,eng.canvasWidth-64),Rnd(64,eng.canvasHeight-64),Rnd(1,4)/2,Rnd(0,359))/
    
  4. Close the FOR loop, and the method.
    Next
    Return 0
    End
    

What just happened?

To actually spawn comets, you have created a method that will do this randomly over the canvas area. You just tell how many comets you need and it will spawn ...

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