Time for action — create a comet

  1. To create a comet, we need a new method called CreateComet. The parameters are the kind of comet, its position, the travel speed, and angle.
    Method CreateComet:ftObject(k:Int, xp:Float, yp:Float, speed:Float, speedAngle:Float)
    
  2. Define a local ftObject called com.
    Local com:ftObject
    
  3. Depending on the size of the comet, create the comet object from different locations of the sprite atlas. Also, set the radius depending on the size.
    If k = cmSmall Then
    com = eng.CreateImage(atlas, 0,32,16,16, xp, yp)
    com.SetRadius(4)
    Endif
    If k = cmMiddle Then
    com = eng.CreateImage(atlas, 32,0,32,32, xp, yp)
    com.SetRadius(12)
    Endif
    If k = cmLarge Then
    com = eng.CreateImage(atlas, 64,0,64,64, xp, yp)
    com.SetRadius(24)
    Endif
    
  4. Now, set the speed and the angle that the comet will move at.
    com.SetSpeed(speed, speedAngle)
    
  5. Next, we set a random starting angle and spinning speed.
    com.SetAngle(Rnd(0,359))
    com.SetSpin(Rnd(-4,4))
    
  6. Store the comet size constant into the tag field.
    com.SetTag(k)
    
  7. Tell the engine that the comet will wrap the screen once it hits the canvas edge.
    com.SetWrapScreen(True)
    
  8. Now, set its collision group to grpComet and the layer to layerGame.
    com.SetColGroup(grpComet)
    com.SetLayer(layerGame)
    
  9. The last things you need to do before you close the method is to set the ID with the grpComet constant and raise cometCount by 1.
    com.SetID(grpComet)
    cometCount += 1
    Return com
    End
    

What just happened?

Using the CreateComet method, you can create a new comet in one call. With its various parameters, you can define the position, the type of comet, and where it will travel during its life time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.55.14