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 collision detection

During the collision callback method, we will set the collision markers and objects, so that we can act on them during the OnObjectUpdate method.

  1. Start with a Select statement on the first object's collision group.
    Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject)
    Select obj.GetColGroup()
    
  2. Check whether it is a wall.
    Case g.grpWall
    
  3. If the second object is in the player's second collision zone (128 pixels away), then set g.hitWall2 to True. We do this by checking the collision group of the second object.
    If obj2.GetColGroup()=g.grpPlayer2 Then g.hitWall2=True
    
  4. Now, check whether the second object is the first collision zone of the player (64 pixels away), and if yes, set g.hitWall to True.
    If obj2.GetColGroup()=g.grpPlayer ...

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