add: ball respawn timeout
This commit is contained in:
parent
754e5867f2
commit
63e1520e6a
@ -86,6 +86,7 @@ class Game {
|
||||
}
|
||||
];
|
||||
this.ballStartSide = 0;
|
||||
this.ballRespawned = false;
|
||||
this.ball = new Ball(this.context, this.def, this.ballStartSide);
|
||||
|
||||
this.interval = setInterval(this.updateGame.bind(this), 10);
|
||||
@ -140,8 +141,11 @@ class Game {
|
||||
this.ball.vy *= -1;
|
||||
else if (this.ball.y + this.ball.radius >= this.canvas.height)
|
||||
this.ball.vy *= -1;
|
||||
|
||||
if (!this.ballRespawned) {
|
||||
this.ball.x += this.ball.vx;
|
||||
this.ball.y += this.ball.vy;
|
||||
}
|
||||
|
||||
this.clear();
|
||||
this.players[0].paddle.update();
|
||||
@ -161,6 +165,9 @@ class Game {
|
||||
this.scoresDisplay.innerHTML = `Scores: ${p1Score} - ${p2Score}`;
|
||||
this.ballStartSide = 1 - this.ballStartSide;
|
||||
this.ball = new Ball(this.context, this.def, this.ballStartSide);
|
||||
this.ballRespawned = true;
|
||||
new Promise(r => setTimeout(r, 300))
|
||||
.then(_ => this.ballRespawned = false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user