-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
84 lines (68 loc) · 2.69 KB
/
main.js
File metadata and controls
84 lines (68 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
console.log('adding event listener');
// import * as THREE from 'three'; // Removed unused import
import { Game } from './game.js';
// Create game instance in global scope for debugging
let game;
// Global starter function for debugging
window.startGame = function() {
console.log("Manual game start triggered");
const gameTitle = document.getElementById('game-title');
if (gameTitle) gameTitle.style.display = 'none';
if (game) {
game.start();
} else {
console.error("Game instance not available");
}
};
document.addEventListener('DOMContentLoaded', () => {
console.log('DOM fully loaded');
// Initialize game but don't start yet
game = new Game('game-container');
// Add event listener to start button
const startButton = document.getElementById('start-game');
const gameTitle = document.getElementById('game-title');
console.log('Start button element:', startButton);
if (startButton) {
console.log('Adding click listener to start button');
// Add multiple event listeners to ensure it works
startButton.addEventListener('click', gameStarter);
startButton.addEventListener('mousedown', gameStarter);
startButton.addEventListener('touchstart', gameStarter);
// Make the button more obvious for debugging
startButton.style.border = '3px solid red';
} else {
console.error('Start button not found in the DOM');
}
// Function to start the game
function gameStarter(e) {
console.log('Start button clicked', e.type);
e.preventDefault();
// Hide the title screen
if (gameTitle) gameTitle.style.display = 'none';
// Start the game
game.start();
// Focus on the game container for keyboard input
const container = document.getElementById('game-container');
if (container) container.focus();
}
// Add debug key listener (D key)
document.addEventListener('keydown', (e) => {
if (e.key === 'd') {
game.debugMode = !game.debugMode;
console.log('Debug mode:', game.debugMode);
} else if (e.key === 's') {
// Alternative way to start the game with 'S' key
console.log('Starting game with S key');
if (gameTitle) gameTitle.style.display = 'none';
game.start();
}
});
// Auto-start after 5 seconds if nothing happens
console.log('Setting auto-start timeout');
setTimeout(() => {
if (!game.isRunning) {
console.log('Auto-starting game after timeout');
window.startGame();
}
}, 5000);
});