Class Ball

  • All Implemented Interfaces:
    IBall

    public class Ball
    extends java.lang.Object
    implements IBall
    This class contains the information about the balls characteristics and behavior
    Author:
    iSchumacher; modified by Gruppe 175 (Moritz Henseleit, Ruben Meyer)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Vector2D direction
      The balls direction
      private 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.
    • Field Detail

      • position

        private Position position
        The balls position on the playground
      • direction

        private Vector2D direction
        The balls direction
    • Constructor Detail

      • Ball

        public Ball()
        The constructor of a ball The balls position and direction are initialized here.
    • Method Detail

      • getPosition

        public Position getPosition()
        The getter for the balls position
        Specified by:
        getPosition in interface IBall
        Returns:
        position The balls current position
      • getDirection

        public Vector2D getDirection()
        The getter for the balls direction
        Specified by:
        getDirection in interface IBall
        Returns:
        direction The balls current direction
      • updatePosition

        public void updatePosition()
        updates ball position
        Specified by:
        updatePosition in interface IBall
      • reactOnBorder

        public void reactOnBorder()
        Ball reacts to contact with the borders
        Specified by:
        reactOnBorder in interface IBall
      • hitsPaddle

        public boolean hitsPaddle​(Paddle paddle)
        tests whether the ball touches the paddle's hit box.
        Specified by:
        hitsPaddle in interface IBall
        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 interface IBall
        Parameters:
        paddle - hitbox mechanism of paddle