diff --git a/game.js b/game.js index 7146286..6c7e00e 100644 --- a/game.js +++ b/game.js @@ -40,6 +40,8 @@ class Game { this.isMoving = false; this.isPaused = false; this.isGameOver = false; + this.speed = 1; + this.lastSpeedUp = 0; this.coinAngle = 0; this.mousePos = null; @@ -156,6 +158,7 @@ class Game { } this.isMoving = true; + this.lastSpeedUp = Date.now(); const dir = this.calcMouseAngle(); const ballCount = this.ballCount; @@ -172,6 +175,10 @@ class Game { } roundOver() { + this.speed = 1; + this.lastSpeedUp = Date.now(); + this.elements.speedUpContainer.innerHTML = ""; + this.ballCount += this.newBalls; this.newBalls = 0; this.remainingBalls = this.ballCount; @@ -259,9 +266,24 @@ class Game { ball.update(10); }); - this.coinAngle += .05; - if (this.coinAngle >= 2 * Math.PI) { - this.coinAngle -= 2 * Math.PI; + this.coinAngle += .05; + if (this.coinAngle >= 2 * Math.PI) { + this.coinAngle -= 2 * Math.PI; + } + + if (this.isMoving && Date.now() - this.lastSpeedUp >= 10000) { + const button = document.createElement('button'); + button.innerText = 'FASTER'; + this.elements.speedUpContainer.innerHTML = ""; + this.elements.speedUpContainer.appendChild(button); + + button.addEventListener('click', () => { + this.speed *= 2; + button.remove(); + }); + + this.lastSpeedUp = Date.now(); + } } if (!this.isPaused && !this.isGameOver) { @@ -278,6 +300,7 @@ class Game { play() { this.isPaused = false; + this.lastSpeedUp = Date.now(); this.update(); this.draw(); @@ -293,6 +316,7 @@ class Game { } destroy() { + this.elements.gameOverMenu.classList.remove('shown'); this.removeEventListeners(); } diff --git a/index.html b/index.html index 578386d..47c0f69 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@

0

-
+