Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -519,33 +519,46 @@ class Game {
|
|
| 519 |
roughness: 0.8,
|
| 520 |
metalness: 0.2
|
| 521 |
});
|
| 522 |
-
|
| 523 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 524 |
ground.rotation.x = -Math.PI / 2;
|
| 525 |
ground.receiveShadow = true;
|
| 526 |
|
| 527 |
-
// ๋
|
| 528 |
const vertices = ground.geometry.attributes.position.array;
|
| 529 |
-
const heightScale =
|
| 530 |
-
const
|
| 531 |
|
| 532 |
for (let i = 0; i < vertices.length; i += 3) {
|
| 533 |
const x = vertices[i];
|
| 534 |
const y = vertices[i + 1];
|
| 535 |
-
// Perlin ๋
ธ์ด์ฆ์ ์ ์ฌํ ํจ๊ณผ๋ฅผ ๋ด๋ ์์ ๋ ์์
|
| 536 |
-
vertices[i + 2] =
|
| 537 |
-
(Math.sin(x * frequency) * Math.cos(y * frequency) * heightScale) +
|
| 538 |
-
(Math.sin(x * frequency * 2) * Math.cos(y * frequency * 2) * heightScale * 0.5);
|
| 539 |
|
| 540 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
|
| 542 |
-
const edgeFactor = Math.max(0, 1 - distanceFromCenter);
|
| 543 |
-
|
|
|
|
|
|
|
| 544 |
}
|
| 545 |
|
| 546 |
ground.geometry.attributes.position.needsUpdate = true;
|
| 547 |
ground.geometry.computeVertexNormals();
|
| 548 |
-
this.ground = ground;
|
| 549 |
this.scene.add(ground);
|
| 550 |
|
| 551 |
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|
|
|
|
| 519 |
roughness: 0.8,
|
| 520 |
metalness: 0.2
|
| 521 |
});
|
|
|
|
| 522 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 523 |
ground.rotation.x = -Math.PI / 2;
|
| 524 |
ground.receiveShadow = true;
|
| 525 |
|
| 526 |
+
// ๋ ๋ค์ํ ์งํ ์์ฑ
|
| 527 |
const vertices = ground.geometry.attributes.position.array;
|
| 528 |
+
const heightScale = 15; // ๋์ด ์ค์ผ์ผ
|
| 529 |
+
const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํ์
|
| 530 |
|
| 531 |
for (let i = 0; i < vertices.length; i += 3) {
|
| 532 |
const x = vertices[i];
|
| 533 |
const y = vertices[i + 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
+
// ์ฌ๋ฌ ์ฃผํ์๋ฅผ ์กฐํฉํ ์งํ ์์ฑ
|
| 536 |
+
let height = 0;
|
| 537 |
+
|
| 538 |
+
// ํฐ ์ธ๋ (๊ธฐ๋ณธ ์งํ)
|
| 539 |
+
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
| 540 |
+
|
| 541 |
+
// ์ค๊ฐ ํฌ๊ธฐ ์งํ
|
| 542 |
+
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
| 543 |
+
|
| 544 |
+
// ์์ ๊ตด๊ณก
|
| 545 |
+
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
| 546 |
+
|
| 547 |
+
// ๋๋ค ๋
ธ์ด์ฆ ์ถ๊ฐ (์์ฃผ ์์ ๊ตด๊ณก)
|
| 548 |
+
const noise = (Math.random() - 0.5) * heightScale * 0.1;
|
| 549 |
+
height += noise;
|
| 550 |
+
|
| 551 |
+
// ๋งต ๊ฐ์ฅ์๋ฆฌ๋ก ๊ฐ์๋ก ๋์ด๋ฅผ ๋ถ๋๋ฝ๊ฒ ๊ฐ์
|
| 552 |
const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
|
| 553 |
+
const edgeFactor = Math.pow(Math.max(0, 1 - distanceFromCenter), 2); // ๋ถ๋๋ฌ์ด ๊ฐ์
|
| 554 |
+
|
| 555 |
+
// ์ต์ข
๋์ด ์ค์
|
| 556 |
+
vertices[i + 2] = height * edgeFactor;
|
| 557 |
}
|
| 558 |
|
| 559 |
ground.geometry.attributes.position.needsUpdate = true;
|
| 560 |
ground.geometry.computeVertexNormals();
|
| 561 |
+
this.ground = ground;
|
| 562 |
this.scene.add(ground);
|
| 563 |
|
| 564 |
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|