java.lang.Object
project.pong.model.Ball
The Ball class represents the ball in the Pong game.
-
Constructor Summary
ConstructorsConstructorDescriptionBall(int x, int y, double speed, double directionX, double directionY, double increaseSpeed) Constructs a Ball object with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidReverses the direction of movement along the x-axis.voidReverses the direction of movement along the y-axis.doubleGets the base speed of the ball.doubleGets the direction of movement along the x-axis.doubleGets the direction of movement along the y-axis.doubleGets the speed increase factor of the ball.doublegetSpeed()Gets the speed of the ball.doublegetWidth()Gets the width of the ball.doublegetX()Gets the x-coordinate of the ball.doublegetY()Gets the y-coordinate of the ball.voidIncreases the speed of the ball.voidmove()Moves the ball based on its current speed and direction.voidreset()Resets the speed of the ball to its base speed.voidresizeHeight(double factor) Resizes the height of the ball.voidresizeWidth(double factor) Resizes the width of the ball.voidrun()Runs the thread for the ball's movement.voidsetBaseSpeed(double baseSpeed) Sets the base speed of the ball.voidsetDirectionX(double directionX) Sets the direction of movement along the x-axis.voidsetDirectionY(double directionY) Sets the direction of movement along the y-axis.voidsetIncreaseSpeed(double increaseSpeed) Sets the speed increase factor of the ball.voidsetSpeed(double speed) Sets the speed of the ball.voidsetX(double x) Sets the x-coordinate of the ball.voidsetY(double y) Sets the y-coordinate of the ball.voidstop()Stops the ball movement thread.
-
Constructor Details
-
Ball
public Ball(int x, int y, double speed, double directionX, double directionY, double increaseSpeed) Constructs a Ball object with the specified parameters.- Parameters:
x- The x-coordinate of the ball's initial position.y- The y-coordinate of the ball's initial position.speed- The speed of the ball.directionX- The direction of movement along the x-axis.directionY- The direction of movement along the y-axis.increaseSpeed- The speed increase factor.
-
-
Method Details
-
getBaseSpeed
public double getBaseSpeed()Gets the base speed of the ball.- Returns:
- The base speed of the ball.
-
setBaseSpeed
public void setBaseSpeed(double baseSpeed) Sets the base speed of the ball.- Parameters:
baseSpeed- The base speed to set.
-
reset
public void reset()Resets the speed of the ball to its base speed. -
getX
public double getX()Gets the x-coordinate of the ball.- Returns:
- The x-coordinate of the ball.
-
setX
public void setX(double x) Sets the x-coordinate of the ball.- Parameters:
x- The x-coordinate to set.
-
getY
public double getY()Gets the y-coordinate of the ball.- Returns:
- The y-coordinate of the ball.
-
setY
public void setY(double y) Sets the y-coordinate of the ball.- Parameters:
y- The y-coordinate to set.
-
getSpeed
public double getSpeed()Gets the speed of the ball.- Returns:
- The speed of the ball.
-
setSpeed
public void setSpeed(double speed) Sets the speed of the ball.- Parameters:
speed- The speed to set.
-
getDirectionX
public double getDirectionX()Gets the direction of movement along the x-axis.- Returns:
- The direction of movement along the x-axis.
-
setDirectionX
public void setDirectionX(double directionX) Sets the direction of movement along the x-axis.- Parameters:
directionX- The direction to set.
-
getDirectionY
public double getDirectionY()Gets the direction of movement along the y-axis.- Returns:
- The direction of movement along the y-axis.
-
setDirectionY
public void setDirectionY(double directionY) Sets the direction of movement along the y-axis.- Parameters:
directionY- The direction to set.
-
move
public void move()Moves the ball based on its current speed and direction. -
changeDirectionX
public void changeDirectionX()Reverses the direction of movement along the x-axis. -
changeDirectionY
public void changeDirectionY()Reverses the direction of movement along the y-axis. -
getIncreaseSpeed
public double getIncreaseSpeed()Gets the speed increase factor of the ball.- Returns:
- The speed increase factor of the ball.
-
setIncreaseSpeed
public void setIncreaseSpeed(double increaseSpeed) Sets the speed increase factor of the ball.- Parameters:
increaseSpeed- The speed increase factor to set.
-
increaseSpeed
public void increaseSpeed()Increases the speed of the ball. -
getWidth
public double getWidth()Gets the width of the ball.- Returns:
- The width of the ball.
-
resizeWidth
public void resizeWidth(double factor) Resizes the width of the ball.- Specified by:
resizeWidthin interfaceResizable- Parameters:
factor- The factor by which to resize the width.
-
resizeHeight
public void resizeHeight(double factor) Resizes the height of the ball.- Specified by:
resizeHeightin interfaceResizable- Parameters:
factor- The factor by which to resize the height.
-
run
public void run()Runs the thread for the ball's movement. -
stop
public void stop()Stops the ball movement thread.
-