Spaces:
Running
Running
gini1
commited on
Commit
โข
5ccac0e
1
Parent(s):
a6d36b3
Update index.html
Browse files- index.html +98 -105
index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33 |
z-index: 100;
|
34 |
border-radius: 5px;
|
35 |
}
|
36 |
-
#
|
37 |
position: absolute;
|
38 |
top: 50%;
|
39 |
left: 50%;
|
@@ -54,11 +54,11 @@
|
|
54 |
Click to start<br>
|
55 |
WASD - Move<br>
|
56 |
Mouse - Look around<br>
|
57 |
-
Find
|
58 |
Avoid the enemies!
|
59 |
</div>
|
60 |
<div id="timer">Safe Time: 10s</div>
|
61 |
-
<div id="
|
62 |
|
63 |
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
|
64 |
|
@@ -78,7 +78,7 @@
|
|
78 |
|
79 |
// ๊ธฐ๋ณธ ๋ณ์
|
80 |
let scene, camera, renderer, controls;
|
81 |
-
let
|
82 |
let isGameOver = false;
|
83 |
let isSafePeriod = true;
|
84 |
let startTime = 0;
|
@@ -96,19 +96,24 @@
|
|
96 |
renderer = new THREE.WebGLRenderer({ antialias: true });
|
97 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
98 |
renderer.shadowMap.enabled = true;
|
|
|
99 |
document.body.appendChild(renderer.domElement);
|
100 |
|
101 |
// ์กฐ๋ช
|
102 |
-
const ambientLight = new THREE.AmbientLight(0xffffff, 0
|
103 |
scene.add(ambientLight);
|
104 |
|
105 |
-
const dirLight = new THREE.DirectionalLight(0xffffff,
|
106 |
dirLight.position.set(50, 50, 0);
|
107 |
dirLight.castShadow = true;
|
108 |
dirLight.shadow.mapSize.width = 2048;
|
109 |
dirLight.shadow.mapSize.height = 2048;
|
110 |
dirLight.shadow.camera.far = 300;
|
111 |
scene.add(dirLight);
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
|
114 |
// ์งํ ์์ฑ
|
@@ -116,7 +121,8 @@
|
|
116 |
const geometry = new THREE.PlaneGeometry(300, 300, 50, 50);
|
117 |
const material = new THREE.MeshStandardMaterial({
|
118 |
color: 0x3a8c3a,
|
119 |
-
roughness: 0.
|
|
|
120 |
});
|
121 |
|
122 |
const vertices = geometry.attributes.position.array;
|
@@ -135,7 +141,11 @@
|
|
135 |
// ๋๋ฌด ์์ฑ
|
136 |
function createTrees() {
|
137 |
const treeGeo = new THREE.CylinderGeometry(0, 4, 15, 8);
|
138 |
-
const treeMat = new THREE.MeshStandardMaterial({
|
|
|
|
|
|
|
|
|
139 |
|
140 |
for (let i = 0; i < 100; i++) {
|
141 |
const tree = new THREE.Mesh(treeGeo, treeMat);
|
@@ -150,23 +160,33 @@
|
|
150 |
}
|
151 |
}
|
152 |
|
153 |
-
//
|
154 |
-
function
|
155 |
const loader = new GLTFLoader();
|
156 |
loader.load('me.glb', (gltf) => {
|
157 |
-
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
if (node.isMesh) {
|
|
|
|
|
161 |
node.castShadow = true;
|
|
|
162 |
}
|
163 |
});
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
170 |
});
|
171 |
}
|
172 |
|
@@ -184,13 +204,16 @@
|
|
184 |
const radius = 100;
|
185 |
enemy.position.set(
|
186 |
Math.cos(angle) * radius,
|
187 |
-
|
188 |
Math.sin(angle) * radius
|
189 |
);
|
190 |
|
191 |
enemy.traverse((node) => {
|
192 |
if (node.isMesh) {
|
|
|
|
|
193 |
node.castShadow = true;
|
|
|
194 |
}
|
195 |
});
|
196 |
|
@@ -198,42 +221,12 @@
|
|
198 |
enemies.push({
|
199 |
model: enemy,
|
200 |
speed: 0.2,
|
201 |
-
velocity: new THREE.Vector3()
|
|
|
202 |
});
|
203 |
}
|
204 |
console.log('Enemies loaded');
|
205 |
-
},
|
206 |
-
undefined,
|
207 |
-
(error) => {
|
208 |
-
console.error('Error loading enemy model:', error);
|
209 |
-
});
|
210 |
-
}
|
211 |
-
|
212 |
-
// ๋ฌด๊ธฐ ์์ฑ
|
213 |
-
function spawnWeapon() {
|
214 |
-
const geometry = new THREE.BoxGeometry(1, 1, 3);
|
215 |
-
const material = new THREE.MeshStandardMaterial({
|
216 |
-
color: 0xffd700,
|
217 |
-
metalness: 0.7,
|
218 |
-
roughness: 0.3,
|
219 |
-
emissive: 0xffd700,
|
220 |
-
emissiveIntensity: 0.5
|
221 |
});
|
222 |
-
|
223 |
-
weapon = new THREE.Mesh(geometry, material);
|
224 |
-
weapon.position.set(
|
225 |
-
(Math.random() - 0.5) * 200,
|
226 |
-
2,
|
227 |
-
(Math.random() - 0.5) * 200
|
228 |
-
);
|
229 |
-
weapon.castShadow = true;
|
230 |
-
scene.add(weapon);
|
231 |
-
|
232 |
-
// ๋ฌด๊ธฐ ์ถํ ์๋ฆผ
|
233 |
-
document.getElementById('weaponAlert').style.display = 'block';
|
234 |
-
setTimeout(() => {
|
235 |
-
document.getElementById('weaponAlert').style.display = 'none';
|
236 |
-
}, 3000);
|
237 |
}
|
238 |
|
239 |
// ์ปจํธ๋กค ์ด๊ธฐํ
|
@@ -268,7 +261,7 @@
|
|
268 |
document.addEventListener('click', () => {
|
269 |
if (!startTime) {
|
270 |
startTime = Date.now();
|
271 |
-
setTimeout(
|
272 |
}
|
273 |
controls.lock();
|
274 |
});
|
@@ -284,12 +277,52 @@
|
|
284 |
return moveState;
|
285 |
}
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
// ๊ฒ์ ์ด๊ธฐํ
|
288 |
function init() {
|
289 |
initScene();
|
290 |
createTerrain();
|
291 |
createTrees();
|
292 |
-
loadPlayer();
|
293 |
loadEnemies();
|
294 |
const moveState = initControls();
|
295 |
|
@@ -317,41 +350,13 @@
|
|
317 |
if (moveState.left) controls.moveRight(-speed);
|
318 |
if (moveState.right) controls.moveRight(speed);
|
319 |
|
320 |
-
// ํ๋ ์ด์ด ๋ชจ๋ธ ์
๋ฐ์ดํธ
|
321 |
-
if (playerModel) {
|
322 |
-
playerModel.position.copy(camera.position);
|
323 |
-
playerModel.position.y -= 2;
|
324 |
-
const direction = new THREE.Vector3();
|
325 |
-
camera.getWorldDirection(direction);
|
326 |
-
playerModel.rotation.y = Math.atan2(direction.x, direction.z);
|
327 |
-
}
|
328 |
-
|
329 |
// ์ ์
๋ฐ์ดํธ
|
330 |
-
|
331 |
-
enemies.forEach(enemy => {
|
332 |
-
const direction = new THREE.Vector3();
|
333 |
-
direction.subVectors(camera.position, enemy.model.position);
|
334 |
-
direction.y = 0;
|
335 |
-
direction.normalize();
|
336 |
-
|
337 |
-
enemy.velocity.add(direction.multiplyScalar(enemy.speed));
|
338 |
-
enemy.velocity.multiplyScalar(0.98);
|
339 |
-
enemy.model.position.add(enemy.velocity);
|
340 |
-
|
341 |
-
// ์ถฉ๋ ์ฒดํฌ
|
342 |
-
if (enemy.model.position.distanceTo(camera.position) < 3) {
|
343 |
-
gameOver(false);
|
344 |
-
}
|
345 |
-
|
346 |
-
// ์ ํ์
|
347 |
-
enemy.model.lookAt(camera.position);
|
348 |
-
});
|
349 |
-
}
|
350 |
|
351 |
-
//
|
352 |
-
if (
|
353 |
-
|
354 |
-
if (camera.position.distanceTo(
|
355 |
gameOver(true);
|
356 |
}
|
357 |
}
|
@@ -360,27 +365,15 @@
|
|
360 |
renderer.render(scene, camera);
|
361 |
}
|
362 |
|
363 |
-
// ์ฐฝ ํฌ๊ธฐ ์กฐ์ ์ฒ๋ฆฌ
|
364 |
-
window.addEventListener('resize', () => {
|
365 |
-
camera.aspect = window.innerWidth / window.innerHeight;
|
366 |
-
camera.updateProjectionMatrix();
|
367 |
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
368 |
-
});
|
369 |
-
|
370 |
animate();
|
371 |
}
|
372 |
|
373 |
-
//
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
alert(won ? 'You found the weapon and won!' : 'Game Over! You were caught!');
|
380 |
-
location.reload();
|
381 |
-
}, 100);
|
382 |
-
}
|
383 |
-
}
|
384 |
|
385 |
// ๊ฒ์ ์์
|
386 |
init();
|
|
|
33 |
z-index: 100;
|
34 |
border-radius: 5px;
|
35 |
}
|
36 |
+
#targetAlert {
|
37 |
position: absolute;
|
38 |
top: 50%;
|
39 |
left: 50%;
|
|
|
54 |
Click to start<br>
|
55 |
WASD - Move<br>
|
56 |
Mouse - Look around<br>
|
57 |
+
Find and touch your clone to win!<br>
|
58 |
Avoid the enemies!
|
59 |
</div>
|
60 |
<div id="timer">Safe Time: 10s</div>
|
61 |
+
<div id="targetAlert">Find and touch your clone to win!</div>
|
62 |
|
63 |
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
|
64 |
|
|
|
78 |
|
79 |
// ๊ธฐ๋ณธ ๋ณ์
|
80 |
let scene, camera, renderer, controls;
|
81 |
+
let enemies = [], target;
|
82 |
let isGameOver = false;
|
83 |
let isSafePeriod = true;
|
84 |
let startTime = 0;
|
|
|
96 |
renderer = new THREE.WebGLRenderer({ antialias: true });
|
97 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
98 |
renderer.shadowMap.enabled = true;
|
99 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
100 |
document.body.appendChild(renderer.domElement);
|
101 |
|
102 |
// ์กฐ๋ช
|
103 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
|
104 |
scene.add(ambientLight);
|
105 |
|
106 |
+
const dirLight = new THREE.DirectionalLight(0xffffff, 1.2);
|
107 |
dirLight.position.set(50, 50, 0);
|
108 |
dirLight.castShadow = true;
|
109 |
dirLight.shadow.mapSize.width = 2048;
|
110 |
dirLight.shadow.mapSize.height = 2048;
|
111 |
dirLight.shadow.camera.far = 300;
|
112 |
scene.add(dirLight);
|
113 |
+
|
114 |
+
// ๋ฐ์ฌ๊ด ์ถ๊ฐ
|
115 |
+
const hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.6);
|
116 |
+
scene.add(hemiLight);
|
117 |
}
|
118 |
|
119 |
// ์งํ ์์ฑ
|
|
|
121 |
const geometry = new THREE.PlaneGeometry(300, 300, 50, 50);
|
122 |
const material = new THREE.MeshStandardMaterial({
|
123 |
color: 0x3a8c3a,
|
124 |
+
roughness: 0.6,
|
125 |
+
metalness: 0.1
|
126 |
});
|
127 |
|
128 |
const vertices = geometry.attributes.position.array;
|
|
|
141 |
// ๋๋ฌด ์์ฑ
|
142 |
function createTrees() {
|
143 |
const treeGeo = new THREE.CylinderGeometry(0, 4, 15, 8);
|
144 |
+
const treeMat = new THREE.MeshStandardMaterial({
|
145 |
+
color: 0x0d5c0d,
|
146 |
+
roughness: 0.8,
|
147 |
+
metalness: 0.2
|
148 |
+
});
|
149 |
|
150 |
for (let i = 0; i < 100; i++) {
|
151 |
const tree = new THREE.Mesh(treeGeo, treeMat);
|
|
|
160 |
}
|
161 |
}
|
162 |
|
163 |
+
// ๋ชฉํ๋ฌผ(Clone) ์์ฑ
|
164 |
+
function spawnTarget() {
|
165 |
const loader = new GLTFLoader();
|
166 |
loader.load('me.glb', (gltf) => {
|
167 |
+
target = gltf.scene;
|
168 |
+
target.scale.set(0.5, 0.5, 0.5);
|
169 |
+
target.position.set(
|
170 |
+
(Math.random() - 0.5) * 200,
|
171 |
+
0,
|
172 |
+
(Math.random() - 0.5) * 200
|
173 |
+
);
|
174 |
+
|
175 |
+
target.traverse((node) => {
|
176 |
if (node.isMesh) {
|
177 |
+
node.material.metalness = 0.3;
|
178 |
+
node.material.roughness = 0.5;
|
179 |
node.castShadow = true;
|
180 |
+
node.receiveShadow = true;
|
181 |
}
|
182 |
});
|
183 |
+
|
184 |
+
scene.add(target);
|
185 |
+
|
186 |
+
document.getElementById('targetAlert').style.display = 'block';
|
187 |
+
setTimeout(() => {
|
188 |
+
document.getElementById('targetAlert').style.display = 'none';
|
189 |
+
}, 3000);
|
190 |
});
|
191 |
}
|
192 |
|
|
|
204 |
const radius = 100;
|
205 |
enemy.position.set(
|
206 |
Math.cos(angle) * radius,
|
207 |
+
0,
|
208 |
Math.sin(angle) * radius
|
209 |
);
|
210 |
|
211 |
enemy.traverse((node) => {
|
212 |
if (node.isMesh) {
|
213 |
+
node.material.metalness = 0.3;
|
214 |
+
node.material.roughness = 0.5;
|
215 |
node.castShadow = true;
|
216 |
+
node.receiveShadow = true;
|
217 |
}
|
218 |
});
|
219 |
|
|
|
221 |
enemies.push({
|
222 |
model: enemy,
|
223 |
speed: 0.2,
|
224 |
+
velocity: new THREE.Vector3(),
|
225 |
+
rotation: new THREE.Euler()
|
226 |
});
|
227 |
}
|
228 |
console.log('Enemies loaded');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
}
|
231 |
|
232 |
// ์ปจํธ๋กค ์ด๊ธฐํ
|
|
|
261 |
document.addEventListener('click', () => {
|
262 |
if (!startTime) {
|
263 |
startTime = Date.now();
|
264 |
+
setTimeout(spawnTarget, Math.random() * 5000 + 5000);
|
265 |
}
|
266 |
controls.lock();
|
267 |
});
|
|
|
277 |
return moveState;
|
278 |
}
|
279 |
|
280 |
+
// ์ ์
๋ฐ์ดํธ
|
281 |
+
function updateEnemies() {
|
282 |
+
if (!isSafePeriod) {
|
283 |
+
enemies.forEach(enemy => {
|
284 |
+
const direction = new THREE.Vector3();
|
285 |
+
direction.subVectors(camera.position, enemy.model.position);
|
286 |
+
direction.y = 0;
|
287 |
+
direction.normalize();
|
288 |
+
|
289 |
+
// ๋ถ๋๋ฌ์ด ์๋ ๋ณํ
|
290 |
+
enemy.velocity.lerp(direction.multiplyScalar(enemy.speed), 0.02);
|
291 |
+
enemy.model.position.add(enemy.velocity);
|
292 |
+
|
293 |
+
// ๋ถ๋๋ฌ์ด ํ์
|
294 |
+
const targetRotation = Math.atan2(direction.x, direction.z);
|
295 |
+
enemy.model.rotation.y = THREE.MathUtils.lerp(
|
296 |
+
enemy.model.rotation.y,
|
297 |
+
targetRotation,
|
298 |
+
0.05
|
299 |
+
);
|
300 |
+
|
301 |
+
// ์ถฉ๋ ์ฒดํฌ
|
302 |
+
if (enemy.model.position.distanceTo(camera.position) < 3) {
|
303 |
+
gameOver(false);
|
304 |
+
}
|
305 |
+
});
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
// ๊ฒ์ ์ค๋ฒ ์ฒ๋ฆฌ
|
310 |
+
function gameOver(won) {
|
311 |
+
if (!isGameOver) {
|
312 |
+
isGameOver = true;
|
313 |
+
controls.unlock();
|
314 |
+
setTimeout(() => {
|
315 |
+
alert(won ? 'You found your clone and won!' : 'Game Over! You were caught!');
|
316 |
+
location.reload();
|
317 |
+
}, 100);
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
// ๊ฒ์ ์ด๊ธฐํ
|
322 |
function init() {
|
323 |
initScene();
|
324 |
createTerrain();
|
325 |
createTrees();
|
|
|
326 |
loadEnemies();
|
327 |
const moveState = initControls();
|
328 |
|
|
|
350 |
if (moveState.left) controls.moveRight(-speed);
|
351 |
if (moveState.right) controls.moveRight(speed);
|
352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
// ์ ์
๋ฐ์ดํธ
|
354 |
+
updateEnemies();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
|
356 |
+
// ๋ชฉํ๋ฌผ ์ฒดํฌ
|
357 |
+
if (target) {
|
358 |
+
target.rotation.y += 0.01;
|
359 |
+
if (camera.position.distanceTo(target.position) < 3) {
|
360 |
gameOver(true);
|
361 |
}
|
362 |
}
|
|
|
365 |
renderer.render(scene, camera);
|
366 |
}
|
367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
animate();
|
369 |
}
|
370 |
|
371 |
+
// ํ๋ฉด ํฌ๊ธฐ ์กฐ์ ์ฒ๋ฆฌ
|
372 |
+
window.addEventListener('resize', () => {
|
373 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
374 |
+
camera.updateProjectionMatrix();
|
375 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
376 |
+
});
|
|
|
|
|
|
|
|
|
|
|
377 |
|
378 |
// ๊ฒ์ ์์
|
379 |
init();
|