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 –making win and lose conditions


For any game alerts to even appear during game play, we need to create some if statements for every possible scenario available in each level. When this occurs, the score needs to be reset back to zero. To make the win and lose conditions, follow these steps:

  1. Below the alertScreen() function, create a new function called restart():

    function restart()
  2. Create an if statement for a "win" game event when the first level has been completed and transitions to level 2:

      if gameEvent == "win" and currentLevel == 1 then
        currentLevel = currentLevel + 1
        changeLevel2()
        levelNum.text = tostring(currentLevel)

    Note

    The tostring() method converts any argument to a string. In the preceding example, the currentLevel value changes from 1 to 2 when a "win" game event occurs. The value will convert to a string format that the levelNum text object can display on screen for level 2.

  3. Add an elseif statement for a "win" game event when the second level has been...