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 – updating the ball


The ball needs to move in a continuous motion without gravity affecting it. We'll have to take into account the side walls and the 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 so that the ball is only allowed to move through and alert when it passes through the area below the paddle region. Let's perform the following steps:

  1. Create a new function called function updateBall() below the removeBrick(event) function:

    function updateBall()
  2. Add in the ball movement:

      ball.x = ball.x + vx
      ball.y = ball.y + vy
  3. Add in the ball movement for the x direction:

      if ball.x < 0 or ball.x + ball.width > display.contentWidth then
        vx = -vx
      end

    The following screenshot shows the movement of ball in the x direction:

  4. Add in the ball movement for the y direction:

      if ball.y < 0 then 
        vy = -vy 
      end

    The following screenshot shows the movement...

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)