feat: Ball gets removed when reaching bottom

This commit is contained in:
sigmasternchen 2024-11-03 20:21:49 +01:00
parent a43a70f523
commit d8d6ba0118
2 changed files with 6 additions and 1 deletions

View file

@ -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;

View file

@ -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);
}
}
}