From 30023be33bb0b38525f29bad10f53d5247b35a44 Mon Sep 17 00:00:00 2001 From: Trimutex Date: Fri, 27 Dec 2024 10:34:39 -0600 Subject: [PATCH] pong: fix unconstructed objects --- src/pong.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pong.ts b/src/pong.ts index 5f140e3..ef2a2cf 100644 --- a/src/pong.ts +++ b/src/pong.ts @@ -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() {