Spaces:
Running
Running
Update index.html
Browse files- index.html +162 -759
index.html
CHANGED
@@ -16,104 +16,74 @@
|
|
16 |
flex-direction: column;
|
17 |
height: 100vh;
|
18 |
}
|
19 |
-
|
20 |
-
#game-container {
|
21 |
-
display: flex;
|
22 |
-
flex-grow: 1;
|
23 |
-
overflow: hidden;
|
24 |
-
}
|
25 |
-
|
26 |
#scene-container {
|
27 |
-
flex-grow: 3;
|
28 |
-
|
29 |
-
border-right: 2px solid #555;
|
30 |
-
min-width: 200px;
|
31 |
-
background-color: #1a1a1a;
|
32 |
-
height: 100%;
|
33 |
-
box-sizing: border-box;
|
34 |
}
|
35 |
-
|
36 |
#ui-container {
|
37 |
-
flex-grow: 2;
|
38 |
-
|
39 |
-
|
40 |
-
background-color: #333;
|
41 |
-
min-width: 280px;
|
42 |
-
height: 100%;
|
43 |
-
box-sizing: border-box;
|
44 |
-
display: flex;
|
45 |
-
flex-direction: column;
|
46 |
}
|
47 |
-
|
48 |
#scene-container canvas { display: block; }
|
49 |
-
|
50 |
#story-title {
|
51 |
-
color: #ffcc66;
|
52 |
-
|
53 |
-
margin-bottom: 15px;
|
54 |
-
border-bottom: 1px solid #555;
|
55 |
-
padding-bottom: 10px;
|
56 |
-
font-size: 1.4em;
|
57 |
-
}
|
58 |
-
|
59 |
-
#story-content {
|
60 |
-
margin-bottom: 20px;
|
61 |
-
line-height: 1.6;
|
62 |
-
flex-grow: 1;
|
63 |
}
|
|
|
64 |
#story-content p { margin-bottom: 1em; }
|
65 |
#story-content p:last-child { margin-bottom: 0; }
|
66 |
-
|
67 |
#stats-inventory-container {
|
68 |
-
margin-bottom: 20px;
|
69 |
-
|
70 |
-
border-bottom: 1px solid #555;
|
71 |
-
font-size: 0.9em;
|
72 |
}
|
73 |
#stats-display, #inventory-display {
|
74 |
-
margin-bottom: 10px;
|
75 |
-
line-height: 1.8;
|
76 |
}
|
77 |
#stats-display span, #inventory-display span {
|
78 |
-
display: inline-block;
|
79 |
-
|
80 |
-
|
81 |
-
border-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
white-space: nowrap;
|
86 |
}
|
87 |
-
#stats-display strong, #inventory-display strong { color: #aaa; margin-right: 5px; }
|
88 |
#inventory-display em { color: #888; font-style: normal; }
|
89 |
-
|
90 |
#inventory-display .item-quest { background-color: #666030; border-color: #999048;}
|
91 |
#inventory-display .item-weapon { background-color: #663030; border-color: #994848;}
|
92 |
#inventory-display .item-armor { background-color: #306630; border-color: #489948;}
|
93 |
#inventory-display .item-spell { background-color: #303066; border-color: #484899;}
|
94 |
#inventory-display .item-unknown { background-color: #555; border-color: #777;}
|
95 |
-
|
96 |
#choices-container {
|
97 |
-
margin-top: auto;
|
98 |
-
padding-top: 15px;
|
99 |
-
border-top: 1px solid #555;
|
100 |
}
|
101 |
#choices-container h3 { margin-top: 0; margin-bottom: 10px; color: #aaa; }
|
102 |
#choices { display: flex; flex-direction: column; gap: 10px; }
|
103 |
-
|
104 |
.choice-button {
|
105 |
-
display: block; width: 100%; padding: 10px 12px;
|
106 |
background-color: #555; color: #eee; border: 1px solid #777;
|
107 |
border-radius: 5px; cursor: pointer; text-align: left;
|
108 |
font-family: 'Courier New', monospace; font-size: 1em;
|
109 |
transition: background-color 0.2s, border-color 0.2s;
|
110 |
box-sizing: border-box;
|
111 |
}
|
112 |
-
.choice-button:hover:not(:disabled) {
|
113 |
-
|
114 |
-
|
115 |
-
.
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
</style>
|
118 |
</head>
|
119 |
<body>
|
@@ -136,16 +106,18 @@
|
|
136 |
</div>
|
137 |
|
138 |
<script type="importmap">
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
}
|
|
|
145 |
</script>
|
146 |
|
147 |
<script type="module">
|
148 |
import * as THREE from 'three';
|
|
|
149 |
|
150 |
const sceneContainer = document.getElementById('scene-container');
|
151 |
const storyTitleElement = document.getElementById('story-title');
|
@@ -154,732 +126,163 @@
|
|
154 |
const statsElement = document.getElementById('stats-display');
|
155 |
const inventoryElement = document.getElementById('inventory-display');
|
156 |
|
157 |
-
let scene, camera, renderer;
|
158 |
-
let currentAssemblyGroup = null;
|
159 |
|
160 |
-
// Materials
|
161 |
const stoneMaterial = new THREE.MeshStandardMaterial({ color: 0x888888, roughness: 0.8, metalness: 0.1 });
|
162 |
-
const
|
163 |
-
const darkWoodMaterial = new THREE.MeshStandardMaterial({ color: 0x5C3D20, roughness: 0.7, metalness: 0 });
|
164 |
-
const leafMaterial = new THREE.MeshStandardMaterial({ color: 0x2E8B57, roughness: 0.6, metalness: 0 });
|
165 |
-
const groundMaterial = new THREE.MeshStandardMaterial({ color: 0x556B2F, roughness: 0.9, metalness: 0 });
|
166 |
-
const metalMaterial = new THREE.MeshStandardMaterial({ color: 0xaaaaaa, metalness: 0.8, roughness: 0.3 });
|
167 |
const templeMaterial = new THREE.MeshStandardMaterial({ color: 0xA99B78, roughness: 0.7, metalness: 0.1 });
|
168 |
-
const errorMaterial = new THREE.MeshStandardMaterial({ color: 0xffa500, roughness: 0.5 });
|
169 |
-
const gameOverMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000, roughness: 0.5 });
|
170 |
const dirtMaterial = new THREE.MeshStandardMaterial({ color: 0x8B5E3C, roughness: 0.9 });
|
171 |
-
const grassMaterial = new THREE.MeshStandardMaterial({ color: 0x3CB371, roughness: 0.8 });
|
172 |
-
const oceanMaterial = new THREE.MeshStandardMaterial({ color: 0x1E90FF, roughness: 0.5, metalness: 0.2 });
|
173 |
-
const sandMaterial = new THREE.MeshStandardMaterial({ color: 0xF4A460, roughness: 0.9 });
|
174 |
-
const wetStoneMaterial = new THREE.MeshStandardMaterial({ color: 0x2F4F4F, roughness: 0.7 });
|
175 |
-
const glowMaterial = new THREE.MeshStandardMaterial({ color: 0x00FFAA, emissive: 0x00FFAA, emissiveIntensity: 0.5 });
|
176 |
|
177 |
function initThreeJS() {
|
178 |
-
if (!sceneContainer) { console.error("Scene container not found!"); return; }
|
179 |
scene = new THREE.Scene();
|
180 |
scene.background = new THREE.Color(0x222222);
|
181 |
-
const
|
182 |
-
|
183 |
-
camera
|
184 |
-
|
185 |
-
|
186 |
-
renderer = new THREE.WebGLRenderer({ antialias: true });
|
187 |
-
renderer.setSize(width || 400, height || 300);
|
188 |
renderer.shadowMap.enabled = true;
|
189 |
-
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
190 |
sceneContainer.appendChild(renderer.domElement);
|
191 |
-
|
192 |
-
|
193 |
-
window.addEventListener('resize', onWindowResize, false);
|
194 |
-
setTimeout(onWindowResize, 100);
|
195 |
animate();
|
196 |
}
|
197 |
|
198 |
function onWindowResize() {
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
if (width > 0 && height > 0) {
|
203 |
-
camera.aspect = width / height;
|
204 |
-
camera.updateProjectionMatrix();
|
205 |
-
renderer.setSize(width, height);
|
206 |
-
}
|
207 |
}
|
208 |
|
209 |
function animate() {
|
210 |
requestAnimationFrame(animate);
|
211 |
-
const
|
212 |
-
scene.traverse(
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
}
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
mesh.
|
223 |
-
mesh.rotation.set(rotation.x, rotation.y, rotation.z);
|
224 |
-
mesh.scale.set(scale.x, scale.y, scale.z);
|
225 |
-
mesh.castShadow = true; mesh.receiveShadow = true;
|
226 |
return mesh;
|
227 |
}
|
228 |
|
229 |
-
function
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
const group = new THREE.Group();
|
240 |
-
const sphereGeo = new THREE.SphereGeometry(0.5, 16, 16);
|
241 |
-
group.add(createMesh(sphereGeo, stoneMaterial, { x: 0, y: 0.5, z: 0 }));
|
242 |
-
group.add(createGroundPlane());
|
243 |
-
return group;
|
244 |
-
}
|
245 |
-
|
246 |
-
function createCityGatesAssembly() {
|
247 |
-
const group = new THREE.Group();
|
248 |
-
const gh=4, gw=1.5, gd=0.8, ah=1, aw=3;
|
249 |
-
const tlGeo = new THREE.BoxGeometry(gw, gh, gd);
|
250 |
-
group.add(createMesh(tlGeo, stoneMaterial, { x:-(aw/2+gw/2), y:gh/2, z:0 }));
|
251 |
-
const trGeo = new THREE.BoxGeometry(gw, gh, gd);
|
252 |
-
group.add(createMesh(trGeo, stoneMaterial, { x:(aw/2+gw/2), y:gh/2, z:0 }));
|
253 |
-
const aGeo = new THREE.BoxGeometry(aw, ah, gd);
|
254 |
-
group.add(createMesh(aGeo, stoneMaterial, { x:0, y:gh-ah/2, z:0 }));
|
255 |
-
const cs=0.4;
|
256 |
-
const cg = new THREE.BoxGeometry(cs, cs, gd*1.1);
|
257 |
-
for(let i=-1; i<=1; i+=2){
|
258 |
-
group.add(createMesh(cg.clone(), stoneMaterial, { x:-(aw/2+gw/2)+i*cs*0.7, y:gh+cs/2, z:0 }));
|
259 |
-
group.add(createMesh(cg.clone(), stoneMaterial, { x:(aw/2+gw/2)+i*cs*0.7, y:gh+cs/2, z:0 }));
|
260 |
-
}
|
261 |
-
group.add(createMesh(cg.clone(), stoneMaterial, { x:0, y:gh+ah-cs/2, z:0 }));
|
262 |
-
group.add(createGroundPlane(stoneMaterial));
|
263 |
-
return group;
|
264 |
-
}
|
265 |
-
|
266 |
-
function createWeaponsmithAssembly() {
|
267 |
-
const group = new THREE.Group();
|
268 |
-
const bw=3, bh=2.5, bd=3.5;
|
269 |
-
const bGeo = new THREE.BoxGeometry(bw, bh, bd);
|
270 |
-
group.add(createMesh(bGeo, darkWoodMaterial, { x:0, y:bh/2, z:0 }));
|
271 |
-
const ch=3.5;
|
272 |
-
const cGeo = new THREE.CylinderGeometry(0.3, 0.4, ch, 8);
|
273 |
-
group.add(createMesh(cGeo, stoneMaterial, { x:bw*0.3, y:ch/2, z:-bd*0.3 }));
|
274 |
-
group.add(createGroundPlane());
|
275 |
-
return group;
|
276 |
-
}
|
277 |
-
|
278 |
-
function createTempleAssembly() {
|
279 |
-
const group = new THREE.Group();
|
280 |
-
const bs=5, bsh=0.5, ch=3, cr=0.25, rh=0.5;
|
281 |
-
const bGeo = new THREE.BoxGeometry(bs, bsh, bs);
|
282 |
-
group.add(createMesh(bGeo, templeMaterial, { x:0, y:bsh/2, z:0 }));
|
283 |
-
const cGeo = new THREE.CylinderGeometry(cr, cr, ch, 12);
|
284 |
-
const cPos = [{x:-bs/3, z:-bs/3}, {x:bs/3, z:-bs/3}, {x:-bs/3, z:bs/3}, {x:bs/3, z:bs/3}];
|
285 |
-
cPos.forEach(p=>group.add(createMesh(cGeo.clone(), templeMaterial, { x:p.x, y:bsh+ch/2, z:p.z })));
|
286 |
-
const rGeo = new THREE.BoxGeometry(bs*0.9, rh, bs*0.9);
|
287 |
-
group.add(createMesh(rGeo, templeMaterial, { x:0, y:bsh+ch+rh/2, z:0 }));
|
288 |
-
group.add(createGroundPlane());
|
289 |
-
return group;
|
290 |
-
}
|
291 |
-
|
292 |
-
function createResistanceMeetingAssembly() {
|
293 |
-
const group = new THREE.Group();
|
294 |
-
const tw=2, th=0.8, td=1, tt=0.1;
|
295 |
-
const ttg = new THREE.BoxGeometry(tw, tt, td);
|
296 |
-
group.add(createMesh(ttg, woodMaterial, { x:0, y:th-tt/2, z:0 }));
|
297 |
-
const lh=th-tt, ls=0.1;
|
298 |
-
const lg=new THREE.BoxGeometry(ls, lh, ls);
|
299 |
-
const lofW=tw/2-ls*1.5;
|
300 |
-
const lofD=td/2-ls*1.5;
|
301 |
-
group.add(createMesh(lg, woodMaterial, { x:-lofW, y:lh/2, z:-lofD }));
|
302 |
-
group.add(createMesh(lg.clone(), woodMaterial, { x:lofW, y:lh/2, z:-lofD }));
|
303 |
-
group.add(createMesh(lg.clone(), woodMaterial, { x:-lofW, y:lh/2, z:lofD }));
|
304 |
-
group.add(createMesh(lg.clone(), woodMaterial, { x:lofW, y:lh/2, z:lofD }));
|
305 |
-
const ss=0.4;
|
306 |
-
const sg=new THREE.BoxGeometry(ss, ss*0.8, ss);
|
307 |
-
group.add(createMesh(sg, darkWoodMaterial, { x:-tw*0.6, y:ss*0.4, z:0 }));
|
308 |
-
group.add(createMesh(sg.clone(), darkWoodMaterial, { x:tw*0.6, y:ss*0.4, z:0 }));
|
309 |
-
group.add(createGroundPlane(stoneMaterial));
|
310 |
-
return group;
|
311 |
-
}
|
312 |
-
|
313 |
-
function createForestAssembly(tc=10, a=10) {
|
314 |
-
const group = new THREE.Group();
|
315 |
-
const cT=(x,z)=>{
|
316 |
-
const tg=new THREE.Group();
|
317 |
-
const th=Math.random()*1.5+2;
|
318 |
-
const tr=Math.random()*0.1+0.1;
|
319 |
-
const tGeo = new THREE.CylinderGeometry(tr*0.7, tr, th, 8);
|
320 |
-
tg.add(createMesh(tGeo, woodMaterial, {x:0, y:th/2, z:0}));
|
321 |
-
const fr=th*0.4+0.2;
|
322 |
-
const fGeo=new THREE.SphereGeometry(fr, 8, 6);
|
323 |
-
tg.add(createMesh(fGeo, leafMaterial, {x:0, y:th*0.9, z:0}));
|
324 |
-
tg.position.set(x,0,z);
|
325 |
-
return tg;
|
326 |
-
};
|
327 |
-
for(let i=0; i<tc; i++){
|
328 |
-
const x=(Math.random()-0.5)*a;
|
329 |
-
const z=(Math.random()-0.5)*a;
|
330 |
-
if(Math.sqrt(x*x+z*z)>1.0) group.add(cT(x,z));
|
331 |
-
}
|
332 |
-
group.add(createGroundPlane(groundMaterial, a*1.1));
|
333 |
-
return group;
|
334 |
-
}
|
335 |
-
|
336 |
-
function createRoadAmbushAssembly() {
|
337 |
-
const group = new THREE.Group();
|
338 |
-
const a=12;
|
339 |
-
const fg = createForestAssembly(8, a);
|
340 |
-
group.add(fg);
|
341 |
-
const rw=3, rl=a*1.2;
|
342 |
-
const rGeo=new THREE.PlaneGeometry(rw, rl);
|
343 |
-
const rMat=new THREE.MeshStandardMaterial({color:0x966F33, roughness:0.9});
|
344 |
-
const r=createMesh(rGeo, rMat, {x:0, y:0.01, z:0}, {x:-Math.PI/2});
|
345 |
-
r.receiveShadow=true;
|
346 |
-
group.add(r);
|
347 |
-
const rkGeo=new THREE.SphereGeometry(0.5, 5, 4);
|
348 |
-
const rkMat=new THREE.MeshStandardMaterial({color:0x666666, roughness:0.8});
|
349 |
-
group.add(createMesh(rkGeo, rkMat, {x:rw*0.7, y:0.25, z:1}, {y:Math.random()*Math.PI}));
|
350 |
-
group.add(createMesh(rkGeo.clone().scale(0.8,0.8,0.8), rkMat, {x:-rw*0.8, y:0.2, z:-2}, {y:Math.random()*Math.PI}));
|
351 |
-
return group;
|
352 |
-
}
|
353 |
-
|
354 |
-
function createForestEdgeAssembly() {
|
355 |
-
const group = new THREE.Group();
|
356 |
-
const a=15;
|
357 |
-
const fg = createForestAssembly(15, a);
|
358 |
-
const ttr=[];
|
359 |
-
fg.children.forEach(c => {
|
360 |
-
if(c.type === 'Group' && c.position.x > 0) ttr.push(c);
|
361 |
-
});
|
362 |
-
ttr.forEach(t => fg.remove(t));
|
363 |
-
group.add(fg);
|
364 |
-
return group;
|
365 |
-
}
|
366 |
-
|
367 |
-
function createPrisonerCellAssembly() {
|
368 |
-
const group = new THREE.Group();
|
369 |
-
const cs=3, wh=2.5, wt=0.2, br=0.05, bsp=0.25;
|
370 |
-
const cfMat=stoneMaterial.clone();
|
371 |
-
cfMat.color.setHex(0x555555);
|
372 |
-
group.add(createGroundPlane(cfMat, cs));
|
373 |
-
const wbGeo=new THREE.BoxGeometry(cs, wh, wt);
|
374 |
-
group.add(createMesh(wbGeo, stoneMaterial, {x:0, y:wh/2, z:-cs/2}));
|
375 |
-
const wsGeo=new THREE.BoxGeometry(wt, wh, cs);
|
376 |
-
group.add(createMesh(wsGeo, stoneMaterial, {x:-cs/2, y:wh/2, z:0}));
|
377 |
-
group.add(createMesh(wsGeo.clone(), stoneMaterial, {x:cs/2, y:wh/2, z:0}));
|
378 |
-
const bGeo=new THREE.CylinderGeometry(br, br, wh, 8);
|
379 |
-
const nb=Math.floor(cs/bsp);
|
380 |
-
for(let i=0; i<nb; i++){
|
381 |
-
const xp=-cs/2+(i+0.5)*bsp;
|
382 |
-
group.add(createMesh(bGeo.clone(), metalMaterial, {x:xp, y:wh/2, z:cs/2}));
|
383 |
-
}
|
384 |
-
return group;
|
385 |
-
}
|
386 |
-
|
387 |
-
function createGameOverAssembly() {
|
388 |
-
const group = new THREE.Group();
|
389 |
-
const boxGeo = new THREE.BoxGeometry(2, 2, 2);
|
390 |
-
group.add(createMesh(boxGeo, gameOverMaterial, { x: 0, y: 1, z: 0 }));
|
391 |
-
group.add(createGroundPlane(stoneMaterial.clone().set({color: 0x333333})));
|
392 |
-
return group;
|
393 |
-
}
|
394 |
-
|
395 |
-
function createErrorAssembly() {
|
396 |
-
const group = new THREE.Group();
|
397 |
-
const coneGeo = new THREE.ConeGeometry(0.8, 1.5, 8);
|
398 |
-
group.add(createMesh(coneGeo, errorMaterial, { x: 0, y: 0.75, z: 0 }));
|
399 |
-
group.add(createGroundPlane());
|
400 |
-
return group;
|
401 |
-
}
|
402 |
-
|
403 |
-
function createCrossroadsAssembly() {
|
404 |
-
const group = new THREE.Group();
|
405 |
-
group.add(createGroundPlane(dirtMaterial, 30));
|
406 |
-
const poleGeo = new THREE.CylinderGeometry(0.1, 0.1, 3, 8);
|
407 |
-
group.add(createMesh(poleGeo, woodMaterial, { y: 1.5 }));
|
408 |
-
const signGeo = new THREE.BoxGeometry(1.5, 0.3, 0.05);
|
409 |
-
group.add(createMesh(signGeo, woodMaterial, { y: 2.5, z: 0.2 }, { y: Math.PI / 4 }));
|
410 |
-
group.add(createMesh(signGeo, woodMaterial, { y: 2.5, z: -0.2 }, { y: -Math.PI / 4 }));
|
411 |
-
const grassGeo = new THREE.ConeGeometry(0.2, 0.5, 6);
|
412 |
-
for (let i = 0; i < 20; i++) {
|
413 |
-
const x = (Math.random() - 0.5) * 15;
|
414 |
-
const z = (Math.random() - 0.5) * 15;
|
415 |
-
if (Math.abs(x) > 2 || Math.abs(z) > 2) {
|
416 |
-
group.add(createMesh(grassGeo, grassMaterial, { x, y: 0.25, z }, { y: Math.random() * Math.PI }));
|
417 |
-
}
|
418 |
-
}
|
419 |
-
const rockGeo = new THREE.SphereGeometry(0.3, 6, 6);
|
420 |
-
for (let i = 0; i < 10; i++) {
|
421 |
-
group.add(createMesh(rockGeo, stoneMaterial, { x: (Math.random() - 0.5) * 10, y: 0.15, z: (Math.random() - 0.5) * 10 }, { y: Math.random() * Math.PI }));
|
422 |
-
}
|
423 |
-
return group;
|
424 |
-
}
|
425 |
-
|
426 |
-
function createRollingHillsAssembly() {
|
427 |
-
const group = new THREE.Group();
|
428 |
-
const hillGeo = new THREE.PlaneGeometry(50, 50, 10, 10);
|
429 |
-
const hillMat = grassMaterial.clone();
|
430 |
-
const hill = new THREE.Mesh(hillGeo, hillMat);
|
431 |
-
hill.rotation.x = -Math.PI / 2;
|
432 |
-
hill.receiveShadow = true;
|
433 |
-
for (let i = 0; i < hillGeo.attributes.position.count; i++) {
|
434 |
-
const x = hillGeo.attributes.position.getX(i);
|
435 |
-
const z = hillGeo.attributes.position.getZ(i);
|
436 |
-
hillGeo.attributes.position.setY(i, Math.sin(x * 0.2 + z * 0.2) * 2);
|
437 |
-
}
|
438 |
-
hillGeo.computeVertexNormals();
|
439 |
-
group.add(hill);
|
440 |
-
const shepherdGeo = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
|
441 |
-
group.add(createMesh(shepherdGeo, darkWoodMaterial, { x: 10, y: 2, z: -15 }));
|
442 |
-
const grassGeo = new THREE.ConeGeometry(0.3, 0.7, 6);
|
443 |
-
for (let i = 0; i < 50; i++) {
|
444 |
-
group.add(createMesh(grassGeo, grassMaterial, { x: (Math.random() - 0.5) * 40, y: 0.35, z: (Math.random() - 0.5) * 40 }, { y: Math.random() * Math.PI }));
|
445 |
-
}
|
446 |
-
return group;
|
447 |
-
}
|
448 |
-
|
449 |
-
function createCoastalCliffsAssembly() {
|
450 |
-
const group = new THREE.Group();
|
451 |
-
const cliffGeo = new THREE.BoxGeometry(10, 5, 10);
|
452 |
-
group.add(createMesh(cliffGeo, stoneMaterial, { y: 2.5 }));
|
453 |
-
const pathGeo = new THREE.PlaneGeometry(1, 10);
|
454 |
-
const path = createMesh(pathGeo, dirtMaterial, { x: -2, y: 2, z: 0 }, { x: -Math.PI / 2, z: -Math.PI / 4 });
|
455 |
-
group.add(path);
|
456 |
-
const oceanGeo = new THREE.PlaneGeometry(100, 100);
|
457 |
-
const ocean = createMesh(oceanGeo, oceanMaterial, { y: -2 }, { x: -Math.PI / 2 });
|
458 |
-
ocean.receiveShadow = false;
|
459 |
-
ocean.userData.update = (time) => {
|
460 |
-
ocean.position.y = -2 + Math.sin(time * 0.5) * 0.1;
|
461 |
-
};
|
462 |
-
group.add(ocean);
|
463 |
-
return group;
|
464 |
-
}
|
465 |
-
|
466 |
-
function createForestEntranceAssembly() {
|
467 |
-
const group = createForestAssembly(20, 12);
|
468 |
-
const rootGeo = new THREE.TorusGeometry(0.5, 0.1, 8, 16);
|
469 |
-
for (let i = 0; i < 10; i++) {
|
470 |
-
group.add(createMesh(rootGeo, woodMaterial, { x: (Math.random() - 0.5) * 8, y: 0.1, z: (Math.random() - 0.5) * 8 }, { x: Math.PI / 2 }));
|
471 |
-
}
|
472 |
-
return group;
|
473 |
-
}
|
474 |
-
|
475 |
-
function createOvergrownPathAssembly() {
|
476 |
-
const group = new THREE.Group();
|
477 |
-
group.add(createGroundPlane(dirtMaterial, 15));
|
478 |
-
const forest = createForestAssembly(15, 10);
|
479 |
-
group.add(forest);
|
480 |
-
const fungiGeo = new THREE.SphereGeometry(0.1, 8, 8);
|
481 |
-
for (let i = 0; i < 30; i++) {
|
482 |
-
group.add(createMesh(fungiGeo, glowMaterial, { x: (Math.random() - 0.5) * 8, y: 0.1, z: (Math.random() - 0.5) * 8 }));
|
483 |
-
}
|
484 |
-
const vineGeo = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
|
485 |
-
for (let i = 0; i < 10; i++) {
|
486 |
-
group.add(createMesh(vineGeo, leafMaterial, { x: (Math.random() - 0.5) * 6, y: 2, z: (Math.random() - 0.5) * 6 }, { z: Math.random() * Math.PI }));
|
487 |
-
}
|
488 |
-
return group;
|
489 |
-
}
|
490 |
-
|
491 |
-
function createClearingStatueAssembly() {
|
492 |
-
const group = new THREE.Group();
|
493 |
-
group.add(createGroundPlane(grassMaterial, 10));
|
494 |
-
const statueGeo = new THREE.BoxGeometry(0.8, 2, 0.8);
|
495 |
-
group.add(createMesh(statueGeo, stoneMaterial, { y: 1 }));
|
496 |
-
const mossGeo = new THREE.SphereGeometry(0.2, 8, 8);
|
497 |
-
for (let i = 0; i < 10; i++) {
|
498 |
-
group.add(createMesh(mossGeo, grassMaterial, { x: (Math.random() - 0.5) * 0.8, y: 0.5 + Math.random(), z: (Math.random() - 0.5) * 0.8 }));
|
499 |
-
}
|
500 |
-
const leafGeo = new THREE.PlaneGeometry(0.1, 0.1);
|
501 |
-
for (let i = 0; i < 20; i++) {
|
502 |
-
group.add(createMesh(leafGeo, leafMaterial, { x: (Math.random() - 0.5) * 5, y: 0.05, z: (Math.random() - 0.5) * 5 }, { y: Math.random() * Math.PI }));
|
503 |
-
}
|
504 |
-
return group;
|
505 |
-
}
|
506 |
-
|
507 |
-
function createGoblinAmbushAssembly() {
|
508 |
-
const group = createOvergrownPathAssembly();
|
509 |
-
const bodyGeo = new THREE.CylinderGeometry(0.3, 0.3, 1, 8);
|
510 |
-
const headGeo = new THREE.SphereGeometry(0.2, 8, 8);
|
511 |
-
const goblinMat = new THREE.MeshStandardMaterial({ color: 0x556B2F });
|
512 |
-
for (let i = -1; i <= 1; i += 2) {
|
513 |
-
const goblin = new THREE.Group();
|
514 |
-
goblin.add(createMesh(bodyGeo, goblinMat, { y: 0.5 }));
|
515 |
-
goblin.add(createMesh(headGeo, goblinMat, { y: 1.2 }));
|
516 |
-
const spearGeo = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
|
517 |
-
goblin.add(createMesh(spearGeo, woodMaterial, { x: 0.3, y: 1, z: 0 }, { z: Math.PI / 4 }));
|
518 |
-
goblin.position.set(i * 2, 0, 2);
|
519 |
-
group.add(goblin);
|
520 |
-
}
|
521 |
-
return group;
|
522 |
-
}
|
523 |
-
|
524 |
-
function createHiddenCoveAssembly() {
|
525 |
-
const group = new THREE.Group();
|
526 |
-
group.add(createGroundPlane(sandMaterial, 15));
|
527 |
-
const caveGeo = new THREE.BoxGeometry(3, 2, 3);
|
528 |
-
group.add(createMesh(caveGeo, stoneMaterial, { z: -5, y: 1 }));
|
529 |
-
const rockGeo = new THREE.SphereGeometry(0.5, 6, 6);
|
530 |
-
for (let i = 0; i < 15; i++) {
|
531 |
-
group.add(createMesh(rockGeo, stoneMaterial, { x: (Math.random() - 0.5) * 10, y: 0.25, z: (Math.random() - 0.5) * 10 }));
|
532 |
-
}
|
533 |
-
const seaweedGeo = new THREE.ConeGeometry(0.2, 1, 6);
|
534 |
-
for (let i = 0; i < 10; i++) {
|
535 |
-
group.add(createMesh(seaweedGeo, leafMaterial, { x: (Math.random() - 0.5) * 8, y: 0.5, z: (Math.random() - 0.5) * 8 }));
|
536 |
-
}
|
537 |
-
return group;
|
538 |
-
}
|
539 |
-
|
540 |
-
function createDarkCaveAssembly() {
|
541 |
-
const group = new THREE.Group();
|
542 |
-
group.add(createGroundPlane(wetStoneMaterial, 10));
|
543 |
-
const wallGeo = new THREE.CylinderGeometry(3, 3, 5, 12, 1, true);
|
544 |
-
const wall = createMesh(wallGeo, stoneMaterial, { y: 2.5 }, { x: Math.PI / 2 });
|
545 |
-
wall.scale.set(1, 1, -1);
|
546 |
-
group.add(wall);
|
547 |
-
const dripGeo = new THREE.SphereGeometry(0.05, 8, 8);
|
548 |
-
for (let i = 0; i < 5; i++) {
|
549 |
-
const drip = createMesh(dripGeo, oceanMaterial, { x: (Math.random() - 0.5) * 2, y: 4, z: (Math.random() - 0.5) * 2 });
|
550 |
-
drip.userData.update = (time) => {
|
551 |
-
drip.position.y -= 0.1;
|
552 |
-
if (drip.position.y < 0) drip.position.y = 4;
|
553 |
-
};
|
554 |
-
group.add(drip);
|
555 |
-
}
|
556 |
-
return group;
|
557 |
-
}
|
558 |
-
|
559 |
-
// Game Data
|
560 |
-
const itemsData = {
|
561 |
-
"Flaming Sword":{type:"weapon", description:"A fiery blade"},
|
562 |
-
"Whispering Bow":{type:"weapon", description:"A silent bow"},
|
563 |
-
"Guardian Shield":{type:"armor", description:"A protective shield"},
|
564 |
-
"Healing Light Spell":{type:"spell", description:"Mends minor wounds"},
|
565 |
-
"Shield of Faith Spell":{type:"spell", description:"Temporary shield"},
|
566 |
-
"Binding Runes Scroll":{type:"spell", description:"Binds an enemy"},
|
567 |
-
"Secret Tunnel Map":{type:"quest", description:"Shows a hidden path"},
|
568 |
-
"Poison Daggers":{type:"weapon", description:"Daggers with poison"},
|
569 |
-
"Master Key":{type:"quest", description:"Unlocks many doors"},
|
570 |
-
"Crude Dagger":{type:"weapon", description:"A roughly made dagger."},
|
571 |
-
"Scout's Pouch":{type:"quest", description:"Contains odds and ends."}
|
572 |
-
};
|
573 |
-
|
574 |
-
const gameData = {
|
575 |
-
"1": { title: "The Crossroads", content: `<p>Dust swirls... Which path calls to you?</p>`, options: [ { text: "Enter the Shadowwood Forest (North)", next: 5 }, { text: "Head towards the Rolling Hills (East)", next: 2 }, { text: "Investigate the Coastal Cliffs (West)", next: 3 } ], illustration: "crossroads-signpost-sunny" },
|
576 |
-
"2": { title: "Rolling Hills", content: `<p>Verdant hills stretch before you... It feels peaceful...</p>`, options: [ { text: "Follow the narrow path", next: 4 }, { text: "Try to hail the distant shepherd (Charisma Check?)", next: 99 } ], illustration: "rolling-green-hills-shepherd-distance" },
|
577 |
-
"3": { title: "Coastal Cliffs Edge", content: `<p>You stand atop windswept cliffs... A precarious-looking path descends...</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 }, { text: "Scan the cliff face for easier routes (Wisdom Check)", check: { stat: 'wisdom', dc: 11, onFailure: 32 }, next: 33 } ], illustration: "windy-sea-cliffs-crashing-waves-path-down" },
|
578 |
-
"4": { title: "Hill Path Overlook", content: `<p>The path crests a hill... you see a small, overgrown shrine...</p>`, options: [ { text: "Investigate the overgrown shrine", next: 40 }, { text: "Continue towards the badlands", next: 41 } ], illustration: "hilltop-view-overgrown-shrine-wildflowers" },
|
579 |
-
"5": { title: "Shadowwood Entrance", content: `<p>Sunlight struggles to pierce the dense canopy... How do you proceed?</p>`, options: [ { text: "Follow the main, albeit overgrown, path", next: 6 }, { text: "Try to navigate through the lighter undergrowth", next: 7 }, { text: "Look for animal trails or signs of passage (Wisdom Check)", check: { stat: 'wisdom', dc: 10, onFailure: 6 }, next: 8 } ], illustration: "dark-forest-entrance-gnarled-roots-filtered-light" },
|
580 |
-
"6": { title: "Overgrown Forest Path", content: `<p>The path is barely visible... You hear a twig snap nearby!</p>`, options: [ { text: "Ready your weapon and investigate", next: 10 }, { text: "Attempt to hide quietly (Dexterity Check)", check: { stat: 'dexterity', dc: 11, onFailure: 10 }, next: 11 }, { text: "Call out cautiously", next: 10 } ], illustration: "overgrown-forest-path-glowing-fungi-vines" },
|
581 |
-
"7": { title: "Tangled Undergrowth", content: `<p>Pushing through ferns... You stumble upon a small clearing containing a moss-covered, weathered stone statue...</p>`, options: [ { text: "Examine the statue closely (Intelligence Check)", check: { stat: 'intelligence', dc: 13, onFailure: 71 }, next: 70 }, { text: "Ignore the statue and press on", next: 72 }, { text: "Leave a small offering (if possible)", next: 73 } ], illustration: "forest-clearing-mossy-statue-weathered-stone" },
|
582 |
-
"8": { title: "Hidden Game Trail", content: `<p>Your sharp eyes spot a faint trail... It leads towards a ravine spanned by a rickety rope bridge.</p><p>(+20 XP)</p>`, options: [ { text: "Risk crossing the rope bridge (Dexterity Check)", check: { stat: 'dexterity', dc: 10, onFailure: 81 }, next: 80 }, { text: "Search for another way across the ravine", next: 82 } ], illustration: "narrow-game-trail-forest-rope-bridge-ravine", reward: { xp: 20 } },
|
583 |
-
"10": { title: "Goblin Ambush!", content: `<p>Two scraggly goblins leap out, brandishing crude spears!</p>`, options: [ { text: "Fight the goblins!", next: 12 }, { text: "Attempt to dodge past them (Dexterity Check)", check: { stat: 'dexterity', dc: 13, onFailure: 10 }, next: 13 } ], illustration: "two-goblins-ambush-forest-path-spears" },
|
584 |
-
"11": { title: "Hidden Evasion", content: `<p>You melt into the shadows as the goblins blunder past.</p><p>(+30 XP)</p>`, options: [ { text: "Continue cautiously", next: 14 } ], illustration: "forest-shadows-hiding-goblins-walking-past", reward: { xp: 30 } },
|
585 |
-
"12": { title: "Ambush Victory!", content: `<p>You defeat the goblins! Found a Crude Dagger.</p><p>(+50 XP)</p>`, options: [ { text: "Press onward", next: 14 } ], illustration: "defeated-goblins-forest-path-loot", reward: { xp: 50, addItem: "Crude Dagger" } },
|
586 |
-
"13": { title: "Daring Escape", content: `<p>With surprising agility, you tumble past the goblins!</p><p>(+25 XP)</p>`, options: [ { text: "Keep running!", next: 14 } ], illustration: "blurred-motion-running-past-goblins-forest", reward: { xp: 25 } },
|
587 |
-
"14": { title: "Forest Stream Crossing", content: `<p>The path leads to a clear, shallow stream...</p>`, options: [ { text: "Wade across the stream", next: 16 }, { text: "Look for a drier crossing point (fallen log?)", next: 15 } ], illustration: "forest-stream-crossing-dappled-sunlight-stones" },
|
588 |
-
"15": { title: "Log Bridge", content: `<p>Further upstream, a large, mossy log spans the stream.</p>`, options: [ { text: "Cross carefully on the log (Dexterity Check)", check: { stat: 'dexterity', dc: 9, onFailure: 151 }, next: 16 }, { text: "Go back and wade instead", next: 14 } ], illustration: "mossy-log-bridge-over-forest-stream" },
|
589 |
-
"151": { title: "Splash!", content: `<p>You slip on the mossy log and tumble into the cold stream! You're soaked but unharmed.</p>`, options: [ { text: "Shake yourself off and continue", next: 16 } ], illustration: "character-splashing-into-stream-from-log" },
|
590 |
-
"16": { title: "Edge of the Woods", content: `<p>You emerge from the Shadowwood... Before you lie rocky foothills...</p>`, options: [ { text: "Begin the ascent into the foothills", next: 17 }, { text: "Scan the fortress from afar (Wisdom Check)", check: { stat: 'wisdom', dc: 14, onFailure: 17 }, next: 18 } ], illustration: "forest-edge-view-rocky-foothills-distant-mountain-fortress" },
|
591 |
-
"17": { title: "Rocky Foothills Path", content: `<p>The climb is arduous... The fortress looms larger now.</p>`, options: [ { text: "Continue the direct ascent", next: 19 }, { text: "Look for signs of a hidden trail (Wisdom Check)", check: { stat: 'wisdom', dc: 15, onFailure: 19 }, next: 20 } ], illustration: "climbing-rocky-foothills-path-fortress-closer" },
|
592 |
-
"18": { title: "Distant Observation", content: `<p>You notice what might be a less-guarded approach along the western ridge...</p><p>(+30 XP)</p>`, options: [ { text: "Take the main path into the foothills", next: 17 }, { text: "Attempt the western ridge approach", next: 21 } ], illustration: "zoomed-view-mountain-fortress-western-ridge", reward: { xp: 30 } },
|
593 |
-
"19": { title: "Blocked Pass", content: `<p>The main path is blocked by a recent rockslide!</p>`, options: [ { text: "Try to climb over (Strength Check)", check: { stat: 'strength', dc: 14, onFailure: 191 }, next: 190 }, { text: "Search for another way around", next: 192 } ], illustration: "rockslide-blocking-mountain-path-boulders" },
|
594 |
-
"20": { title: "Goat Trail", content: `<p>You discover a narrow trail barely wide enough for a mountain goat...</p><p>(+40 XP)</p>`, options: [ { text: "Follow the precarious goat trail", next: 22 } ], illustration: "narrow-goat-trail-mountainside-fortress-view", reward: { xp: 40 } },
|
595 |
-
"30": { title: "Hidden Cove", content: `<p>Your careful descent brings you to a secluded cove. A dark cave entrance is visible...</p><p>(+25 XP)</p>`, options: [ { text: "Explore the dark cave", next: 35 } ], illustration: "hidden-cove-beach-dark-cave-entrance", reward: { xp: 25 } },
|
596 |
-
"31": { title: "Tumbled Down", content: `<p>You lose your footing... landing hard on the sandy cove floor. You lose 5 HP. A dark cave entrance beckons.</p>`, options: [ { text: "Gingerly explore the dark cave", next: 35 } ], illustration: "character-fallen-at-bottom-of-cliff-path-cove", hpLoss: 5 },
|
597 |
-
"32": { title: "No Easier Path", content: `<p>You scan the cliffs intently but find no obviously easier routes.</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 } ], illustration: "scanning-sea-cliffs-no-other-paths-visible" },
|
598 |
-
"33": { title: "Smuggler's Steps?", content: `<p>Your keen eyes spot a series of barely visible handholds and steps carved into the rock...</p><p>(+15 XP)</p>`, options: [ { text: "Use the hidden steps (Easier Dex Check)", check: { stat: 'dexterity', dc: 8, onFailure: 31 }, next: 30 } ], illustration: "close-up-handholds-carved-in-cliff-face", reward: { xp: 15 } },
|
599 |
-
"35": { title: "Dark Cave", content: `<p>The cave smells of salt and decay. Water drips somewhere within.</p>`, options: [{ text: "Press deeper into the darkness", next: 99 } ], illustration: "dark-cave-entrance-dripping-water" },
|
600 |
-
"40": { title: "Overgrown Shrine", content: `<p>Wildflowers grow thick around a small stone shrine. It feels ancient and neglected.</p>`, options: [{ text: "Examine the carvings (Intelligence Check)", check:{stat:'intelligence', dc:11, onFailure: 401}, next: 400 } ], illustration: "overgrown-stone-shrine-wildflowers-close" },
|
601 |
-
"41": { title: "Rocky Badlands", content: `<p>The green hills give way to cracked earth and jagged rock formations under a harsh sun.</p>`, options: [{ text: "Scout ahead", next: 99 } ], illustration: "rocky-badlands-cracked-earth-harsh-sun" },
|
602 |
-
"190": { title: "Over the Rocks", content:"<p>With considerable effort, you manage to climb over the rockslide.</p><p>(+35 XP)</p>", options: [{text:"Continue up the path", next: 22}], illustration:"character-climbing-over-boulders", reward: {xp:35} },
|
603 |
-
"191": { title: "Climb Fails", content:"<p>The boulders are too unstable or sheer. You cannot climb them safely.</p>", options: [{text:"Search for another way around", next: 192}], illustration:"character-slipping-on-rockslide-boulders"},
|
604 |
-
"192": { title: "Detour Found", content:"<p>After some searching, you find a rough path leading around the rockslide, eventually rejoining the main trail.</p>", options: [{text:"Continue up the path", next: 22}], illustration:"rough-detour-path-around-rockslide"},
|
605 |
-
"21": { title: "Western Ridge", content:"<p>The ridge path is narrow and exposed, with strong winds threatening to push you off.</p>", options: [{text:"Proceed carefully (Dexterity Check)", check:{stat:'dexterity', dc: 14, onFailure: 211}, next: 22 } ], illustration:"narrow-windy-mountain-ridge-path" },
|
606 |
-
"22": { title: "Fortress Approach", content:"<p>You've navigated the treacherous paths and now stand near the outer walls of the dark fortress. Guards patrol the battlements.</p>", options: [{text:"Look for an unguarded entrance", next: 99}], illustration:"approaching-dark-fortress-walls-guards"},
|
607 |
-
"211": {title:"Lost Balance", content:"<p>A strong gust of wind catches you off guard, sending you tumbling down a steep slope! You lose 10 HP.</p>", options:[{text:"Climb back up and find another way", next: 17}], illustration:"character-falling-off-windy-ridge", hpLoss: 10},
|
608 |
-
"99": { title: "Game Over / To Be Continued...", content: "<p>Your adventure ends here (for now).</p>", options: [{ text: "Restart", next: 1 }], illustration: "game-over-generic", gameOver: true }
|
609 |
-
};
|
610 |
-
|
611 |
-
// Game State
|
612 |
-
let gameState = {
|
613 |
-
currentPageId: 1,
|
614 |
-
character: {
|
615 |
-
name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer",
|
616 |
-
level: 1, xp: 0, xpToNextLevel: 100,
|
617 |
-
stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 },
|
618 |
-
inventory: []
|
619 |
-
}
|
620 |
-
};
|
621 |
-
|
622 |
-
// Game Logic Functions
|
623 |
-
function startGame() {
|
624 |
-
const defaultChar = { name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer", level: 1, xp: 0, xpToNextLevel: 100, stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 }, inventory: [] };
|
625 |
-
gameState = { currentPageId: 1, character: { ...defaultChar } };
|
626 |
-
renderPage(gameState.currentPageId);
|
627 |
-
}
|
628 |
-
|
629 |
-
function handleChoiceClick(choiceData) {
|
630 |
-
const optionNextPageId = parseInt(choiceData.nextPage);
|
631 |
-
const itemToAdd = choiceData.addItem;
|
632 |
-
let nextPageId = optionNextPageId;
|
633 |
-
let rollResultMessage = "";
|
634 |
-
const check = choiceData.check;
|
635 |
-
|
636 |
-
if (isNaN(optionNextPageId) && !check) { console.error("Invalid choice data:", choiceData); return; }
|
637 |
-
|
638 |
-
if (check) {
|
639 |
-
const statValue = gameState.character.stats[check.stat] || 10;
|
640 |
-
const modifier = Math.floor((statValue - 10) / 2);
|
641 |
-
const roll = Math.floor(Math.random() * 20) + 1;
|
642 |
-
const totalResult = roll + modifier;
|
643 |
-
const dc = check.dc;
|
644 |
-
console.log(`Check: ${check.stat} (DC ${dc}) | Roll: ${roll} + Mod: ${modifier} = ${totalResult}`);
|
645 |
-
if (totalResult >= dc) {
|
646 |
-
nextPageId = optionNextPageId;
|
647 |
-
rollResultMessage = `<p class="roll-success"><em>Check Success! (${totalResult} vs DC ${dc})</em></p>`;
|
648 |
} else {
|
649 |
-
|
650 |
-
|
651 |
-
if (isNaN(nextPageId)) { console.error("Invalid onFailure ID:", check.onFailure); nextPageId = 99; }
|
652 |
-
}
|
653 |
-
}
|
654 |
-
|
655 |
-
if (itemToAdd && !gameState.character.inventory.includes(itemToAdd)) {
|
656 |
-
gameState.character.inventory.push(itemToAdd);
|
657 |
-
console.log("Added item:", itemToAdd);
|
658 |
-
}
|
659 |
-
|
660 |
-
gameState.currentPageId = nextPageId;
|
661 |
-
const nextPageData = gameData[nextPageId];
|
662 |
-
|
663 |
-
if (nextPageData) {
|
664 |
-
if (nextPageData.hpLoss) {
|
665 |
-
gameState.character.stats.hp -= nextPageData.hpLoss;
|
666 |
-
console.log(`Lost ${nextPageData.hpLoss} HP.`);
|
667 |
-
if (gameState.character.stats.hp <= 0) { gameState.character.stats.hp = 0; console.log("Player died!"); nextPageId = 99; }
|
668 |
-
}
|
669 |
-
if (nextPageData.reward) {
|
670 |
-
if (nextPageData.reward.xp) { gameState.character.xp += nextPageData.reward.xp; console.log(`Gained ${nextPageData.reward.xp} XP! Total: ${gameState.character.xp}`); }
|
671 |
-
if (nextPageData.reward.statIncrease) {
|
672 |
-
const stat = nextPageData.reward.statIncrease.stat;
|
673 |
-
const amount = nextPageData.reward.statIncrease.amount;
|
674 |
-
if (gameState.character.stats.hasOwnProperty(stat)) {
|
675 |
-
gameState.character.stats[stat] += amount;
|
676 |
-
console.log(`Stat ${stat} increased by ${amount}.`);
|
677 |
-
}
|
678 |
-
}
|
679 |
-
if(nextPageData.reward.addItem && !gameState.character.inventory.includes(nextPageData.reward.addItem)){
|
680 |
-
gameState.character.inventory.push(nextPageData.reward.addItem);
|
681 |
-
console.log(`Found item: ${nextPageData.reward.addItem}`);
|
682 |
-
}
|
683 |
}
|
684 |
-
|
685 |
-
gameState.character.stats.maxHp = 10 + (conModifier * gameState.character.level);
|
686 |
-
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp);
|
687 |
-
if (nextPageId === 99 && gameState.character.stats.hp <= 0) {
|
688 |
-
renderPageInternal(99, gameData[99], rollResultMessage);
|
689 |
-
return;
|
690 |
-
}
|
691 |
-
} else {
|
692 |
-
console.error(`Data for page ${nextPageId} not found!`);
|
693 |
-
renderPageInternal(99, gameData[99], "<p><em>Error: Next page data missing!</em></p>");
|
694 |
-
return;
|
695 |
}
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
}
|
717 |
-
if (requirementMet) {
|
718 |
-
const choiceData = { nextPage: option.next, addItem: option.addItem, check: option.check };
|
719 |
-
button.onclick = () => handleChoiceClick(choiceData);
|
720 |
-
} else {
|
721 |
-
button.classList.add('disabled');
|
722 |
-
}
|
723 |
-
choicesElement.appendChild(button);
|
724 |
});
|
725 |
-
}
|
726 |
-
|
727 |
-
button.classList.add('choice-button');
|
728 |
-
button.textContent = pageData.gameOver ? "Restart Adventure" : "The End";
|
729 |
-
button.onclick = () => handleChoiceClick({ nextPage: pageData.gameOver ? 1 : 99 });
|
730 |
-
choicesElement.appendChild(button);
|
731 |
-
if (!pageData.gameOver) choicesElement.insertAdjacentHTML('afterbegin', '<p><i>The path ends here.</i></p>');
|
732 |
-
}
|
733 |
-
updateScene(pageData.illustration || 'default');
|
734 |
-
}
|
735 |
-
|
736 |
-
function renderPage(pageId) { renderPageInternal(pageId, gameData[pageId]); }
|
737 |
-
|
738 |
-
function updateStatsDisplay() {
|
739 |
-
const char=gameState.character;
|
740 |
-
statsElement.innerHTML = `<strong>Stats:</strong> <span>Lvl: ${char.level}</span> <span>XP: ${char.xp}/${char.xpToNextLevel}</span> <span>HP: ${char.stats.hp}/${char.stats.maxHp}</span> <span>Str: ${char.stats.strength}</span> <span>Int: ${char.stats.intelligence}</span> <span>Wis: ${char.stats.wisdom}</span> <span>Dex: ${char.stats.dexterity}</span> <span>Con: ${char.stats.constitution}</span> <span>Cha: ${char.stats.charisma}</span>`;
|
741 |
}
|
742 |
|
743 |
-
function
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
const c=`item-${d.type||'unknown'}`;
|
751 |
-
h+=`<span class="${c}" title="${d.description}">${i}</span>`;
|
752 |
-
});
|
753 |
}
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
function updateScene(illustrationKey) {
|
758 |
-
if (currentAssemblyGroup) { scene.remove(currentAssemblyGroup); }
|
759 |
-
scene.fog = null;
|
760 |
-
scene.background = new THREE.Color(0x222222);
|
761 |
-
camera.position.set(0, 2.5, 7);
|
762 |
-
camera.lookAt(0, 0.5, 0);
|
763 |
-
|
764 |
-
let assemblyFunction;
|
765 |
-
switch (illustrationKey) {
|
766 |
-
case 'city-gates': assemblyFunction = createCityGatesAssembly; break;
|
767 |
-
case 'weaponsmith': assemblyFunction = createWeaponsmithAssembly; break;
|
768 |
-
case 'temple': assemblyFunction = createTempleAssembly; break;
|
769 |
-
case 'resistance-meeting': assemblyFunction = createResistanceMeetingAssembly; break;
|
770 |
-
case 'shadowwood-forest': assemblyFunction = createForestAssembly; break;
|
771 |
-
case 'road-ambush': assemblyFunction = createRoadAmbushAssembly; break;
|
772 |
-
case 'forest-edge': assemblyFunction = createForestEdgeAssembly; break;
|
773 |
-
case 'prisoner-cell': assemblyFunction = createPrisonerCellAssembly; break;
|
774 |
-
case 'game-over': case 'game-over-generic': assemblyFunction = createGameOverAssembly; break;
|
775 |
-
case 'error': assemblyFunction = createErrorAssembly; break;
|
776 |
-
case 'crossroads-signpost-sunny':
|
777 |
-
scene.fog = new THREE.Fog(0x87CEEB, 10, 30);
|
778 |
-
scene.background = new THREE.Color(0x87CEEB);
|
779 |
-
camera.position.set(0, 3, 10); camera.lookAt(0, 1, 0);
|
780 |
-
assemblyFunction = createCrossroadsAssembly; break;
|
781 |
-
case 'rolling-green-hills-shepherd-distance':
|
782 |
-
scene.fog = new THREE.Fog(0xA8E4A0, 15, 50);
|
783 |
-
camera.position.set(0, 5, 15); camera.lookAt(0, 2, -5);
|
784 |
-
assemblyFunction = createRollingHillsAssembly; break;
|
785 |
-
case 'windy-sea-cliffs-crashing-waves-path-down':
|
786 |
-
scene.fog = new THREE.Fog(0x6699CC, 10, 40);
|
787 |
-
scene.background = new THREE.Color(0x6699CC);
|
788 |
-
camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5);
|
789 |
-
assemblyFunction = createCoastalCliffsAssembly; break;
|
790 |
-
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
791 |
-
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
792 |
-
camera.position.set(0, 2, 8); camera.lookAt(0, 1, 0);
|
793 |
-
assemblyFunction = createForestEntranceAssembly; break;
|
794 |
-
case 'overgrown-forest-path-glowing-fungi-vines':
|
795 |
-
scene.fog = new THREE.Fog(0x1A2F2A, 3, 15);
|
796 |
-
camera.position.set(0, 1.5, 6); camera.lookAt(0, 0.5, 0);
|
797 |
-
assemblyFunction = createOvergrownPathAssembly; break;
|
798 |
-
case 'forest-clearing-mossy-statue-weathered-stone':
|
799 |
-
scene.fog = new THREE.Fog(0x2E4F3A, 5, 25);
|
800 |
-
camera.position.set(0, 2, 5); camera.lookAt(0, 1, 0);
|
801 |
-
assemblyFunction = createClearingStatueAssembly; break;
|
802 |
-
case 'two-goblins-ambush-forest-path-spears':
|
803 |
-
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
804 |
-
camera.position.set(0, 2, 7); camera.lookAt(0, 1, 0);
|
805 |
-
assemblyFunction = createGoblinAmbushAssembly; break;
|
806 |
-
case 'hidden-cove-beach-dark-cave-entrance':
|
807 |
-
scene.fog = new THREE.Fog(0x336699, 5, 30);
|
808 |
-
scene.background = new THREE.Color(0x336699);
|
809 |
-
camera.position.set(0, 2, 8); camera.lookAt(0, 1, -2);
|
810 |
-
assemblyFunction = createHiddenCoveAssembly; break;
|
811 |
-
case 'dark-cave-entrance-dripping-water':
|
812 |
-
scene.fog = new THREE.Fog(0x1A1A1A, 2, 10);
|
813 |
-
scene.background = new THREE.Color(0x1A1A1A);
|
814 |
-
camera.position.set(0, 1.5, 4); camera.lookAt(0, 1, 0);
|
815 |
-
assemblyFunction = createDarkCaveAssembly; break;
|
816 |
-
default:
|
817 |
-
console.warn(`Unknown illustration key: "${illustrationKey}". Using default.`);
|
818 |
-
assemblyFunction = createDefaultAssembly; break;
|
819 |
}
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
}
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
});
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
directionalLight = new THREE.DirectionalLight(0xFFF8E1, 1.5);
|
843 |
-
directionalLight.position.set(10, 15, 10);
|
844 |
break;
|
845 |
-
case '
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
directionalLight.position.set(5, 10, 5);
|
850 |
break;
|
851 |
-
case '
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
break;
|
856 |
default:
|
857 |
-
|
858 |
-
directionalLight = new THREE.DirectionalLight(0xffffff, 1.2);
|
859 |
-
directionalLight.position.set(8, 15, 10);
|
860 |
}
|
861 |
-
|
862 |
-
|
863 |
-
directionalLight.shadow.camera.near = 0.5;
|
864 |
-
directionalLight.shadow.camera.far = 50;
|
865 |
-
directionalLight.shadow.camera.left = -15;
|
866 |
-
directionalLight.shadow.camera.right = 15;
|
867 |
-
directionalLight.shadow.camera.top = 15;
|
868 |
-
directionalLight.shadow.camera.bottom = -15;
|
869 |
-
scene.add(directionalLight);
|
870 |
}
|
871 |
|
872 |
-
document.addEventListener('DOMContentLoaded',
|
873 |
-
|
874 |
-
|
875 |
-
initThreeJS();
|
876 |
-
startGame();
|
877 |
-
} catch (error) {
|
878 |
-
console.error("Init failed:", error);
|
879 |
-
storyTitleElement.textContent = "Error";
|
880 |
-
storyContentElement.innerHTML = `<p>Init Error. Check console.</p><pre>${error}</pre>`;
|
881 |
-
}
|
882 |
});
|
883 |
</script>
|
884 |
</body>
|
885 |
-
</html>
|
|
|
16 |
flex-direction: column;
|
17 |
height: 100vh;
|
18 |
}
|
19 |
+
#game-container { display: flex; flex-grow: 1; overflow: hidden; }
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
#scene-container {
|
21 |
+
flex-grow: 3; position: relative; border-right: 2px solid #555;
|
22 |
+
min-width: 200px; background-color: #1a1a1a; height: 100%; box-sizing: border-box;
|
|
|
|
|
|
|
|
|
|
|
23 |
}
|
|
|
24 |
#ui-container {
|
25 |
+
flex-grow: 2; padding: 20px; overflow-y: auto;
|
26 |
+
background-color: #333; min-width: 280px; height: 100%;
|
27 |
+
box-sizing: border-box; display: flex; flex-direction: column;
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
|
|
29 |
#scene-container canvas { display: block; }
|
|
|
30 |
#story-title {
|
31 |
+
color: #ffcc66; margin-top: 0; margin-bottom: 15px;
|
32 |
+
border-bottom: 1px solid #555; padding-bottom: 10px; font-size: 1.4em;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
+
#story-content { margin-bottom: 20px; line-height: 1.6; flex-grow: 1; }
|
35 |
#story-content p { margin-bottom: 1em; }
|
36 |
#story-content p:last-child { margin-bottom: 0; }
|
|
|
37 |
#stats-inventory-container {
|
38 |
+
margin-bottom: 20px; padding-bottom: 15px;
|
39 |
+
border-bottom: 1px solid #555; font-size: 0.9em;
|
|
|
|
|
40 |
}
|
41 |
#stats-display, #inventory-display {
|
42 |
+
margin-bottom: 10px; line-height: 1.8;
|
|
|
43 |
}
|
44 |
#stats-display span, #inventory-display span {
|
45 |
+
display: inline-block; background-color: #444;
|
46 |
+
padding: 3px 8px; border-radius: 15px;
|
47 |
+
margin-right: 8px; margin-bottom: 5px;
|
48 |
+
border: 1px solid #666; white-space: nowrap;
|
49 |
+
}
|
50 |
+
#stats-display strong, #inventory-display strong {
|
51 |
+
color: #aaa; margin-right: 5px;
|
|
|
52 |
}
|
|
|
53 |
#inventory-display em { color: #888; font-style: normal; }
|
|
|
54 |
#inventory-display .item-quest { background-color: #666030; border-color: #999048;}
|
55 |
#inventory-display .item-weapon { background-color: #663030; border-color: #994848;}
|
56 |
#inventory-display .item-armor { background-color: #306630; border-color: #489948;}
|
57 |
#inventory-display .item-spell { background-color: #303066; border-color: #484899;}
|
58 |
#inventory-display .item-unknown { background-color: #555; border-color: #777;}
|
|
|
59 |
#choices-container {
|
60 |
+
margin-top: auto; padding-top: 15px; border-top: 1px solid #555;
|
|
|
|
|
61 |
}
|
62 |
#choices-container h3 { margin-top: 0; margin-bottom: 10px; color: #aaa; }
|
63 |
#choices { display: flex; flex-direction: column; gap: 10px; }
|
|
|
64 |
.choice-button {
|
65 |
+
display: block; width: 100%; padding: 10px 12px;
|
66 |
background-color: #555; color: #eee; border: 1px solid #777;
|
67 |
border-radius: 5px; cursor: pointer; text-align: left;
|
68 |
font-family: 'Courier New', monospace; font-size: 1em;
|
69 |
transition: background-color 0.2s, border-color 0.2s;
|
70 |
box-sizing: border-box;
|
71 |
}
|
72 |
+
.choice-button:hover:not(:disabled) {
|
73 |
+
background-color: #d4a017; color: #222; border-color: #b8860b;
|
74 |
+
}
|
75 |
+
.choice-button:disabled {
|
76 |
+
background-color: #444; color: #888; cursor: not-allowed;
|
77 |
+
border-color: #666; opacity: 0.7;
|
78 |
+
}
|
79 |
+
.roll-success {
|
80 |
+
color: #7f7; border-left: 3px solid #4a4;
|
81 |
+
padding-left: 8px; margin-bottom: 1em; font-size: 0.9em;
|
82 |
+
}
|
83 |
+
.roll-failure {
|
84 |
+
color: #f77; border-left: 3px solid #a44;
|
85 |
+
padding-left: 8px; margin-bottom: 1em; font-size: 0.9em;
|
86 |
+
}
|
87 |
</style>
|
88 |
</head>
|
89 |
<body>
|
|
|
106 |
</div>
|
107 |
|
108 |
<script type="importmap">
|
109 |
+
{
|
110 |
+
"imports": {
|
111 |
+
"three": "https://unpkg.com/[email protected]/build/three.module.js",
|
112 |
+
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/",
|
113 |
+
"simplex-noise": "https://unpkg.com/[email protected]/simplex-noise.js"
|
114 |
}
|
115 |
+
}
|
116 |
</script>
|
117 |
|
118 |
<script type="module">
|
119 |
import * as THREE from 'three';
|
120 |
+
import SimplexNoise from 'simplex-noise';
|
121 |
|
122 |
const sceneContainer = document.getElementById('scene-container');
|
123 |
const storyTitleElement = document.getElementById('story-title');
|
|
|
126 |
const statsElement = document.getElementById('stats-display');
|
127 |
const inventoryElement = document.getElementById('inventory-display');
|
128 |
|
129 |
+
let scene, camera, renderer, currentAssemblyGroup = null;
|
|
|
130 |
|
|
|
131 |
const stoneMaterial = new THREE.MeshStandardMaterial({ color: 0x888888, roughness: 0.8, metalness: 0.1 });
|
132 |
+
const groundMaterial = new THREE.MeshStandardMaterial({ color: 0x556B2F, roughness: 0.9 });
|
|
|
|
|
|
|
|
|
133 |
const templeMaterial = new THREE.MeshStandardMaterial({ color: 0xA99B78, roughness: 0.7, metalness: 0.1 });
|
|
|
|
|
134 |
const dirtMaterial = new THREE.MeshStandardMaterial({ color: 0x8B5E3C, roughness: 0.9 });
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
function initThreeJS() {
|
|
|
137 |
scene = new THREE.Scene();
|
138 |
scene.background = new THREE.Color(0x222222);
|
139 |
+
const w = sceneContainer.clientWidth, h = sceneContainer.clientHeight;
|
140 |
+
camera = new THREE.PerspectiveCamera(75, w/h || 1, 0.1, 1000);
|
141 |
+
camera.position.set(0,2.5,7); camera.lookAt(0,0.5,0);
|
142 |
+
renderer = new THREE.WebGLRenderer({ antialias:true });
|
143 |
+
renderer.setSize(w||400, h||300);
|
|
|
|
|
144 |
renderer.shadowMap.enabled = true;
|
|
|
145 |
sceneContainer.appendChild(renderer.domElement);
|
146 |
+
scene.add(new THREE.AmbientLight(0xffffff, 0.5));
|
147 |
+
window.addEventListener('resize', onWindowResize);
|
|
|
|
|
148 |
animate();
|
149 |
}
|
150 |
|
151 |
function onWindowResize() {
|
152 |
+
const w = sceneContainer.clientWidth, h = sceneContainer.clientHeight;
|
153 |
+
camera.aspect = w/h; camera.updateProjectionMatrix();
|
154 |
+
renderer.setSize(w, h);
|
|
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
|
157 |
function animate() {
|
158 |
requestAnimationFrame(animate);
|
159 |
+
const t = performance.now()*0.001;
|
160 |
+
scene.traverse(o => o.userData.update && o.userData.update(t));
|
161 |
+
renderer.render(scene, camera);
|
162 |
+
}
|
163 |
+
|
164 |
+
function createMesh(geo, mat, pos={x:0,y:0,z:0}, rot={x:0,y:0,z:0}, scl={x:1,y:1,z:1}) {
|
165 |
+
const m = new THREE.Mesh(geo, mat);
|
166 |
+
m.position.set(pos.x,pos.y,pos.z);
|
167 |
+
m.rotation.set(rot.x,rot.y,rot.z);
|
168 |
+
m.scale.set(scl.x,scl.y,scl.z);
|
169 |
+
m.castShadow = m.receiveShadow = true;
|
170 |
+
return m;
|
171 |
+
}
|
172 |
+
|
173 |
+
function createProceduralTerrainAssembly({ size=80, segments=128, heightScale=8, seed=123 }) {
|
174 |
+
const noise = new SimplexNoise(seed);
|
175 |
+
const geo = new THREE.PlaneGeometry(size, size, segments, segments);
|
176 |
+
const pos = geo.attributes.position;
|
177 |
+
for (let i=0; i<pos.count; i++) {
|
178 |
+
const x=pos.getX(i), z=pos.getZ(i);
|
179 |
+
pos.setY(i, noise.noise2D(x/10,z/10)*heightScale);
|
180 |
}
|
181 |
+
geo.computeVertexNormals();
|
182 |
+
const mat = new THREE.MeshStandardMaterial({ color:0x556B2F, flatShading:true });
|
183 |
+
const mesh = new THREE.Mesh(geo, mat);
|
184 |
+
mesh.rotation.x = -Math.PI/2;
|
185 |
+
mesh.receiveShadow = true;
|
|
|
|
|
|
|
186 |
return mesh;
|
187 |
}
|
188 |
|
189 |
+
function generateDungeonGrid(cols, rows, minRoom=3) {
|
190 |
+
function split(r, d=0) {
|
191 |
+
if (d>3 || r.width<minRoom*2 || r.height<minRoom*2) return [r];
|
192 |
+
const horiz = r.width>r.height;
|
193 |
+
const max = (horiz?r.width:r.height)-minRoom;
|
194 |
+
const sc = Math.floor(Math.random()*(max-minRoom)+minRoom);
|
195 |
+
let a,b;
|
196 |
+
if(horiz){
|
197 |
+
a={x:r.x,y:r.y,width:sc,height:r.height};
|
198 |
+
b={x:r.x+sc,y:r.y,width:r.width-sc,height:r.height};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
} else {
|
200 |
+
a={x:r.x,y:r.y,width:r.width,height:sc};
|
201 |
+
b={x:r.x,y:r.y+sc,width:r.width,height:r.height-sc};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
}
|
203 |
+
return [...split(a,d+1),...split(b,d+1)];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
}
|
205 |
+
const regions = split({x:0,y:0,width:cols,height:rows});
|
206 |
+
const grid = Array.from({length:rows},()=>Array(cols).fill(1));
|
207 |
+
regions.forEach(r=>{
|
208 |
+
const w=Math.max(2,Math.floor(r.width*0.8)), h=Math.max(2,Math.floor(r.height*0.8));
|
209 |
+
const ox=r.x+Math.floor((r.width-w)/2), oy=r.y+Math.floor((r.height-h)/2);
|
210 |
+
for(let y=oy;y<oy+h;y++)for(let x=ox;x<ox+w;x++)grid[y][x]=0;
|
211 |
+
});
|
212 |
+
return grid;
|
213 |
+
}
|
214 |
+
|
215 |
+
function createDungeonAssembly({ cols=40, rows=30, cellSize=0.8 }) {
|
216 |
+
const grid = generateDungeonGrid(cols, rows);
|
217 |
+
const g = new THREE.Group();
|
218 |
+
const wallGeo = new THREE.BoxGeometry(cellSize,cellSize,cellSize);
|
219 |
+
const floorGeo = new THREE.PlaneGeometry(cellSize,cellSize);
|
220 |
+
grid.forEach((row,y)=>{
|
221 |
+
row.forEach((c,x)=>{
|
222 |
+
const px=(x-cols/2)*cellSize, pz=(y-rows/2)*cellSize;
|
223 |
+
if(c===1) g.add(createMesh(wallGeo,stoneMaterial,{x:px,y:0.5,z:pz}));
|
224 |
+
else g.add(createMesh(floorGeo,groundMaterial,{x:px,y:0,z:pz},{x:-Math.PI/2}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
});
|
226 |
+
});
|
227 |
+
return g;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
}
|
229 |
|
230 |
+
function createCityAssembly({ blocksX=6, blocksZ=6, blockSize=5, streetWidth=1 }) {
|
231 |
+
const g = new THREE.Group();
|
232 |
+
const buildingMat = templeMaterial.clone(), roadMat = dirtMaterial.clone();
|
233 |
+
const total = blocksX*blockSize+(blocksX+1)*streetWidth;
|
234 |
+
for(let i=0;i<=blocksX;i++){
|
235 |
+
g.add(createMesh(new THREE.PlaneGeometry(streetWidth,total),roadMat,
|
236 |
+
{x:-total/2+i*(blockSize+streetWidth),y:0.01,z:0},{x:-Math.PI/2}));
|
|
|
|
|
|
|
237 |
}
|
238 |
+
for(let j=0;j<=blocksZ;j++){
|
239 |
+
g.add(createMesh(new THREE.PlaneGeometry(total,streetWidth),roadMat,
|
240 |
+
{x:0,y:0.01,z:-total/2+j*(blockSize+streetWidth)},{x:-Math.PI/2}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
+
for(let i=0;i<blocksX;i++)for(let j=0;j<blocksZ;j++){
|
243 |
+
const w=Math.random()*(blockSize*0.6)+blockSize*0.2;
|
244 |
+
const d=Math.random()*(blockSize*0.6)+blockSize*0.2;
|
245 |
+
const h=Math.random()*5+2;
|
246 |
+
const bx=-total/2+streetWidth+i*(blockSize+streetWidth)+blockSize/2;
|
247 |
+
const bz=-total/2+streetWidth+j*(blockSize+streetWidth)+blockSize/2;
|
248 |
+
g.add(createMesh(new THREE.BoxGeometry(w,h,d),buildingMat,
|
249 |
+
{x:bx,y:h/2,z:bz}));
|
250 |
}
|
251 |
+
return g;
|
252 |
+
}
|
253 |
+
|
254 |
+
function updateScene(key) {
|
255 |
+
if (currentAssemblyGroup) scene.remove(currentAssemblyGroup);
|
256 |
+
scene.fog = null; scene.background.set(0x222222);
|
257 |
+
camera.position.set(0,2.5,7); camera.lookAt(0,0.5,0);
|
258 |
+
let fn = () => { const g=new THREE.Group(); g.add(createMesh(new THREE.SphereGeometry(0.5,16,16),stoneMaterial,{y:0.5})); return g; };
|
259 |
+
switch(key) {
|
260 |
+
case 'procedural-terrain':
|
261 |
+
fn = () => createProceduralTerrainAssembly({size:80,segments:128,heightScale:8,seed:123});
|
262 |
+
camera.position.set(0,10,20); camera.lookAt(0,0,0);
|
263 |
+
scene.background.set(0x444444);
|
|
|
|
|
264 |
break;
|
265 |
+
case 'dungeon-procedural':
|
266 |
+
fn = () => createDungeonAssembly({cols:40,rows:30,cellSize:0.8});
|
267 |
+
camera.position.set(0,20,20); camera.lookAt(0,0,0);
|
268 |
+
scene.background.set(0x111111);
|
|
|
269 |
break;
|
270 |
+
case 'city-procedural':
|
271 |
+
fn = () => createCityAssembly({blocksX:6,blocksZ:6,blockSize:5,streetWidth:1});
|
272 |
+
camera.position.set(0,20,20); camera.lookAt(0,0,0);
|
273 |
+
scene.background.set(0x333333);
|
274 |
break;
|
275 |
default:
|
276 |
+
break;
|
|
|
|
|
277 |
}
|
278 |
+
currentAssemblyGroup = fn();
|
279 |
+
scene.add(currentAssemblyGroup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
}
|
281 |
|
282 |
+
document.addEventListener('DOMContentLoaded',()=>{
|
283 |
+
initThreeJS();
|
284 |
+
updateScene('procedural-terrain');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
});
|
286 |
</script>
|
287 |
</body>
|
288 |
+
</html>
|