Several improvements
This commit is contained in:
parent
3cfd384b84
commit
5366e70440
28
game.js
28
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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user