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 — setting up the player ship

  1. Add a new method called CreatePlayer to the game class.
    Method CreatePlayer:Int()
    
  2. Set the player object by calling CreateImage with our texture atlas. The positioning doesn't matter because we will do this later on.
    player = eng.CreateImage(atlas,0,0,32,32, 0,0)
    
  3. Now, set the friction and the maximum speed of the ship.
    player.SetFriction(0.2)
    player.SetMaxSpeed(20.0)
    
  4. To have the ship automatically wrap around the screen when it reaches its edges, set the wrapping to True via SetWrapScreen.
    player.SetWrapScreen(True)
    
  5. Reset the layer of the player object to layerGame.
    player.SetLayer(layerGame)
    
  6. The ship needs to be able to collide with comets, specifically. Set its collision group (grpPlayer) so that it can ...

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