Spaces:
Running
Running
cutechicken
commited on
Commit
โข
5da2c82
1
Parent(s):
6aab0c5
Update game.js
Browse files
game.js
CHANGED
@@ -1133,9 +1133,10 @@ class Game {
|
|
1133 |
if (!this.obstacles) {
|
1134 |
this.obstacles = []; // ๋ฐฐ์ด์ด ์์ผ๋ฉด ์ด๊ธฐํ
|
1135 |
}
|
|
|
|
|
1136 |
|
1137 |
-
// ๋ฐ์
|
1138 |
-
// ๋ฐ์ ์์ฑ
|
1139 |
const rockGeometries = [
|
1140 |
new THREE.DodecahedronGeometry(3),
|
1141 |
new THREE.DodecahedronGeometry(2),
|
@@ -1148,23 +1149,37 @@ class Game {
|
|
1148 |
metalness: 0.1
|
1149 |
});
|
1150 |
|
1151 |
-
//
|
1152 |
const collisionBoxMaterial = new THREE.MeshBasicMaterial({
|
1153 |
color: 0xff0000,
|
1154 |
wireframe: true,
|
1155 |
visible: false // ํ์์ true๋ก ๋ณ๊ฒฝํ์ฌ ์ถฉ๋ ๋ฐ์ค ํ์ธ
|
1156 |
});
|
1157 |
|
1158 |
-
for (let i = 0; i <
|
1159 |
const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
|
1160 |
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
|
1161 |
|
1162 |
-
// ๋ฐ์ ์์น ์ค์
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1168 |
|
1169 |
rock.rotation.set(
|
1170 |
Math.random() * Math.PI,
|
@@ -1172,11 +1187,9 @@ class Game {
|
|
1172 |
Math.random() * Math.PI
|
1173 |
);
|
1174 |
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
1 + Math.random() * 0.5
|
1179 |
-
);
|
1180 |
|
1181 |
// ์ถฉ๋ ๋ฐ์ค ์์ฑ ๋ฐ ์ค์
|
1182 |
const boundingBox = new THREE.Box3().setFromObject(rock);
|
@@ -1187,7 +1200,7 @@ class Game {
|
|
1187 |
collisionMesh.position.copy(rock.position);
|
1188 |
collisionMesh.rotation.copy(rock.rotation);
|
1189 |
|
1190 |
-
//
|
1191 |
rock.userData.isCollidable = true;
|
1192 |
rock.userData.type = 'rock';
|
1193 |
rock.userData.collisionMesh = collisionMesh;
|
@@ -1195,9 +1208,21 @@ class Game {
|
|
1195 |
rock.castShadow = true;
|
1196 |
rock.receiveShadow = true;
|
1197 |
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1201 |
}
|
1202 |
|
1203 |
// ์ ์ธ์ฅ ์ถ๊ฐ
|
|
|
1133 |
if (!this.obstacles) {
|
1134 |
this.obstacles = []; // ๋ฐฐ์ด์ด ์์ผ๋ฉด ์ด๊ธฐํ
|
1135 |
}
|
1136 |
+
// ๋ฐ์ ์์ฑ ๊ฐ์๋ฅผ 70๊ฐ๋ก ์ค์
|
1137 |
+
const ROCK_COUNT = 70;
|
1138 |
|
1139 |
+
// ๋ฐ์ ์ง์ค๋ฉํธ๋ฆฌ ์ ์
|
|
|
1140 |
const rockGeometries = [
|
1141 |
new THREE.DodecahedronGeometry(3),
|
1142 |
new THREE.DodecahedronGeometry(2),
|
|
|
1149 |
metalness: 0.1
|
1150 |
});
|
1151 |
|
1152 |
+
// ์ถฉ๋ ๋ฐ์ค ์๊ฐํ์ฉ ์ฌ์ง (๋๋ฒ๊น
์ฉ)
|
1153 |
const collisionBoxMaterial = new THREE.MeshBasicMaterial({
|
1154 |
color: 0xff0000,
|
1155 |
wireframe: true,
|
1156 |
visible: false // ํ์์ true๋ก ๋ณ๊ฒฝํ์ฌ ์ถฉ๋ ๋ฐ์ค ํ์ธ
|
1157 |
});
|
1158 |
|
1159 |
+
for (let i = 0; i < ROCK_COUNT; i++) {
|
1160 |
const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
|
1161 |
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
|
1162 |
|
1163 |
+
// ๋ฐ์ ์์น ์ค์ - ๋งต ๊ฐ์ฅ์๋ฆฌ์ ๋ ๋ง์ด ๋ฐฐ์น
|
1164 |
+
let x, z;
|
1165 |
+
const edgeSpawn = Math.random() < 0.7; // 70% ํ๋ฅ ๋ก ๊ฐ์ฅ์๋ฆฌ์ ์์ฑ
|
1166 |
+
|
1167 |
+
if (edgeSpawn) {
|
1168 |
+
// ๋งต ๊ฐ์ฅ์๋ฆฌ์ ์์ฑ
|
1169 |
+
if (Math.random() < 0.5) {
|
1170 |
+
x = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
|
1171 |
+
z = (Math.random() - 0.5) * MAP_SIZE * 0.9;
|
1172 |
+
} else {
|
1173 |
+
x = (Math.random() - 0.5) * MAP_SIZE * 0.9;
|
1174 |
+
z = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
|
1175 |
+
}
|
1176 |
+
} else {
|
1177 |
+
// ๋งต ์ค์ ์์ญ์ ์์ฑ
|
1178 |
+
x = (Math.random() - 0.5) * MAP_SIZE * 0.6;
|
1179 |
+
z = (Math.random() - 0.5) * MAP_SIZE * 0.6;
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
rock.position.set(x, Math.random() * 2, z);
|
1183 |
|
1184 |
rock.rotation.set(
|
1185 |
Math.random() * Math.PI,
|
|
|
1187 |
Math.random() * Math.PI
|
1188 |
);
|
1189 |
|
1190 |
+
// ๋ฐ์ ํฌ๊ธฐ๋ฅผ ์ข ๋ ๋ค์ํ๊ฒ ์ค์
|
1191 |
+
const scale = 1 + Math.random() * 1.5; // 1.0 ~ 2.5 ์ฌ์ด์ ํฌ๊ธฐ
|
1192 |
+
rock.scale.set(scale, scale, scale);
|
|
|
|
|
1193 |
|
1194 |
// ์ถฉ๋ ๋ฐ์ค ์์ฑ ๋ฐ ์ค์
|
1195 |
const boundingBox = new THREE.Box3().setFromObject(rock);
|
|
|
1200 |
collisionMesh.position.copy(rock.position);
|
1201 |
collisionMesh.rotation.copy(rock.rotation);
|
1202 |
|
1203 |
+
// ๋ชจ๋ ๋ฐ์๋ฅผ ์ถฉ๋ ๊ฐ๋ฅํ๊ฒ ์ค์
|
1204 |
rock.userData.isCollidable = true;
|
1205 |
rock.userData.type = 'rock';
|
1206 |
rock.userData.collisionMesh = collisionMesh;
|
|
|
1208 |
rock.castShadow = true;
|
1209 |
rock.receiveShadow = true;
|
1210 |
|
1211 |
+
// ๋ค๋ฅธ ๋ฐ์๋ค๊ณผ์ ๊ฑฐ๋ฆฌ ์ฒดํฌ
|
1212 |
+
let tooClose = false;
|
1213 |
+
for (const obstacle of this.obstacles) {
|
1214 |
+
const distance = rock.position.distanceTo(obstacle.position);
|
1215 |
+
if (distance < 15) { // ์ต์ ๊ฑฐ๋ฆฌ ์ค์
|
1216 |
+
tooClose = true;
|
1217 |
+
break;
|
1218 |
+
}
|
1219 |
+
}
|
1220 |
+
|
1221 |
+
if (!tooClose) {
|
1222 |
+
this.obstacles.push(rock);
|
1223 |
+
this.scene.add(rock);
|
1224 |
+
this.scene.add(collisionMesh);
|
1225 |
+
}
|
1226 |
}
|
1227 |
|
1228 |
// ์ ์ธ์ฅ ์ถ๊ฐ
|