From d8d6ba01187057bc49e035dc662e129623afb07e Mon Sep 17 00:00:00 2001 From: sigmasternchen Date: Sun, 3 Nov 2024 20:21:49 +0100 Subject: [PATCH] feat: Ball gets removed when reaching bottom --- src/game/Ball.ts | 4 ++++ src/game/Game.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/game/Ball.ts b/src/game/Ball.ts index 38aeef2..16c0ae5 100644 --- a/src/game/Ball.ts +++ b/src/game/Ball.ts @@ -34,6 +34,10 @@ export class Ball { gameElement.appendChild(this.element); } + public readonly remove = (gameElement: HTMLElement): void => { + gameElement.removeChild(this.element); + } + public readonly launch = (): void => { this.phi = choice(startAngles); this.speed = defaultBallSpeed; diff --git a/src/game/Game.ts b/src/game/Game.ts index 4234a06..dfb65ac 100644 --- a/src/game/Game.ts +++ b/src/game/Game.ts @@ -74,7 +74,8 @@ export class Game { } else if (ball.position.y - ballSize / 2 < 0) { ball.collision(0); } else if (ball.position.y + ballSize / 2 >= fieldHeight) { - ball.collision(0); + ball.remove(this.root); + this.balls = this.balls.filter(_ball => _ball != ball); } } }