diff --git a/pacman.html b/pacman.html
index 9cf6a4a..8c81479 100644
--- a/pacman.html
+++ b/pacman.html
@@ -682,6 +682,17 @@
return false; // Still traveling home
}
+
+ // Helper function for opposite direction
+ function getOppositeDirection(direction) {
+ switch(direction) {
+ case 'UP': return 'DOWN';
+ case 'DOWN': return 'UP';
+ case 'LEFT': return 'RIGHT';
+ case 'RIGHT': return 'LEFT';
+ default: return direction;
+ }
+ }
function movePacman() {
if (pacman.nextDirection) {
@@ -1328,26 +1339,27 @@
}
function handleSpaceButton() {
- console.log('Space button pressed, current game state:', gameState);
+ console.log('=== SPACE BUTTON PRESSED ===');
+ console.log('Current game state:', gameState);
+ console.log('Space button element:', mobileSpaceBtnElement);
- // Proper assembly-based state transitions
if (gameState === 'ATTRACT') {
- // From ATTRACT mode, go to START state (show title screen)
+ console.log('ATTRACT → START transition');
gameState = 'START';
attractModeTimer = 0;
startScreenElement.style.display = 'block';
- console.log('ATTRACT → START');
+ console.log('ATTRACT → START completed');
soundSystem.play('ready');
} else if (gameState === 'START') {
- // From START state, go to READY state (show "READY!" for 3 seconds)
+ console.log('START → READY transition');
gameState = 'READY';
- readyTimer = 180; // 3 seconds at 60fps (based on assembly timing)
+ readyTimer = 180;
startScreenElement.style.display = 'none';
resetPositions();
- console.log('START → READY');
+ console.log('START → READY completed');
soundSystem.play('ready');
} else if (gameState === 'GAME_OVER') {
- // From GAME_OVER, restart to START state
+ console.log('GAME_OVER → START transition');
gameState = 'START';
gameOverElement.style.display = 'none';
score = 0;
@@ -1357,34 +1369,48 @@
updateLives();
maze = JSON.parse(JSON.stringify(mazeLayout));
startScreenElement.style.display = 'block';
- console.log('GAME_OVER → START');
+ console.log('GAME_OVER → START completed');
soundSystem.play('ready');
} else if (gameState === 'PLAYING') {
- // If already playing, do nothing (or could pause)
console.log('Already in PLAYING state');
+ } else {
+ console.log('Unhandled game state:', gameState);
}
+ console.log('New game state:', gameState);
updateDebugInfo();
+ console.log('=== SPACE BUTTON HANDLER COMPLETE ===');
}
// Initialize game with ATTRACT mode (assembly-based startup)
+ console.log('=== INITIALIZING GAME ===');
gameState = 'ATTRACT';
attractModeTimer = 0;
+ console.log('Mobile detected:', isMobile);
+ console.log('Window width:', window.innerWidth);
+
// Setup mobile controls
if (isMobile || window.innerWidth <= 768) {
+ console.log('Setting up mobile controls...');
setupMobileControls();
+ } else {
+ console.log('Not setting up mobile controls - desktop mode');
}
// Show mobile controls
mobileControlsElement.classList.add('active');
mobileSpaceBtnElement.style.display = 'block';
+ console.log('Mobile space button element:', mobileSpaceBtnElement);
+ console.log('Mobile controls element:', mobileControlsElement);
+
// Update debug info
updateDebugInfo();
console.log('Full Pacman game initialized with ATTRACT mode');
console.log('Game state:', gameState);
+ console.log('=== GAME INITIALIZATION COMPLETE ===');
// Start game loop
gameLoop();