Time for action — creating the clouds

The clouds will come in different sizes and shapes. The shapes are chosen randomly from the sprite sheet by the method of creation, as follows:

  1. Insert the method CreateClouds into the game class.
    Method CreateClouds:Int()
    
  2. As we will be creating several clouds, create a local object variable.
    Local obj:ftObject
    
  3. To calculate the shape, add a local shape variable of the type FLOAT.
    Local shape:Float
    
  4. Set the cloud layer as the default layer; all new objects, from now on, will be assigned to it.
    eng.SetDefaultLayer(layerClouds)
    
  5. We want ten clouds. Start a FOR loop ranging from 1 to 10.
    For Local i:Int = 1 To 10
    
  6. To determine the cloud shape, we need a random number ranging from 0 to 100.
    shape = Rnd(100.0)
    
  7. Check if shape is less or equal to 20. If yes, then load one cloud shape from the sprite atlas. Place it randomly on the canvas.
    If shape <= 20.0 Then
    obj = eng.CreateImage(atlas,128,0,64,64,Rnd(10,cw-10),Rnd(10,ch-10))
    
  8. If shape is greater than 20 and less than or equal to 70, then load the second cloud shape.
    Elseif shape > 20.0 And shape <= 70.0 Then
    obj = eng.CreateImage(atlas,192,0,64,64,Rnd(10,cw-10),Rnd(10,ch-10))
    
  9. And, if shape is greater than 70, load the last cloud sprite shape.
    Else
    obj = eng.CreateImage(atlas,0,64,128,128,Rnd(10,cw-10),Rnd(10,ch-10))
    Endif
    
  10. Set the speed and direction of the cloud randomly, and also its angle.
    obj.SetSpeed(Rnd(0.2,2),Rnd(360))
    obj.SetAngle(Rnd(360))
    
  11. Let the cloud object wrap around the screen edges when it moves outside the canvas borders.
    obj.SetWrapScreen(True)
    
  12. Close the FOR loop and this method.
    Next
    Return 0
    End
    

What just happened?

The CreateClouds method will add 10 clouds on the canvas in a random fashion. It will determine the shape to use randomly.

To make this method more general, you could add a parameter to the method head, which determines the amount of clouds to be created. But for now, we will go by this fixed amount we have chosen.

What is going on?—creating info text objects

Air Dogs 1942 will have support from four text objects which will inform the player about the current state and score of the game.

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

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