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 – removing the bricks


When the ball collides with a brick, we will use the same technique applied to the paddle to determine the path the ball will follow. When a brick is hit, we'll need to figure out which brick has been touched and then remove it from both the stage and the bricks group. Each brick removal will increment 100 points to the score. The score will be taken from the score constant and added to the current score as text. To remove the bricks from the game, follow these steps:

  1. Below the gameLevel2() function, create a function called removeBrick(event):

    function removeBrick(event)
  2. Check which side of the brick the ball hits by using the if statement. When checking for an event, we'll refer the event to the object name, "brick". This is the name we gave our brick display object:

      if event.other.name == "brick" and ball.x + ball.width * 0.5 < event.other.x + event.other.width * 0.5 then
        vx = -vx 
      elseif event.other.name == "brick" and ball.x + ball.width...