1
double right = xCenter + (PADDLE_WIDTH / 2);
double left = xCenter - (PADDLE_WIDTH / 2);

paddle.setLocation(   xCenter - (PADDLE_WIDTH / 2) , PADDLE_Y_OFFSET );
if (left == getWidth()|| right != getWidth()) {
    paddle.setLocation(xCenter - (PADDLE_WIDTH / 2) , PADDLE_Y_OFFSET );
}
ceyko
  • 4,822
  • 1
  • 18
  • 23
Awsome Man
  • 13
  • 1
  • 1
    What does getWidth() return? The canvas width? The if statement is superfluous, as it does exactely the same as the line before it. – Hyperboreus Dec 13 '12 at 06:36
  • 1
    What is `getWidth()`? Do you mean to check instead, something like `left < 0 || right > getWidth()` ? – ceyko Dec 13 '12 at 06:36

2 Answers2

0

You need something like this (pseudo code):

if left < leftBoundary then setLocation (leftBoundary)
if right > rightBounday then setLocation (rightBoundart - paddleWidth)

assuming than setLocation takes the left corner of the paddle for a parameter.

Hyperboreus
  • 31,997
  • 9
  • 47
  • 87
0

Explicitly test to see if any part of the paddle exceeds the boundary conditions. Rather than using 'if(left == getWidth() || right != getWidth())' use inequalities '>' or '<' to test if the position lies within the border.

blaffie
  • 505
  • 1
  • 10
  • 32