Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Game #3, CometCrusher > Time for action — detailing the OnObjectUpdate metho...

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 relative to its current angle with SetAngle.
    If KeyDown(KEY_RIGHT) 'turn right
    obj.SetAngle(15.0 * delta,True)
    Endif
    

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint