Enable player to speed up game

This commit is contained in:
KingOfDog 2019-04-10 18:00:13 +02:00 committed by Marcel
parent 07424dd662
commit 04ee870a5e
2 changed files with 28 additions and 4 deletions

30
game.js
View File

@ -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();
}

View File

@ -29,7 +29,7 @@
<h3 id="coin-count">0</h3>
</div>
<div></div>
<div class="speed-up-container"></div>
</div>
<div class="game-container">