Class PongBall

java.lang.Object
  |
  +--PongBall

public class PongBall
extends java.lang.Object

This class describes an object that is used to represent the ball in a game of pong. Each PongBall will have an x and y position. Each PongBall will also have a velocity in the x direction and a velocity in the y direction.


Constructor Summary
PongBall(int initX, int initY, int initXVel, int initYVel)
          Construct a new PongBall with the specified initial position and velocity.
 
Method Summary
 void bounceX()
          Reverse the X direction of this PongBall.
 void bounceY()
          Reverse the Y direction of this PongBall.
 int getX()
          Return the current X position of this PongBall.
 int getY()
          Return the current Y position of this PongBall.
 void move()
          Move this PongBall according to its current velocity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PongBall

public PongBall(int initX,
                int initY,
                int initXVel,
                int initYVel)
Construct a new PongBall with the specified initial position and velocity.

Parameters:
initX - the initial X position of the new PongBall.
initY - the initial Y position of the new PongBall.
initXVel - the initial velocity of the new PongBall in the X direction.
initYVel - the initial velocity of the new PongBall in the Y Direction.
Method Detail

bounceX

public void bounceX()
Reverse the X direction of this PongBall. This method is invoked by the Pong application each time this PongBall collides with a vertical obstruction such as a wall or paddle. The X direction can be reversed by changing the sign of the X velocity.


bounceY

public void bounceY()
Reverse the Y direction of this PongBall. This method is invoked by the Pong application each time this PongBall collides with a horizontal obstruction such as a wall or the top/bottom edge of paddle. The Y direction can be reversed by changing the sign of the Y velocity.


getX

public int getX()
Return the current X position of this PongBall.

Returns:
the X position of this PongBall.

getY

public int getY()
Return the current Y position of this PongBall.

Returns:
the Y position of this PongBall.

move

public void move()
Move this PongBall according to its current velocity. This method is invoked at a regular rate by the Pong application in order to update the position of the ball. The X position changes by the velocity in the X direction and the y position changes by the velocity in the Y direction.



Free Web Hosting