diff --git a/sources/js/index.js b/sources/js/index.js index 350c397..3b19ba7 100644 --- a/sources/js/index.js +++ b/sources/js/index.js @@ -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(); });