Enable player to speed up game
This commit is contained in:
24
game.js
24
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;
|
||||
@@ -264,6 +271,21 @@ class Game {
|
||||
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) {
|
||||
requestAnimationFrame(() => this.update());
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@
|
||||
<h3 id="coin-count">0</h3>
|
||||
</div>
|
||||
|
||||
<div></div>
|
||||
<div class="speed-up-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="game-container">
|
||||
|
Reference in New Issue
Block a user