pong: fix unconstructed objects
This commit is contained in:
parent
39380d76af
commit
30023be33b
17
src/pong.ts
17
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user