Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -853,74 +853,29 @@ class Game {
|
|
| 853 |
this.scene.add(hemisphereLight);
|
| 854 |
|
| 855 |
// ์งํ ์์ฑ ์์
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
const flatlandRadius = MAP_SIZE * 0.3;
|
| 875 |
-
const transitionZone = MAP_SIZE * 0.1;
|
| 876 |
-
|
| 877 |
-
for (let i = 0; i < vertices.length; i += 3) {
|
| 878 |
-
const x = vertices[i];
|
| 879 |
-
const y = vertices[i + 1];
|
| 880 |
-
|
| 881 |
-
const distanceFromCenter = Math.sqrt(x * x + y * y);
|
| 882 |
-
|
| 883 |
-
if (distanceFromCenter < flatlandRadius) {
|
| 884 |
-
vertices[i + 2] = 0;
|
| 885 |
-
}
|
| 886 |
-
else if (distanceFromCenter < flatlandRadius + transitionZone) {
|
| 887 |
-
const transitionFactor = (distanceFromCenter - flatlandRadius) / transitionZone;
|
| 888 |
-
let height = 0;
|
| 889 |
-
|
| 890 |
-
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
| 891 |
-
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
| 892 |
-
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
| 893 |
-
|
| 894 |
-
vertices[i + 2] = height * transitionFactor;
|
| 895 |
-
}
|
| 896 |
-
else {
|
| 897 |
-
let height = 0;
|
| 898 |
-
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
| 899 |
-
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
| 900 |
-
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
| 901 |
-
vertices[i + 2] = height;
|
| 902 |
-
}
|
| 903 |
-
}
|
| 904 |
-
|
| 905 |
-
ground.geometry.attributes.position.needsUpdate = true;
|
| 906 |
-
ground.geometry.computeVertexNormals();
|
| 907 |
-
this.ground = ground;
|
| 908 |
-
this.scene.add(ground);
|
| 909 |
-
|
| 910 |
-
// ๋ฑ๊ณ ์ ํจ๊ณผ
|
| 911 |
-
const contourMaterial = new THREE.LineBasicMaterial({
|
| 912 |
-
color: 0x000000,
|
| 913 |
-
opacity: 0.15,
|
| 914 |
-
transparent: true
|
| 915 |
-
});
|
| 916 |
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
contourLines.rotation.x = -Math.PI / 2;
|
| 922 |
-
contourLines.position.y = 0.1;
|
| 923 |
-
this.scene.add(contourLines);
|
| 924 |
|
| 925 |
// ๊ฒฉ์ ํจ๊ณผ
|
| 926 |
const gridHelper = new THREE.GridHelper(flatlandRadius * 2, 50, 0x000000, 0x000000);
|
|
@@ -1097,44 +1052,8 @@ class Game {
|
|
| 1097 |
}
|
| 1098 |
|
| 1099 |
getHeightAtPosition(x, z) {
|
| 1100 |
-
|
| 1101 |
-
|
| 1102 |
-
// ์งํ์ ์ ์ ๋ฐ์ดํฐ
|
| 1103 |
-
const vertices = this.ground.geometry.attributes.position.array;
|
| 1104 |
-
const segmentsX = Math.sqrt(vertices.length / 3) - 1;
|
| 1105 |
-
const segmentsZ = segmentsX;
|
| 1106 |
-
|
| 1107 |
-
// ๋งต ์ขํ๋ฅผ ์งํ ๊ฒฉ์ ์ขํ๋ก ๋ณํ
|
| 1108 |
-
const gridX = ((x + MAP_SIZE / 2) / MAP_SIZE) * segmentsX;
|
| 1109 |
-
const gridZ = ((z + MAP_SIZE / 2) / MAP_SIZE) * segmentsZ;
|
| 1110 |
-
|
| 1111 |
-
// ๊ฐ์ฅ ๊ฐ๊น์ด ๊ฒฉ์์ ์ฐพ๊ธฐ
|
| 1112 |
-
const x1 = Math.floor(gridX);
|
| 1113 |
-
const z1 = Math.floor(gridZ);
|
| 1114 |
-
const x2 = Math.min(x1 + 1, segmentsX);
|
| 1115 |
-
const z2 = Math.min(z1 + 1, segmentsZ);
|
| 1116 |
-
|
| 1117 |
-
// ๊ฒฉ์์ ๋ค์ ๋์ด ๊ฐ์ ธ์ค๊ธฐ
|
| 1118 |
-
const getHeight = (x, z) => {
|
| 1119 |
-
if (x < 0 || x > segmentsX || z < 0 || z > segmentsZ) return 0;
|
| 1120 |
-
const index = (z * (segmentsX + 1) + x) * 3 + 2;
|
| 1121 |
-
return vertices[index];
|
| 1122 |
-
};
|
| 1123 |
-
|
| 1124 |
-
const h11 = getHeight(x1, z1);
|
| 1125 |
-
const h21 = getHeight(x2, z1);
|
| 1126 |
-
const h12 = getHeight(x1, z2);
|
| 1127 |
-
const h22 = getHeight(x2, z2);
|
| 1128 |
-
|
| 1129 |
-
// ๋ณด๊ฐ์ผ๋ก ์ ํํ ๋์ด ๊ณ์ฐ
|
| 1130 |
-
const fx = gridX - x1;
|
| 1131 |
-
const fz = gridZ - z1;
|
| 1132 |
-
|
| 1133 |
-
const h1 = h11 * (1 - fx) + h21 * fx;
|
| 1134 |
-
const h2 = h12 * (1 - fx) + h22 * fx;
|
| 1135 |
-
|
| 1136 |
-
return h1 * (1 - fz) + h2 * fz;
|
| 1137 |
-
}
|
| 1138 |
|
| 1139 |
findValidSpawnPosition() {
|
| 1140 |
const margin = 50;
|
|
|
|
| 853 |
this.scene.add(hemisphereLight);
|
| 854 |
|
| 855 |
// ์งํ ์์ฑ ์์
|
| 856 |
+
// ์งํ ์์ฑ ์์
|
| 857 |
+
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE);
|
| 858 |
+
const groundMaterial = new THREE.MeshStandardMaterial({
|
| 859 |
+
color: 0xD2B48C,
|
| 860 |
+
roughness: 0.8,
|
| 861 |
+
metalness: 0.2,
|
| 862 |
+
envMapIntensity: 1.0
|
| 863 |
+
});
|
| 864 |
+
|
| 865 |
+
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 866 |
+
ground.rotation.x = -Math.PI / 2;
|
| 867 |
+
ground.receiveShadow = true;
|
| 868 |
+
|
| 869 |
+
// ๋ชจ๋ ์ ์ ์ ๋์ด๋ฅผ 0์ผ๋ก ์ค์
|
| 870 |
+
const vertices = ground.geometry.attributes.position.array;
|
| 871 |
+
for (let i = 0; i < vertices.length; i += 3) {
|
| 872 |
+
vertices[i + 2] = 0;
|
| 873 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 874 |
|
| 875 |
+
ground.geometry.attributes.position.needsUpdate = true;
|
| 876 |
+
ground.geometry.computeVertexNormals();
|
| 877 |
+
this.ground = ground;
|
| 878 |
+
this.scene.add(ground);
|
|
|
|
|
|
|
|
|
|
| 879 |
|
| 880 |
// ๊ฒฉ์ ํจ๊ณผ
|
| 881 |
const gridHelper = new THREE.GridHelper(flatlandRadius * 2, 50, 0x000000, 0x000000);
|
|
|
|
| 1052 |
}
|
| 1053 |
|
| 1054 |
getHeightAtPosition(x, z) {
|
| 1055 |
+
return 0; // ํญ์ ๋์ด 0 ๋ฐํ
|
| 1056 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1057 |
|
| 1058 |
findValidSpawnPosition() {
|
| 1059 |
const margin = 50;
|