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 response

During this method, we will add hit points, let the planes explode, and add scores.

  1. Check whether the collision group of the first object is equal to g.grpShot.
    Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject)
    If obj.GetColGroup()=g.grpShot Then
    
  2. Play the sound effect of a plane being hit.
    g.sndHit.Play()
    
  3. Check if the second object is the player plane.
    If obj2 = g.player Then
    
  4. Add 1 to the player's hits field.
    g.hits += 1
    
  5. Check if it took five or more hits.
    If g.hits >= 5 Then
    
  6. Add 1 to the computer score field.
    g.scoreC += 1
    
  7. Play the explosion sound effect.
    g.sndExplo.Play()
    
  8. Spawn an explosion of 15 particles at the object's position.
    g.SpawnExplosion(obj.GetPosX(), obj.GetPosY(),15)
    
  9. Remove the ...

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