Time for action — spawning an enemy plane

Besides using a different image, which is placed and rotated differently, spawning the enemy plane works in a similar way to spawning the player plane.

  1. Add a new method called SpawnEnemy to the game class.
    Method SpawnEnemy:Int ()
    
  2. Assign the image of the plane to the corresponding enemy field.
    enemy = eng.CreateImage(atlas,64,0,64,64,cw/4*3,ch/2)
    
  3. Scale it down to a factor of 0.7.
    enemy.SetScale(0.7)
    
  4. Set its angle to 180 degrees and give it a speed of 8.
    enemy.SetAngle(180)
    enemy.SetSpeed(8)
    
  5. Let the enemy plane wrap around the screen edges.
    enemy.SetWrapScreen(True)
    
  6. For collision detection, set the collision group to grpEnemy and give it a radius of 24.
    enemy.SetColGroup(grpEnemy)
    enemy.SetRadius(24)
    
  7. Reset its hit points to 0 and close the method.
    hitsC=0
    canShoot=True
    Return 0
    End
    

What just happened?

Now, you have added a method to spawn an enemy plane that will appear on the right side of the canvas, facing downwards. Call it with care! Just kidding!

Starting a new game

Before we detail the update process of the game, we need one more helper method to start a new game.

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

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