Class Bouncer
- java.lang.Object
-
- Bouncer
-
public class Bouncer extends java.lang.Object
Handle the math calculations needed to determine if the ball hits a paddle or a wall.
-
-
Constructor Summary
Constructors Constructor Description Bouncer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getPaddleSideHit(PongPaddle paddle, PongBall ball)
Check if the ball has hit the paddle.static int
getWallHit(double left, double right, double top, double bottom, PongBall ball)
Determine which wall, if any, the ball has hit.
-
-
-
Field Detail
-
NONE
public static final int NONE
- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
- See Also:
- Constant Field Values
-
TOP
public static final int TOP
- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOM
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPaddleSideHit
public static int getPaddleSideHit(PongPaddle paddle, PongBall ball)
Check if the ball has hit the paddle. If so, return which side of the paddle has been hit. Also shifts the ball's position to the point of impact.- Parameters:
paddle
- the paddle to be checkedball
- the ball- Returns:
- one of Bouncer.LEFT, Bouncer.RIGHT, Bouncer.TOP, Bouncer.BOTTOM indicating which side of the paddle has been hit, or Bouncer.NONE if the paddle has not been hit
-
getWallHit
public static int getWallHit(double left, double right, double top, double bottom, PongBall ball)
Determine which wall, if any, the ball has hit. Also shifts the ball's position to the point of impact. Note that "top" and "bottom" refer to the relative position on the screen - because lower y coordinates are higher up on the screen, the top wall will have a smaller y coordinate than the bottom wall.- Parameters:
left
- x coordinate of the left wall (left < right)right
- x coordinate of the right wall (left < right)top
- y coordinate of the top wall (top < bottom)bottom
- y coordinate of the bottom wall (top < bottom)ball
- the ball- Returns:
- one of Bouncer.LEFT, Bouncer.RIGHT, Bouncer.TOP, Bouncer.BOTTOM indicating which wall has been hit, or Bouncer.NONE if no wall has been hit
-
-