diff --git a/src/game/Game.ts b/src/game/Game.ts index 0ce3eb5..81971b2 100644 --- a/src/game/Game.ts +++ b/src/game/Game.ts @@ -58,6 +58,7 @@ export class Game { private readonly handleCollisions = (ball: Ball): void => { this.handleEdgeCollisions(ball); + this.paddle.handleCollisions(ball); } private readonly handleEdgeCollisions = (ball: Ball): void => { diff --git a/src/game/Paddle.ts b/src/game/Paddle.ts index 82f8ce3..98b938a 100644 --- a/src/game/Paddle.ts +++ b/src/game/Paddle.ts @@ -59,4 +59,17 @@ export class Paddle { this.ball.setup(gameElement); } } + + public readonly handleCollisions = (ball: Ball): void => { + if ( + ball.position.y + ballSize / 2 > paddleY && + ball.position.x + ballSize / 2 > this.position - this.size / 2 && + ball.position.x - ballSize / 2 < this.position + this.size / 2 + ) { + const t = (ball.position.x - this.position + this.size / 2) / this.size; + const phi = (t - 0.5) * -2 * Math.PI / 8; + + ball.collision(phi); + } + } } \ No newline at end of file