Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – creating the egg collision


We have handled collisions in the previous sample games we created. Handling postcollisions requires the introduction of force to execute the completion of a postcollision event:

  1. Create a new local function called onEggCollision() with two parameters called self and event:

        local onEggCollision = function( self, event )
  2. Create an if statement when the force is greater than 1 and include not self.isHit. Add in the eggCaughtSound sound effect:

          if event.force > 1 and not self.isHit then
            audio.play( eggCaughtSound )
  3. Make self invisible and inactive, and replace it with the friedEgg display object:

            self.isHit = true
            print( "Egg destroyed!")
            self.isVisible = false
            friedEgg.x = self.x; friedEgg.y = self.y
            friedEgg.alpha = 0
            friedEgg.isVisible = true
  4. Create a function that transitions the friedEgg display object and fades it off the stage by using the onComplete command:

            local fadeEgg...