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 – counting the lives


Tracking the lives left in the game keeps the player updated on how much sooner it will be till the game is over. To count the remaining lives in the game, perform the following steps:

  1. Set up the function called livesCount():

        local livesCount = function()
  2. Display the text for lives every time the number is decremented:

          gameLives = gameLives - 1
          livesText.text = "Lives: " .. gameLives
          livesText.xScale = 0.5; livesText.yScale = 0.5  --> for clear retina display text
          livesText.x = (480 - (livesText.contentWidth * 0.5)) - 15
          livesText.y = 15
          print(gameLives .. " eggs left")
          if gameLives < 1 then
            callGameOver()
          end
        end

What just happened?

The livesCount() function is a separate function that updates gameLives. It makes sure that you're aware that gameLives = gameLives – 1. This decreases the set value instantiated in the beginning of the code. When gameLives changes values, it displays the update...