Spaces:
Running
Running
cutechicken
commited on
Commit
โข
c29708a
1
Parent(s):
7aa0006
Update game.js
Browse files
game.js
CHANGED
@@ -327,14 +327,14 @@ class Game {
|
|
327 |
|
328 |
async initialize() {
|
329 |
try {
|
330 |
-
// ์๊ฐ ํจ๊ณผ
|
331 |
-
this.scene.fog = new THREE.Fog(
|
332 |
-
this.scene.background = new THREE.Color(
|
333 |
|
334 |
-
const ambientLight = new THREE.AmbientLight(0xffffff, 0.
|
335 |
this.scene.add(ambientLight);
|
336 |
|
337 |
-
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.
|
338 |
directionalLight.position.set(50, 50, 50);
|
339 |
directionalLight.castShadow = true;
|
340 |
directionalLight.shadow.mapSize.width = 2048;
|
@@ -342,33 +342,43 @@ class Game {
|
|
342 |
this.scene.add(directionalLight);
|
343 |
|
344 |
// ์ฌ๋ง ์งํ ์์ฑ
|
345 |
-
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE,
|
346 |
const groundTexture = new THREE.TextureLoader().load('/textures/sand.jpg');
|
347 |
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
|
348 |
groundTexture.repeat.set(50, 50);
|
349 |
|
|
|
350 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
351 |
map: groundTexture,
|
|
|
352 |
roughness: 1.0,
|
353 |
metalness: 0.0,
|
354 |
-
|
355 |
});
|
356 |
|
357 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
358 |
ground.rotation.x = -Math.PI / 2;
|
359 |
ground.receiveShadow = true;
|
360 |
|
361 |
-
// ์งํ์
|
362 |
const vertices = ground.geometry.attributes.position.array;
|
|
|
363 |
for (let i = 0; i < vertices.length; i += 3) {
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
}
|
366 |
ground.geometry.attributes.position.needsUpdate = true;
|
367 |
ground.geometry.computeVertexNormals();
|
368 |
|
369 |
this.scene.add(ground);
|
370 |
|
371 |
-
|
|
|
372 |
await this.tank.initialize(this.scene, this.loader);
|
373 |
|
374 |
if (!this.tank.isLoaded) {
|
@@ -396,6 +406,68 @@ class Game {
|
|
396 |
}
|
397 |
}
|
398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
setupEventListeners() {
|
400 |
document.addEventListener('keydown', (event) => {
|
401 |
if (this.isLoading || this.isGameOver) return;
|
|
|
327 |
|
328 |
async initialize() {
|
329 |
try {
|
330 |
+
// ์๊ฐ ํจ๊ณผ ์กฐ์
|
331 |
+
this.scene.fog = new THREE.Fog(0xC2B280, 1, 150); // ๋ ์์ฐ์ค๋ฌ์ด ์ฌ๋ง์
|
332 |
+
this.scene.background = new THREE.Color(0x87CEEB); // ํ๋์ ๋ฐฐ๊ฒฝ
|
333 |
|
334 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6); // ์ฃผ๋ณ๊ด ๊ฐ์
|
335 |
this.scene.add(ambientLight);
|
336 |
|
337 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.2); // ํ์๊ด ๊ฐํ
|
338 |
directionalLight.position.set(50, 50, 50);
|
339 |
directionalLight.castShadow = true;
|
340 |
directionalLight.shadow.mapSize.width = 2048;
|
|
|
342 |
this.scene.add(directionalLight);
|
343 |
|
344 |
// ์ฌ๋ง ์งํ ์์ฑ
|
345 |
+
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 200, 200);
|
346 |
const groundTexture = new THREE.TextureLoader().load('/textures/sand.jpg');
|
347 |
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
|
348 |
groundTexture.repeat.set(50, 50);
|
349 |
|
350 |
+
// ์ฌ๋ง ์ฌ์ง ๊ฐ์
|
351 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
352 |
map: groundTexture,
|
353 |
+
color: 0xD2B48C,
|
354 |
roughness: 1.0,
|
355 |
metalness: 0.0,
|
356 |
+
bumpScale: 0.5
|
357 |
});
|
358 |
|
359 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
360 |
ground.rotation.x = -Math.PI / 2;
|
361 |
ground.receiveShadow = true;
|
362 |
|
363 |
+
// ์ฌ๋ง ์งํ์ ๊ธฐ๋ณต ์ถ๊ฐ
|
364 |
const vertices = ground.geometry.attributes.position.array;
|
365 |
+
let seed = Math.random() * 100;
|
366 |
for (let i = 0; i < vertices.length; i += 3) {
|
367 |
+
// Perlin noise๋ฅผ ์ฌ์ฉํ ์์ฐ์ค๋ฌ์ด ๋๋ฎ์ด
|
368 |
+
const x = vertices[i] / 100;
|
369 |
+
const y = vertices[i + 1] / 100;
|
370 |
+
vertices[i + 2] =
|
371 |
+
(Math.sin(x + seed) * Math.cos(y + seed) * 2.0) + // ํฐ ์ธ๋
|
372 |
+
(Math.sin(x * 2 + seed) * Math.cos(y * 2 + seed) * 1.0) + // ์ค๊ฐ ํฌ๊ธฐ ์ธ๋
|
373 |
+
(Math.sin(x * 4 + seed) * Math.cos(y * 4 + seed) * 0.5); // ์์ ๋ชจ๋ ์ธ๋
|
374 |
}
|
375 |
ground.geometry.attributes.position.needsUpdate = true;
|
376 |
ground.geometry.computeVertexNormals();
|
377 |
|
378 |
this.scene.add(ground);
|
379 |
|
380 |
+
// ์ฌ๋ง ์ฅ์๋ฌผ ์ถ๊ฐ
|
381 |
+
await this.addDesertDecorations();
|
382 |
await this.tank.initialize(this.scene, this.loader);
|
383 |
|
384 |
if (!this.tank.isLoaded) {
|
|
|
406 |
}
|
407 |
}
|
408 |
|
409 |
+
// ์ฌ๋ง ์ฅ์๋ฌผ ์ถ๊ฐ ๋ฉ์๋
|
410 |
+
async addDesertDecorations() {
|
411 |
+
// ๋ฐ์ ์์ฑ
|
412 |
+
const rockGeometries = [
|
413 |
+
new THREE.DodecahedronGeometry(3),
|
414 |
+
new THREE.DodecahedronGeometry(2),
|
415 |
+
new THREE.DodecahedronGeometry(4)
|
416 |
+
];
|
417 |
+
|
418 |
+
const rockMaterial = new THREE.MeshStandardMaterial({
|
419 |
+
color: 0x8B4513,
|
420 |
+
roughness: 0.9,
|
421 |
+
metalness: 0.1
|
422 |
+
});
|
423 |
+
|
424 |
+
for (let i = 0; i < 100; i++) {
|
425 |
+
const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
|
426 |
+
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
|
427 |
+
|
428 |
+
rock.position.set(
|
429 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.9,
|
430 |
+
Math.random() * 2,
|
431 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.9
|
432 |
+
);
|
433 |
+
|
434 |
+
rock.rotation.set(
|
435 |
+
Math.random() * Math.PI,
|
436 |
+
Math.random() * Math.PI,
|
437 |
+
Math.random() * Math.PI
|
438 |
+
);
|
439 |
+
|
440 |
+
rock.scale.set(
|
441 |
+
1 + Math.random() * 0.5,
|
442 |
+
1 + Math.random() * 0.5,
|
443 |
+
1 + Math.random() * 0.5
|
444 |
+
);
|
445 |
+
|
446 |
+
rock.castShadow = true;
|
447 |
+
rock.receiveShadow = true;
|
448 |
+
this.scene.add(rock);
|
449 |
+
}
|
450 |
+
|
451 |
+
// ์ ์ธ์ฅ ์ถ๊ฐ (๊ฐ๋จํ geometry๋ก ํํ)
|
452 |
+
const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
|
453 |
+
const cactusMaterial = new THREE.MeshStandardMaterial({
|
454 |
+
color: 0x2F4F2F,
|
455 |
+
roughness: 0.8
|
456 |
+
});
|
457 |
+
|
458 |
+
for (let i = 0; i < 50; i++) {
|
459 |
+
const cactus = new THREE.Mesh(cactusGeometry, cactusMaterial);
|
460 |
+
cactus.position.set(
|
461 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.8,
|
462 |
+
2,
|
463 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.8
|
464 |
+
);
|
465 |
+
cactus.castShadow = true;
|
466 |
+
cactus.receiveShadow = true;
|
467 |
+
this.scene.add(cactus);
|
468 |
+
}
|
469 |
+
}
|
470 |
+
|
471 |
setupEventListeners() {
|
472 |
document.addEventListener('keydown', (event) => {
|
473 |
if (this.isLoading || this.isGameOver) return;
|