diff --git a/frontend/static/js/views/Game.js b/frontend/static/js/views/Game.js index 57b936e..87dd0cb 100644 --- a/frontend/static/js/views/Game.js +++ b/frontend/static/js/views/Game.js @@ -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; - this.ball.x += this.ball.vx; - this.ball.y += this.ball.vy; + + 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); } }