Several improvements

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

28
game.js
View File

@ -1,12 +1,11 @@
class Game { class Game {
constructor(container) { constructor(container) {
this.elements = { this.elements = {
highscore: container.querySelector('#highscore'),
score: container.querySelector('#score'), score: container.querySelector('#score'),
coinCount: container.querySelector('#coin-count'),
pauseBtn: container.querySelector('.play-btn'), pauseBtn: container.querySelector('.play-btn'),
pauseMenu: container.querySelector('#pause-menu'), pauseMenu: container.querySelector('#pause-menu'),
gameOverMenu: container.querySelector('#game-over-menu'), gameOverMenu: container.querySelector('#game-over-menu'),
speedUpContainer: container.querySelector('.speed-up-container'),
}; };
this.canvas = container.querySelector('#canvas'); this.canvas = container.querySelector('#canvas');
@ -61,10 +60,12 @@ class Game {
}); });
this.canvas.addEventListener('mouseup', (e) => { this.canvas.addEventListener('mouseup', (e) => {
this.mousePos = cbRelMousePos(e); if (this.mousePos) {
this.shoot().then(() => { this.mousePos = cbRelMousePos(e);
this.mousePos = null; this.shoot().then(() => {
}); this.mousePos = null;
});
}
}); });
this.elements.pauseBtn.addEventListener('click', () => { this.elements.pauseBtn.addEventListener('click', () => {
@ -246,7 +247,7 @@ class Game {
powerUp.remove(); powerUp.remove();
}); });
} }
}) });
} }
increaseRoundNumber() { increaseRoundNumber() {
@ -256,15 +257,14 @@ class Game {
} }
increaseCoinCount() { increaseCoinCount() {
coinCount++; setCoinCount(coinCount + 1);
this.elements.coinCount.innerText = coinCount;
} }
update() { update() {
this.balls.forEach(ball => { for (let i = 0; i < this.speed; i++) {
ball.update(10); this.balls.forEach(ball => {
}); ball.update(10);
});
this.coinAngle += .05; this.coinAngle += .05;
if (this.coinAngle >= 2 * Math.PI) { if (this.coinAngle >= 2 * Math.PI) {
@ -295,7 +295,7 @@ class Game {
this.increaseRoundNumber(); this.increaseRoundNumber();
this.addNewObjects(); this.addNewObjects();
this.shiftObjectsDown(); this.shiftObjectsDown();
this.play() this.play();
} }
play() { play() {