The ball needs to move in a continuous motion without gravity affecting it. We'll have to take into account the side walls and top and bottom walls. The velocity in the x and y direction have to reflect the other way when a collision happens on any of the boundaries. We need to set coordinates that the ball is only allowed to move through and an alert when it passes through an area below the paddle region.
Create a new function called
function updateBall()
below theremoveBrick(event)
function.function updateBall()
Add in the ball movement:
ball.x = ball.x + vx ball.y = ball.y + vy
Add in the ball movement for the x-direction:
if ball.x < 0 or ball.x + ball.width > display.contentWidth then vx = -vx end
Add in the ball movement for the y-direction:
if ball.y < 0 then vy = -vy end
Add in the ball movement when it collides with the bottom of the Gameplay screen. Create the lose Alert screen and a game event for
"lose"
. Close the function...