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:
Below the
gameLevel2()
function, create a function calledremoveBrick(event)
:function removeBrick(event)
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 ourbrick
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...