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 game = new Game(canvas);
|
||||
const scores = [];
|
||||
let inGame = false;
|
||||
|
||||
let gameOverModal;
|
||||
|
||||
|
@ -43,6 +44,7 @@ req.onload = () => {
|
|||
req.send();
|
||||
|
||||
game.onStart = () => {
|
||||
inGame = true;
|
||||
updateLives(game.lives);
|
||||
updateScore(game.score);
|
||||
menu.classList.add("invisible");
|
||||
|
@ -52,6 +54,7 @@ game.onStart = () => {
|
|||
};
|
||||
|
||||
game.onStop = () => {
|
||||
inGame = false;
|
||||
menu.classList.remove("invisible");
|
||||
gameZone.classList.add("invisible");
|
||||
};
|
||||
|
@ -133,11 +136,16 @@ function reloadScoreBoard() {
|
|||
}
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
M.AutoInit();
|
||||
gameOverModal = M.Modal.getInstance(gameOver);
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", ev => {
|
||||
if (inGame && ev.key === "Escape")
|
||||
alert("Game in pause...");
|
||||
});
|
||||
|
||||
audio.addEventListener("canplaythrough", () => {
|
||||
audio.play();
|
||||
});
|
||||
|
|
Reference in a new issue