Time for action — spawning the player plane

We need a method that will make the player plane appear. The plane should appear on the left side of the screen, facing upwards. Like the clouds, the plane will wrap around the screen once it moves over the screen edges.

  1. Add a new method called SpawnPlayer to the class game.
    Method SpawnPlayer:Int ()
    
  2. Store the reference to the player plane object inside its corresponding field.
    player = eng.CreateImage(atlas,0,0,64,64,cw/4,ch/2)
    
  3. Scale it down to a factor of 0.7 and set the speed of the plane to 8.
    player.SetScale(0.7)
    player.SetSpeed(8)
    
  4. The player should wrap around the screen.
    player.SetWrapScreen(True)
    
  5. For collision detection, set the collision group to grpPlayer and the radius to 24 pixels. As the plane is already scaled down, the actual radius will be stored as 24 times 0.7.
    player.SetColGroup(grpPlayer)
    player.SetRadius(24)
    
  6. Reset the hit points to 0. Then, close the method.
    hits=0
    Return 0
    End
    

What just happened?

Using the SpawnPlayer method, you can always create a new player machine with a single call. Of course, only call it when the plane was previously destroyed, or you will end up with more than one plane, of which you can only control the newer one.

Spawning an enemy

As the hero needs an enemy to fight against, we need to spawn at least one enemy plane.

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

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