From 5366e70440bcd4063afc6540d45e3bda8c7853c5 Mon Sep 17 00:00:00 2001 From: KingOfDog Date: Wed, 10 Apr 2019 18:02:55 +0200 Subject: [PATCH] Several improvements --- game.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/game.js b/game.js index 6c7e00e..fe880ee 100644 --- a/game.js +++ b/game.js @@ -1,12 +1,11 @@ class Game { constructor(container) { this.elements = { - highscore: container.querySelector('#highscore'), score: container.querySelector('#score'), - coinCount: container.querySelector('#coin-count'), pauseBtn: container.querySelector('.play-btn'), pauseMenu: container.querySelector('#pause-menu'), gameOverMenu: container.querySelector('#game-over-menu'), + speedUpContainer: container.querySelector('.speed-up-container'), }; this.canvas = container.querySelector('#canvas'); @@ -61,10 +60,12 @@ class Game { }); this.canvas.addEventListener('mouseup', (e) => { - this.mousePos = cbRelMousePos(e); - this.shoot().then(() => { - this.mousePos = null; - }); + if (this.mousePos) { + this.mousePos = cbRelMousePos(e); + this.shoot().then(() => { + this.mousePos = null; + }); + } }); this.elements.pauseBtn.addEventListener('click', () => { @@ -246,7 +247,7 @@ class Game { powerUp.remove(); }); } - }) + }); } increaseRoundNumber() { @@ -256,15 +257,14 @@ class Game { } increaseCoinCount() { - coinCount++; - - this.elements.coinCount.innerText = coinCount; + setCoinCount(coinCount + 1); } update() { - this.balls.forEach(ball => { - ball.update(10); - }); + for (let i = 0; i < this.speed; i++) { + this.balls.forEach(ball => { + ball.update(10); + }); this.coinAngle += .05; if (this.coinAngle >= 2 * Math.PI) { @@ -295,7 +295,7 @@ class Game { this.increaseRoundNumber(); this.addNewObjects(); this.shiftObjectsDown(); - this.play() + this.play(); } play() {