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 — acting on object update events

  1. Inside the method we will check if the ball reaches the edges of the game field and change its speed values according to the accelerometer values. The OnObjectUpdate method gives you the object as a parameter.
    Method OnObjectUpdate:Int(obj:ftObject)
    
  2. Perform a SELECT operation on the obj variable:
    Select obj
    
  3. If the object is equal to the object in g.ball, it is our ball:
    Case g.ball
    
  4. Now, check whether the ball reaches the top or bottom edge and whether its y speed value indicates that it is moving towards the corresponding edge:
    If (obj.yPos < obj.GetHeight()/2 And obj.GetSpeedY() < 0) Or (obj.yPos > (g.ch - obj.GetHeight()/2) And obj.GetSpeedY() > 0) Then
    
  5. Reverse the Y speed factor so it will bounce ...

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