Fixed game startup issues and added comprehensive debug logging
- Added missing getOppositeDirection function to prevent JavaScript errors - Enhanced initialization logging with detailed state tracking - Added comprehensive debug logging for space button interactions - Improved mobile control detection and setup logging - Added state transition logging for ATTRACT → START → READY → PLAYING - Fixed critical runtime errors preventing game from starting
This commit is contained in:
46
pacman.html
46
pacman.html
@@ -683,6 +683,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) {
|
||||
const nextPos = getNextPosition(pacman.x, pacman.y, 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();
|
||||
|
||||
Reference in New Issue
Block a user