Spaces:
Running
Running
Update index.html
Browse files- index.html +31 -32
index.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>World Grid Test (Fixed)</title>
|
7 |
<style>
|
8 |
body { font-family: 'Courier New', monospace; background-color: #111; color: #eee; margin: 0; padding: 0; overflow: hidden; display: flex; flex-direction: column; height: 100vh; }
|
9 |
#game-container { display: flex; flex-grow: 1; overflow: hidden; }
|
@@ -69,9 +69,9 @@
|
|
69 |
const choicesElement = document.getElementById('choices');
|
70 |
const statsElement = document.getElementById('stats-display');
|
71 |
const inventoryElement = document.getElementById('inventory-display');
|
72 |
-
const actionInfoElement = document.getElementById('action-info');
|
73 |
|
74 |
-
let scene, camera, renderer, clock, controls
|
75 |
let worldGroup = null;
|
76 |
let zoneGroups = {};
|
77 |
let currentMessage = "";
|
@@ -105,8 +105,6 @@
|
|
105 |
scene = new THREE.Scene();
|
106 |
scene.background = new THREE.Color(0x1a1a1a);
|
107 |
clock = new THREE.Clock();
|
108 |
-
raycaster = new THREE.Raycaster();
|
109 |
-
mouse = new THREE.Vector2();
|
110 |
worldGroup = new THREE.Group();
|
111 |
scene.add(worldGroup);
|
112 |
|
@@ -169,9 +167,9 @@
|
|
169 |
|
170 |
function setupLighting(type = 'default') {
|
171 |
currentLights.forEach(light => {
|
172 |
-
if (light) scene.remove(light);
|
173 |
});
|
174 |
-
currentLights = [];
|
175 |
|
176 |
let ambientIntensity = 0.5;
|
177 |
let dirIntensity = 1.0;
|
@@ -182,16 +180,17 @@
|
|
182 |
if (type === 'cave') {
|
183 |
ambientIntensity = 0.2; dirIntensity = 0;
|
184 |
const ptLight = new THREE.PointLight(0xffaa55, 1.5, 12, 1);
|
185 |
-
ptLight.position.set(0, 3, 0);
|
186 |
-
ptLight.castShadow = true;
|
187 |
-
|
188 |
-
|
|
|
189 |
}
|
190 |
if (type === 'ruins') { ambientIntensity = 0.4; dirIntensity = 0.7; dirColor = 0xaaaaff; dirPosition = new THREE.Vector3(-8, 12, -5); }
|
191 |
|
192 |
const ambientLight = new THREE.AmbientLight(0xffffff, ambientIntensity);
|
193 |
-
scene.add(ambientLight);
|
194 |
-
currentLights.push(ambientLight);
|
195 |
|
196 |
if (dirIntensity > 0) {
|
197 |
const directionalLight = new THREE.DirectionalLight(dirColor, dirIntensity);
|
@@ -203,7 +202,7 @@
|
|
203 |
directionalLight.shadow.camera.left = -sb; directionalLight.shadow.camera.right = sb;
|
204 |
directionalLight.shadow.camera.top = sb; directionalLight.shadow.camera.bottom = -sb;
|
205 |
directionalLight.shadow.bias = -0.0005;
|
206 |
-
scene.add(directionalLight);
|
207 |
currentLights.push(directionalLight);
|
208 |
}
|
209 |
}
|
@@ -252,11 +251,11 @@
|
|
252 |
const st = createMesh(coneGeo, MAT.stone, {x: (Math.random()-0.5)*16, y: 6 + Math.random()*2, z: (Math.random()-0.5)*16}, {x:Math.PI});
|
253 |
group.add(st);
|
254 |
}
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
group.visible = false;
|
261 |
return { group, lighting: 'cave', title: "Dim Cave", entryText: "It's dark and damp in here. Water drips.", options: [], zoneId: zoneId };
|
262 |
}
|
@@ -279,11 +278,10 @@
|
|
279 |
return { group, lighting: 'ruins', title: "Crumbling Ruins", entryText: "The wind whistles through broken walls.", options: [], zoneId: zoneId };
|
280 |
}
|
281 |
|
282 |
-
|
283 |
function getZoneId(row, col) { return `zone_${row}_${col}`; }
|
284 |
|
285 |
function populateZoneCreators() {
|
286 |
-
|
287 |
for (let r = 0; r < MAP_ROWS; r++) {
|
288 |
for (let c = 0; c < MAP_COLS; c++) {
|
289 |
const zoneId = getZoneId(r, c);
|
@@ -322,13 +320,12 @@
|
|
322 |
character: JSON.parse(JSON.stringify(defaultChar))
|
323 |
};
|
324 |
populateZoneCreators();
|
325 |
-
zoneGroups = {};
|
326 |
-
// Clear existing groups from worldGroup if any
|
327 |
while(worldGroup.children.length > 0){
|
328 |
worldGroup.remove(worldGroup.children[0]);
|
329 |
}
|
330 |
console.log("Starting new game:", gameState);
|
331 |
-
transitionToZone(getZoneId(1, 1));
|
332 |
}
|
333 |
|
334 |
function transitionToZone(newZoneId) {
|
@@ -367,16 +364,15 @@
|
|
367 |
}
|
368 |
|
369 |
gameState.currentZoneId = newZoneId;
|
370 |
-
setupLighting(zoneInfo.lighting || 'default');
|
371 |
|
372 |
-
|
373 |
currentLights.forEach(light => {
|
374 |
-
if (light.isPointLight && !light.parent) { //
|
375 |
-
zoneInfo.group.add(light);
|
376 |
}
|
377 |
});
|
378 |
|
379 |
-
|
380 |
camera.position.set(0, 6, 12);
|
381 |
controls.target.set(0, 1, 0);
|
382 |
controls.update();
|
@@ -411,7 +407,7 @@
|
|
411 |
const button = document.createElement('button');
|
412 |
button.classList.add('choice-button');
|
413 |
button.textContent = `Go ${directions[dir]}`;
|
414 |
-
button.onclick = () => transitionToZone(neighborId);
|
415 |
choicesElement.appendChild(button);
|
416 |
}
|
417 |
|
@@ -430,7 +426,7 @@
|
|
430 |
updateActionInfo();
|
431 |
}
|
432 |
|
433 |
-
window.transitionToZone = transitionToZone; // Make accessible
|
434 |
|
435 |
|
436 |
function updateStatsDisplay() {
|
@@ -454,6 +450,7 @@
|
|
454 |
}
|
455 |
|
456 |
function updateActionInfo() {
|
|
|
457 |
actionInfoElement.textContent = `Zone: ${gameState.currentZoneId || 'None'}`;
|
458 |
}
|
459 |
|
@@ -462,6 +459,8 @@
|
|
462 |
function togglePlacementMode() { console.log("Placement disabled.");}
|
463 |
function startCombat(enemyTypeId) { console.log("Combat disabled."); }
|
464 |
function handleCombatAction(action) { console.log("Combat disabled."); }
|
|
|
|
|
465 |
|
466 |
|
467 |
document.addEventListener('DOMContentLoaded', () => {
|
@@ -469,7 +468,7 @@
|
|
469 |
try {
|
470 |
initThreeJS();
|
471 |
if (!scene || !camera || !renderer) throw new Error("Three.js failed to initialize.");
|
472 |
-
startGame();
|
473 |
console.log("Game world initialized and started.");
|
474 |
} catch (error) {
|
475 |
console.error("Initialization failed:", error);
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>World Grid Test (Fixed Const Assignment)</title>
|
7 |
<style>
|
8 |
body { font-family: 'Courier New', monospace; background-color: #111; color: #eee; margin: 0; padding: 0; overflow: hidden; display: flex; flex-direction: column; height: 100vh; }
|
9 |
#game-container { display: flex; flex-grow: 1; overflow: hidden; }
|
|
|
69 |
const choicesElement = document.getElementById('choices');
|
70 |
const statsElement = document.getElementById('stats-display');
|
71 |
const inventoryElement = document.getElementById('inventory-display');
|
72 |
+
const actionInfoElement = document.getElementById('action-info');
|
73 |
|
74 |
+
let scene, camera, renderer, clock, controls;
|
75 |
let worldGroup = null;
|
76 |
let zoneGroups = {};
|
77 |
let currentMessage = "";
|
|
|
105 |
scene = new THREE.Scene();
|
106 |
scene.background = new THREE.Color(0x1a1a1a);
|
107 |
clock = new THREE.Clock();
|
|
|
|
|
108 |
worldGroup = new THREE.Group();
|
109 |
scene.add(worldGroup);
|
110 |
|
|
|
167 |
|
168 |
function setupLighting(type = 'default') {
|
169 |
currentLights.forEach(light => {
|
170 |
+
if (light) scene.remove(light);
|
171 |
});
|
172 |
+
currentLights = [];
|
173 |
|
174 |
let ambientIntensity = 0.5;
|
175 |
let dirIntensity = 1.0;
|
|
|
180 |
if (type === 'cave') {
|
181 |
ambientIntensity = 0.2; dirIntensity = 0;
|
182 |
const ptLight = new THREE.PointLight(0xffaa55, 1.5, 12, 1);
|
183 |
+
ptLight.position.set(0, 3, 0);
|
184 |
+
ptLight.castShadow = true;
|
185 |
+
ptLight.shadow.mapSize.set(512, 512);
|
186 |
+
// Will be added to zone group later
|
187 |
+
currentLights.push(ptLight);
|
188 |
}
|
189 |
if (type === 'ruins') { ambientIntensity = 0.4; dirIntensity = 0.7; dirColor = 0xaaaaff; dirPosition = new THREE.Vector3(-8, 12, -5); }
|
190 |
|
191 |
const ambientLight = new THREE.AmbientLight(0xffffff, ambientIntensity);
|
192 |
+
scene.add(ambientLight);
|
193 |
+
currentLights.push(ambientLight);
|
194 |
|
195 |
if (dirIntensity > 0) {
|
196 |
const directionalLight = new THREE.DirectionalLight(dirColor, dirIntensity);
|
|
|
202 |
directionalLight.shadow.camera.left = -sb; directionalLight.shadow.camera.right = sb;
|
203 |
directionalLight.shadow.camera.top = sb; directionalLight.shadow.camera.bottom = -sb;
|
204 |
directionalLight.shadow.bias = -0.0005;
|
205 |
+
scene.add(directionalLight);
|
206 |
currentLights.push(directionalLight);
|
207 |
}
|
208 |
}
|
|
|
251 |
const st = createMesh(coneGeo, MAT.stone, {x: (Math.random()-0.5)*16, y: 6 + Math.random()*2, z: (Math.random()-0.5)*16}, {x:Math.PI});
|
252 |
group.add(st);
|
253 |
}
|
254 |
+
// Add point light specific to cave if tracked
|
255 |
+
const caveLight = currentLights.find(l => l && l.isPointLight);
|
256 |
+
if (caveLight) {
|
257 |
+
group.add(caveLight);
|
258 |
+
}
|
259 |
group.visible = false;
|
260 |
return { group, lighting: 'cave', title: "Dim Cave", entryText: "It's dark and damp in here. Water drips.", options: [], zoneId: zoneId };
|
261 |
}
|
|
|
278 |
return { group, lighting: 'ruins', title: "Crumbling Ruins", entryText: "The wind whistles through broken walls.", options: [], zoneId: zoneId };
|
279 |
}
|
280 |
|
|
|
281 |
function getZoneId(row, col) { return `zone_${row}_${col}`; }
|
282 |
|
283 |
function populateZoneCreators() {
|
284 |
+
// No reassignment here! Just adding properties to existing const object.
|
285 |
for (let r = 0; r < MAP_ROWS; r++) {
|
286 |
for (let c = 0; c < MAP_COLS; c++) {
|
287 |
const zoneId = getZoneId(r, c);
|
|
|
320 |
character: JSON.parse(JSON.stringify(defaultChar))
|
321 |
};
|
322 |
populateZoneCreators();
|
323 |
+
zoneGroups = {};
|
|
|
324 |
while(worldGroup.children.length > 0){
|
325 |
worldGroup.remove(worldGroup.children[0]);
|
326 |
}
|
327 |
console.log("Starting new game:", gameState);
|
328 |
+
transitionToZone(getZoneId(1, 1));
|
329 |
}
|
330 |
|
331 |
function transitionToZone(newZoneId) {
|
|
|
364 |
}
|
365 |
|
366 |
gameState.currentZoneId = newZoneId;
|
367 |
+
setupLighting(zoneInfo.lighting || 'default'); // Setup general lighting
|
368 |
|
369 |
+
// Add zone-specific lights from setupLighting to the *current* zone's group
|
370 |
currentLights.forEach(light => {
|
371 |
+
if (light && light.isPointLight && !light.parent) { // If it's a point light tracked but not in scene
|
372 |
+
zoneInfo.group.add(light); // Add it to the now visible group
|
373 |
}
|
374 |
});
|
375 |
|
|
|
376 |
camera.position.set(0, 6, 12);
|
377 |
controls.target.set(0, 1, 0);
|
378 |
controls.update();
|
|
|
407 |
const button = document.createElement('button');
|
408 |
button.classList.add('choice-button');
|
409 |
button.textContent = `Go ${directions[dir]}`;
|
410 |
+
button.onclick = () => transitionToZone(neighborId); // Use transitionToZone directly
|
411 |
choicesElement.appendChild(button);
|
412 |
}
|
413 |
|
|
|
426 |
updateActionInfo();
|
427 |
}
|
428 |
|
429 |
+
window.transitionToZone = transitionToZone; // Make globally accessible
|
430 |
|
431 |
|
432 |
function updateStatsDisplay() {
|
|
|
450 |
}
|
451 |
|
452 |
function updateActionInfo() {
|
453 |
+
if (!actionInfoElement) return; // Guard against element not existing yet
|
454 |
actionInfoElement.textContent = `Zone: ${gameState.currentZoneId || 'None'}`;
|
455 |
}
|
456 |
|
|
|
459 |
function togglePlacementMode() { console.log("Placement disabled.");}
|
460 |
function startCombat(enemyTypeId) { console.log("Combat disabled."); }
|
461 |
function handleCombatAction(action) { console.log("Combat disabled."); }
|
462 |
+
window.startCombat = startCombat;
|
463 |
+
window.handleCombatAction = handleCombatAction;
|
464 |
|
465 |
|
466 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
468 |
try {
|
469 |
initThreeJS();
|
470 |
if (!scene || !camera || !renderer) throw new Error("Three.js failed to initialize.");
|
471 |
+
startGame(); // Start game directly
|
472 |
console.log("Game world initialized and started.");
|
473 |
} catch (error) {
|
474 |
console.error("Initialization failed:", error);
|