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 panda character


We need to set up the panda collision event and animate it accordingly, using the image sheet:

  1. We need to create a local function that will introduce the collision and touch events for the panda. We shall call it createPanda():

    local createPanda = function()
  2. When the panda collides with the stars, use onPandaCollision() with the parameters self and event. Reload panda every time a collision occurs with the stars or the edge of the screen, by using callNewRound():

      local onPandaCollision = function( self, event )
        if event.phase == "began" then
    
          if panda.isHit == false then
    
            panda.isHit = true
    
            if event.other.myName == "star" then
              callNewRound( true, "yes" )
            else
              callNewRound( true, "no" )
            end
    
            if event.other.myName == "wall" then
              callNewRound( true, "yes" )
            else
              callNewRound( true, "no" )
            end
    
            elseif panda.isHit then
              return...