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

The OnObjectCollision method has two parameters. The first object is the one that actually checks against a collision with the second object. To identify an object, we will compare against its collision group field, collGroup.

  1. Add a local integer variable called i to the OnObjectCollision method.
    Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject)
    Local i:Int
    
  2. Now, check if the collGroup field of the second object is g.grpComet. As this is a constant from the game class, we need to add the prefix g. which stores it.
    If obj2.collGroup = g.grpComet Then
    
  3. Compare the tag field with the constant comet size g.cmLarge.
    If obj2.tag = g.cmLarge Then
    
  4. Spawn an explosion of 15 particles via g.SpawnExplosion ...

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