pong: fix unconstructed objects

This commit is contained in:
Trimutex 2024-12-27 10:34:39 -06:00
parent 39380d76af
commit 30023be33b

View File

@ -27,7 +27,9 @@ class Paddle {
score: number;
dy: number;
constructor() {
constructor(_geometry: Box, _isLeft: boolean) {
this.geometry = _geometry;
this.isLeft = _isLeft;
this.speed = 6;
this.isBot = true;
this.score = 0;
@ -38,14 +40,6 @@ class Paddle {
this.score++;
}
updateGeometry(_geometry: Box) {
this.geometry = _geometry;
}
updateSide(_isLeft: boolean) {
this.isLeft = _isLeft;
}
input() {
if (!this.isBot)
return;
@ -102,8 +96,9 @@ class PongCore {
this.height = this.canvas.height;
this.gameover = false;
this.paddleSpeed = 6;
this.left.updateGeometry(new Box(this.width / 2, this.height / 2 - this.paddleHeight / 2, this.grid, this.paddleHeight));
this.right.updateGeometry(new Box(this.width - this.grid * 3, this.height / 2 - this.paddleHeight / 2, this.grid, this.paddleHeight));
this.ball = new Ball();
this.left = new Paddle(new Box(this.width / 2, this.height / 2 - this.paddleHeight / 2, this.grid, this.paddleHeight), true);
this.right = new Paddle(new Box(this.width - this.grid * 3, this.height / 2 - this.paddleHeight / 2, this.grid, this.paddleHeight), false);
}
start() {