Several improvements
This commit is contained in:
parent
3cfd384b84
commit
5366e70440
14
game.js
14
game.js
|
@ -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) => {
|
||||||
|
if (this.mousePos) {
|
||||||
this.mousePos = cbRelMousePos(e);
|
this.mousePos = cbRelMousePos(e);
|
||||||
this.shoot().then(() => {
|
this.shoot().then(() => {
|
||||||
this.mousePos = null;
|
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,12 +257,11 @@ class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
increaseCoinCount() {
|
increaseCoinCount() {
|
||||||
coinCount++;
|
setCoinCount(coinCount + 1);
|
||||||
|
|
||||||
this.elements.coinCount.innerText = coinCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
|
for (let i = 0; i < this.speed; i++) {
|
||||||
this.balls.forEach(ball => {
|
this.balls.forEach(ball => {
|
||||||
ball.update(10);
|
ball.update(10);
|
||||||
});
|
});
|
||||||
|
@ -295,7 +295,7 @@ class Game {
|
||||||
this.increaseRoundNumber();
|
this.increaseRoundNumber();
|
||||||
this.addNewObjects();
|
this.addNewObjects();
|
||||||
this.shiftObjectsDown();
|
this.shiftObjectsDown();
|
||||||
this.play()
|
this.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
play() {
|
play() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user