Several improvements

This commit is contained in:
KingOfDog 2019-04-10 18:02:55 +02:00 committed by Marcel
parent 3cfd384b84
commit 5366e70440

14
game.js
View File

@ -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) => {
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,12 +257,11 @@ class Game {
}
increaseCoinCount() {
coinCount++;
this.elements.coinCount.innerText = coinCount;
setCoinCount(coinCount + 1);
}
update() {
for (let i = 0; i < this.speed; i++) {
this.balls.forEach(ball => {
ball.update(10);
});
@ -295,7 +295,7 @@ class Game {
this.increaseRoundNumber();
this.addNewObjects();
this.shiftObjectsDown();
this.play()
this.play();
}
play() {