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 – resetting and changing levels


We'll need to create functions that set up the first and second levels in the game. If a level needs to be replayed, only the current level the user lost in can be accessed. Follow these steps to transition between the levels:

  1. Create a new function called changeLevel1(). This will be placed below the updateBall() function:

    function changeLevel1()
  2. Clear the bricks group when the player loses the round, and then reset them:

      bricks:removeSelf()
    
      bricks.numChildren = 0
      bricks = display.newGroup()
  3. Remove alertDisplayGroup:

      alertBox:removeEventListener("tap", restart)
      alertDisplayGroup:removeSelf()
      alertDisplayGroup = nil
  4. Reset the ball and paddle positions:

      ball.x = (display.contentWidth * 0.5) - (ball.width * 0.5)
      ball.y = (paddle.y - paddle.height) - (ball.height * 0.5) -2
    
      paddle.x = display.contentWidth * 0.5
  5. Redraw the bricks for the current level:

    gameLevel1()
  6. Add an event listener to the background object for startGame(). Close the...