Spaces:
Running
Running
cutechicken
commited on
Update game.js
Browse files
game.js
CHANGED
@@ -577,59 +577,47 @@ class Game {
|
|
577 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
578 |
ground.rotation.x = -Math.PI / 2;
|
579 |
ground.receiveShadow = true;
|
580 |
-
|
581 |
-
// ๊ฒฉ์ ํจ๊ณผ๋ฅผ ์ํ ๋ผ์ธ ์ถ๊ฐ
|
582 |
-
const gridSize = 50; // ๊ฒฉ์ ํฌ๊ธฐ
|
583 |
-
const gridHelper = new THREE.GridHelper(MAP_SIZE, gridSize, 0x000000, 0x000000);
|
584 |
-
gridHelper.material.opacity = 0.1;
|
585 |
-
gridHelper.material.transparent = true;
|
586 |
-
gridHelper.position.y = 0.1; // ์ง๋ฉด๋ณด๋ค ์ฝ๊ฐ ์์ ๋ฐฐ์น
|
587 |
-
this.scene.add(gridHelper);
|
588 |
-
|
589 |
-
// ๋ฑ๊ณ ์ ํจ๊ณผ๋ฅผ ์ํ ์งํ ์ปจํฌ์ด
|
590 |
-
const contourLines = new THREE.LineSegments(
|
591 |
-
new THREE.EdgesGeometry(groundGeometry),
|
592 |
-
new THREE.LineBasicMaterial({
|
593 |
-
color: 0x000000,
|
594 |
-
opacity: 0.15,
|
595 |
-
transparent: true
|
596 |
-
})
|
597 |
-
);
|
598 |
-
contourLines.rotation.x = -Math.PI / 2;
|
599 |
-
contourLines.position.y = 0.1;
|
600 |
-
this.scene.add(contourLines);
|
601 |
|
602 |
-
//
|
603 |
const vertices = ground.geometry.attributes.position.array;
|
604 |
-
const heightScale = 15;
|
605 |
-
const baseFrequency = 0.008;
|
606 |
|
|
|
|
|
|
|
|
|
607 |
for (let i = 0; i < vertices.length; i += 3) {
|
608 |
const x = vertices[i];
|
609 |
const y = vertices[i + 1];
|
610 |
|
611 |
-
//
|
612 |
-
|
613 |
-
|
614 |
-
// ํฐ ์ธ๋ (๊ธฐ๋ณธ ์งํ)
|
615 |
-
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
616 |
-
|
617 |
-
// ์ค๊ฐ ํฌ๊ธฐ ์งํ
|
618 |
-
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
619 |
|
620 |
-
//
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
}
|
634 |
|
635 |
ground.geometry.attributes.position.needsUpdate = true;
|
@@ -637,6 +625,28 @@ class Game {
|
|
637 |
this.ground = ground;
|
638 |
this.scene.add(ground);
|
639 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|
641 |
await this.addDesertDecorations();
|
642 |
|
|
|
577 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
578 |
ground.rotation.x = -Math.PI / 2;
|
579 |
ground.receiveShadow = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
|
581 |
+
// ์งํ ๋์ด ์ค์
|
582 |
const vertices = ground.geometry.attributes.position.array;
|
583 |
+
const heightScale = 15;
|
584 |
+
const baseFrequency = 0.008;
|
585 |
|
586 |
+
// ํ์ง ์์ญ ์ ์
|
587 |
+
const flatlandRadius = MAP_SIZE * 0.3; // ํ์ง ์์ญ์ ๋ฐ๊ฒฝ
|
588 |
+
const transitionZone = MAP_SIZE * 0.1; // ํ์ง์ ์ธ๋ ์ฌ์ด์ ์ ํ ๊ตฌ์ญ
|
589 |
+
|
590 |
for (let i = 0; i < vertices.length; i += 3) {
|
591 |
const x = vertices[i];
|
592 |
const y = vertices[i + 1];
|
593 |
|
594 |
+
// ์ค์ฌ์ ์ผ๋ก๋ถํฐ์ ๊ฑฐ๋ฆฌ ๊ณ์ฐ
|
595 |
+
const distanceFromCenter = Math.sqrt(x * x + y * y);
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
|
597 |
+
// ํ์ง ์์ญ์ด๋ฉด ๋์ด๋ฅผ 0์ผ๋ก ์ค์
|
598 |
+
if (distanceFromCenter < flatlandRadius) {
|
599 |
+
vertices[i + 2] = 0;
|
600 |
+
}
|
601 |
+
// ์ ํ ๊ตฌ์ญ์ด๋ฉด ๋ถ๋๋ฝ๊ฒ ๋์ด ์ฆ๊ฐ
|
602 |
+
else if (distanceFromCenter < flatlandRadius + transitionZone) {
|
603 |
+
const transitionFactor = (distanceFromCenter - flatlandRadius) / transitionZone;
|
604 |
+
let height = 0;
|
605 |
+
|
606 |
+
// ์ธ๋ ๋์ด ๊ณ์ฐ
|
607 |
+
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
608 |
+
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
609 |
+
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
610 |
+
|
611 |
+
vertices[i + 2] = height * transitionFactor;
|
612 |
+
}
|
613 |
+
// ์ธ๋ ์์ญ
|
614 |
+
else {
|
615 |
+
let height = 0;
|
616 |
+
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
617 |
+
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
618 |
+
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
619 |
+
vertices[i + 2] = height;
|
620 |
+
}
|
621 |
}
|
622 |
|
623 |
ground.geometry.attributes.position.needsUpdate = true;
|
|
|
625 |
this.ground = ground;
|
626 |
this.scene.add(ground);
|
627 |
|
628 |
+
// ๋ฑ๊ณ ์ ํจ๊ณผ (์ธ๋ ์์ญ์๋ง ์ ์ฉ)
|
629 |
+
const contourMaterial = new THREE.LineBasicMaterial({
|
630 |
+
color: 0x000000,
|
631 |
+
opacity: 0.15,
|
632 |
+
transparent: true
|
633 |
+
});
|
634 |
+
|
635 |
+
const contourLines = new THREE.LineSegments(
|
636 |
+
new THREE.EdgesGeometry(groundGeometry),
|
637 |
+
contourMaterial
|
638 |
+
);
|
639 |
+
contourLines.rotation.x = -Math.PI / 2;
|
640 |
+
contourLines.position.y = 0.1;
|
641 |
+
this.scene.add(contourLines);
|
642 |
+
|
643 |
+
// ๊ฒฉ์ ํจ๊ณผ (ํ์ง ์์ญ์๋ง ์ ๏ฟฝ๏ฟฝ)
|
644 |
+
const gridHelper = new THREE.GridHelper(flatlandRadius * 2, 50, 0x000000, 0x000000);
|
645 |
+
gridHelper.material.opacity = 0.1;
|
646 |
+
gridHelper.material.transparent = true;
|
647 |
+
gridHelper.position.y = 0.1;
|
648 |
+
this.scene.add(gridHelper);
|
649 |
+
|
650 |
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|
651 |
await this.addDesertDecorations();
|
652 |
|