Add pause on escape
This commit is contained in:
parent
93bd24e757
commit
705afa9dfd
1 changed files with 9 additions and 1 deletions
|
@ -17,6 +17,7 @@ const dieSound = new Audio("sources/sound/onDie.mp3");
|
||||||
const gameOverSound = new Audio("sources/sound/onGameOver.mp3");
|
const gameOverSound = new Audio("sources/sound/onGameOver.mp3");
|
||||||
const game = new Game(canvas);
|
const game = new Game(canvas);
|
||||||
const scores = [];
|
const scores = [];
|
||||||
|
let inGame = false;
|
||||||
|
|
||||||
let gameOverModal;
|
let gameOverModal;
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ req.onload = () => {
|
||||||
req.send();
|
req.send();
|
||||||
|
|
||||||
game.onStart = () => {
|
game.onStart = () => {
|
||||||
|
inGame = true;
|
||||||
updateLives(game.lives);
|
updateLives(game.lives);
|
||||||
updateScore(game.score);
|
updateScore(game.score);
|
||||||
menu.classList.add("invisible");
|
menu.classList.add("invisible");
|
||||||
|
@ -52,6 +54,7 @@ game.onStart = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
game.onStop = () => {
|
game.onStop = () => {
|
||||||
|
inGame = false;
|
||||||
menu.classList.remove("invisible");
|
menu.classList.remove("invisible");
|
||||||
gameZone.classList.add("invisible");
|
gameZone.classList.add("invisible");
|
||||||
};
|
};
|
||||||
|
@ -133,11 +136,16 @@ function reloadScoreBoard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
M.AutoInit();
|
M.AutoInit();
|
||||||
gameOverModal = M.Modal.getInstance(gameOver);
|
gameOverModal = M.Modal.getInstance(gameOver);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", ev => {
|
||||||
|
if (inGame && ev.key === "Escape")
|
||||||
|
alert("Game in pause...");
|
||||||
|
});
|
||||||
|
|
||||||
audio.addEventListener("canplaythrough", () => {
|
audio.addEventListener("canplaythrough", () => {
|
||||||
audio.play();
|
audio.play();
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue