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 – making the ball bounce against the paddle


We will check which side of the paddle the ball has hit to choose the side where it will move next. It's important to have the motion to follow through any directional hits as it would in a realistic environment. With every paddle collision, we want to make sure that the ball goes in the up direction. For this, follow these steps:

  1. Create a new function called bounce() for the ball after the movePaddle() function:

    function bounce()
  2. Add in a value of -3 for velocity in the y direction. This will make the ball move in an upward motion:

      vy = -3
  3. Check when a collision is made with the paddle and ball objects and close the function:

      if((ball.x + ball.width * 0.5) < paddle.x) then
        vx = -vx
      elseif((ball.x + ball.width * 0.5) >= paddle.x) then
        vx = vx
      end
    end

What just happened?

When the ball collides with the paddle, the motion follows through, depending on what side of the paddle is touched by the ball. In the first part...

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)