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 — detailing the OnObjectUpdate method

The OnObjectUpdate method has one parameter, the object that is updated.

  1. Check if the object is equal to g.player.
    Method OnObjectUpdate:Int(obj:ftObject)
    If obj = g.player Then
    
  2. If the up arrow key is pressed, add 1.5 times the engine delta field value to the object (player) with the AddSpeed method. Also, spawn a player engine particle with g.SpawnPlayerEngine.
    If KeyDown(KEY_UP) 'Speed up
    obj.AddSpeed(1.5*delta)
    g.SpawnPlayerEngine()
    Endif
    
  3. Check if the left arrow key is pressed. Then set the angle, 15*delta degrees relative to its current angle with SetAngle.
    If KeyDown(KEY_LEFT) 'turn left
    obj.SetAngle(-15.0 * delta,True)
    Endif
    
  4. If the right arrow key is pressed, set the angle, +15*delta degrees ...

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