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

Inside the OnObjectCollision method, we will remove tiles, and the ball, and will spawn some particle effects:

  1. Check whether the collision group of obj2 is equal to grpEnemy. That means the ball collided with the enemy:
    Method OnObjectCollision:Int(obj1:ftObject, obj2:ftObject)
    If obj2.GetColGroup() = g.grpEnemy Then
    
  2. Remove obj1, the ball:
    obj1.Remove()
    
  3. Spawn a new particle emitter at the ball's position, with a time factor of 300 milliseconds and a kind flag of 1:
    g.SpawnEmitter(obj1.GetPosX(), obj1.GetPosY(), 300,1)
    
  4. Play the explosion sound effect:
    g.sndExplo.Play()
    
  5. Now, reduce the lifes variable of the game class:
    g.lifes -= 1
    
  6. And create a new ball:
    g.CreateBall()
    Endif
    

    This was the check against ...

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