class Ball extends Entity {
  --cięcie--
  checkPaddleCollision(paddle, xSpeedAfterBounce) {
    let ballBox = this.boundingBox();
    let paddleBox = paddle.boundingBox();

    // Sprawdzenie, czy paletka i piłeczka nachodzą na siebie w pionie oraz w poziomie
    let collisionOccurred = (
      ballBox.left   < paddleBox.right &&
      ballBox.right  > paddleBox.left &&
      ballBox.top    < paddleBox.bottom &&
      ballBox.bottom > paddleBox.top
    );

    if (collisionOccurred) {
      let distanceFromTop = ballBox.top - paddleBox.top;
      let distanceFromBottom = paddleBox.bottom - ballBox.bottom;
      this.adjustAngle(distanceFromTop, distanceFromBottom);   ❸
      this.xSpeed = xSpeedAfterBounce;
    }
  }

  checkWallCollision(width, height, scores) {
    let ballBox = this.boundingBox();

    // Zderzenie z lewą ścianą
    if (ballBox.left < 0) {
      scores.rightScore++;
      this.init();
    }
    // Zderzenie z prawą ścianą
    if (ballBox.right > width) {
      scores.leftScore++;
      this.init();
    }
    // Zderzenie z górną lub dolną ścianą
    if (ballBox.top < 0 || ballBox.bottom > height) {
      this.ySpeed = -this.ySpeed;
    }
  }
}
