mirror of
https://github.com/sigmasternchen/88x31breakout
synced 2025-03-15 07:59:00 +00:00
feat: Add collisions with paddle
This commit is contained in:
parent
e357656d00
commit
e864112755
2 changed files with 14 additions and 0 deletions
|
@ -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 => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue