Пример #1
0
  /**
   * This method calculates whether the ball is out of bounds or not, i.e. whether the ball has left
   * the screen. If it has the method will return true as well as incrementing the score of the
   * relevant player depending on which side of the screen the ball went off at.
   *
   * @return returns true if the balls has left the screen and false otherwise.
   */
  public boolean isOutOfBounds() {
    /* if the top right point of the ball is less than zero it's passed the
     * left side of the screen, therefore player 2 has scored and the ball is
     * out of bounds */
    if (topRightPoint.getX() < (GameDimensions.FIELD_WIDTH / 2) * -1.0f) {
      ScorePanel.incPlayer2Score();
      return true;

    } // if
    /* if the bottom (bottom/top doesn't matter) left point of the ball is
     * greater than the window width it's passed the right side of the
     * screen, therefore player 2 has scored and the ball is out of bounds */
    else if (bottomLeftPoint.getX() > (GameDimensions.FIELD_WIDTH / 2)) {
      ScorePanel.incPlayer1Score();
      return true;
    } // else if
    else return false;
  } // isOutOfBounds