Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

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...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)