Package break_out.model
Class Ball
- java.lang.Object
-
- break_out.model.Ball
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Color
color
The balls color with default component colorprivate Vector2D
direction
The balls directionprivate boolean
hitsPaddle
The balls hit state for paddles; custom implementationprivate Stone
hitStone
The stone which has been hit by the ballprivate boolean
isLost
The balls lost state for upper and lower bordersprivate Position
position
The balls position on the playground
-
Constructor Summary
Constructors Constructor Description Ball()
The constructor of a ball The balls position and direction are initialized here.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Color
getColor()
The getter for the balls colorVector2D
getDirection()
The getter for the balls directionboolean
getHitState()
The getter for the balls hit stateStone
getHitStone()
returns the stone which got hit, can be nullPosition
getPosition()
The getter for the balls positionboolean
hitsPaddle(Paddle paddle)
tests whether the ball touches the paddle's hit box.boolean
hitsStone(java.util.ArrayList<Stone> stones)
tests whether the ball touches any stone's hit boxboolean
isLost()
The getter for balls lost statevoid
newRandomColor()
Creates new random color for the ball and sets itvoid
reactOnBorder()
Ball reacts to contact with the bordersvoid
reflectOnPaddle(Paddle paddle)
Ball got hit by Paddle paddlevoid
reflectOnStone(Stone stone)
Ball got hit by Stone stonevoid
resetDirection()
resets balls directionvoid
resetPosition()
resets balls positionvoid
setColor(java.awt.Color color)
The setter for the balls colorvoid
setHitState(boolean state)
The setter for the balls hit statevoid
setLost(boolean lost)
The setter for balls lost statevoid
updatePosition()
updates ball position
-
-
-
Field Detail
-
position
private Position position
The balls position on the playground
-
direction
private Vector2D direction
The balls direction
-
hitsPaddle
private boolean hitsPaddle
The balls hit state for paddles; custom implementation
-
isLost
private boolean isLost
The balls lost state for upper and lower borders
-
color
private java.awt.Color color
The balls color with default component color
-
hitStone
private Stone hitStone
The stone which has been hit by the ball
-
-
Method Detail
-
getPosition
public Position getPosition()
The getter for the balls position- Specified by:
getPosition
in interfaceIBall
- Returns:
- position The balls current position
-
getDirection
public Vector2D getDirection()
The getter for the balls direction- Specified by:
getDirection
in interfaceIBall
- Returns:
- direction The balls current direction
-
getColor
public java.awt.Color getColor()
The getter for the balls color- Returns:
- color The balls current color
-
setColor
public void setColor(java.awt.Color color)
The setter for the balls color- Parameters:
color
- The balls new color
-
newRandomColor
public void newRandomColor()
Creates new random color for the ball and sets it- See Also:
- Stackoverflow Answer 4247219
-
getHitState
public boolean getHitState()
The getter for the balls hit state- Returns:
- hitsPaddle The balls current hit state
-
setHitState
public void setHitState(boolean state)
The setter for the balls hit state- Parameters:
state
- The balls new hit state
-
updatePosition
public void updatePosition()
updates ball position- Specified by:
updatePosition
in interfaceIBall
-
reactOnBorder
public void reactOnBorder()
Ball reacts to contact with the borders- Specified by:
reactOnBorder
in interfaceIBall
-
hitsPaddle
public boolean hitsPaddle(Paddle paddle)
tests whether the ball touches the paddle's hit box.- Specified by:
hitsPaddle
in interfaceIBall
- Parameters:
paddle
- paddle which will be tested- Returns:
- true when ball hits the paddle
-
reflectOnPaddle
public void reflectOnPaddle(Paddle paddle)
Ball got hit by Paddle paddle- Specified by:
reflectOnPaddle
in interfaceIBall
- Parameters:
paddle
- hitbox mechanism of paddle
-
hitsStone
public boolean hitsStone(java.util.ArrayList<Stone> stones)
tests whether the ball touches any stone's hit box
-
getHitStone
public Stone getHitStone()
returns the stone which got hit, can be null- Specified by:
getHitStone
in interfaceIBall
- Returns:
- the stone which got hit
-
reflectOnStone
public void reflectOnStone(Stone stone)
Ball got hit by Stone stone- Parameters:
stone
- hitbox mechanism of stone
-
isLost
public boolean isLost()
The getter for balls lost state
-
setLost
public void setLost(boolean lost)
The setter for balls lost state- Parameters:
lost
- balls lost state
-
resetPosition
public void resetPosition()
resets balls position
-
resetDirection
public void resetDirection()
resets balls direction
-
-