// Main game loop function loop() { // Draw game state ctx.fillStyle = 'white'; ctx.fillRect(0, 0, canvas.width, canvas.height); renderMaze(); checkGameState(); updateGameState(); // Update game state every 16 milliseconds window.requestAnimationFrame(loop); } loop(); // Add restart button click event listener var restartButton = document.getElementById('restart'); restartButton.addEventListener('click', function() { // Reset game state playerX = 100; playerY = 100; playerHealth = 10; playersEnemys = []; enemies = []; gameState = gameStates['playing']; init(); });