Spaces:
Running
Running
cutechicken
commited on
Commit
โข
cc6ae9c
1
Parent(s):
3374382
Update game.js
Browse files
game.js
CHANGED
@@ -1222,25 +1222,18 @@ class Game {
|
|
1222 |
this.lastRadarUpdate = currentTime;
|
1223 |
}
|
1224 |
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
// ๋ฐ์ ์์ฑ ๊ฐ์๋ฅผ 70๊ฐ๋ก ์ค์
|
1230 |
-
const ROCK_COUNT = 70;
|
1231 |
-
|
1232 |
-
// ๋ฐ์ ์ง์ค๋ฉํธ๋ฆฌ ์ ์
|
1233 |
-
const rockGeometries = [
|
1234 |
-
new THREE.DodecahedronGeometry(3),
|
1235 |
-
new THREE.DodecahedronGeometry(2),
|
1236 |
-
new THREE.DodecahedronGeometry(4)
|
1237 |
-
];
|
1238 |
|
1239 |
-
const
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
|
|
|
|
1244 |
|
1245 |
// ์ถฉ๋ ๋ฐ์ค ์๊ฐํ์ฉ ์ฌ์ง (๋๋ฒ๊น
์ฉ)
|
1246 |
const collisionBoxMaterial = new THREE.MeshBasicMaterial({
|
@@ -1249,76 +1242,83 @@ class Game {
|
|
1249 |
visible: false // ํ์์ true๋ก ๋ณ๊ฒฝํ์ฌ ์ถฉ๋ ๋ฐ์ค ํ์ธ
|
1250 |
});
|
1251 |
|
1252 |
-
for (let i = 0; i <
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
//
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1265 |
} else {
|
1266 |
-
x = (Math.random() - 0.5) * MAP_SIZE * 0.
|
1267 |
-
z = (Math.random()
|
1268 |
}
|
1269 |
-
} else {
|
1270 |
-
// ๋งต ์ค์ ์์ญ์ ์์ฑ
|
1271 |
-
x = (Math.random() - 0.5) * MAP_SIZE * 0.6;
|
1272 |
-
z = (Math.random() - 0.5) * MAP_SIZE * 0.6;
|
1273 |
-
}
|
1274 |
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
Math.random() * Math.PI
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1311 |
}
|
1312 |
-
}
|
1313 |
|
1314 |
-
|
1315 |
-
|
1316 |
-
this.scene.add(rock);
|
1317 |
-
this.scene.add(collisionMesh);
|
1318 |
}
|
1319 |
}
|
1320 |
|
1321 |
-
// ์ ์ธ์ฅ ์ถ๊ฐ
|
1322 |
const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
|
1323 |
const cactusMaterial = new THREE.MeshStandardMaterial({
|
1324 |
color: 0x2F4F2F,
|
@@ -1334,11 +1334,10 @@ class Game {
|
|
1334 |
);
|
1335 |
cactus.castShadow = true;
|
1336 |
cactus.receiveShadow = true;
|
1337 |
-
cactus.userData.isCollidable = false;
|
1338 |
cactus.userData.type = 'cactus';
|
1339 |
|
1340 |
this.scene.add(cactus);
|
1341 |
-
// ์ ์ธ์ฅ์ obstacles ๋ฐฐ์ด์ ์ถ๊ฐํ์ง ์์
|
1342 |
}
|
1343 |
}
|
1344 |
|
|
|
1222 |
this.lastRadarUpdate = currentTime;
|
1223 |
}
|
1224 |
|
1225 |
+
async addDesertDecorations() {
|
1226 |
+
if (!this.obstacles) {
|
1227 |
+
this.obstacles = [];
|
1228 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1229 |
|
1230 |
+
const BUILDING_COUNT = 70; // ๋ฐ์ ๋์ ๊ฑด๋ฌผ๋ก ๋ณ๊ฒฝ
|
1231 |
+
const buildingModels = [
|
1232 |
+
'models/house1.glb',
|
1233 |
+
'models/house2.glb',
|
1234 |
+
'models/house3.glb',
|
1235 |
+
'models/house4.glb'
|
1236 |
+
];
|
1237 |
|
1238 |
// ์ถฉ๋ ๋ฐ์ค ์๊ฐํ์ฉ ์ฌ์ง (๋๋ฒ๊น
์ฉ)
|
1239 |
const collisionBoxMaterial = new THREE.MeshBasicMaterial({
|
|
|
1242 |
visible: false // ํ์์ true๋ก ๋ณ๊ฒฝํ์ฌ ์ถฉ๋ ๋ฐ์ค ํ์ธ
|
1243 |
});
|
1244 |
|
1245 |
+
for (let i = 0; i < BUILDING_COUNT; i++) {
|
1246 |
+
try {
|
1247 |
+
// ๋ฌด์์๋ก ๊ฑด๋ฌผ ๋ชจ๋ธ ์ ํ
|
1248 |
+
const modelPath = buildingModels[Math.floor(Math.random() * buildingModels.length)];
|
1249 |
+
const result = await this.loader.loadAsync(modelPath);
|
1250 |
+
const building = result.scene;
|
1251 |
+
|
1252 |
+
// ๊ฑด๋ฌผ ์์น ์ค์ - ๋งต ๊ฐ์ฅ์๋ฆฌ์ ๋ ๋ง์ด ๋ฐฐ์น
|
1253 |
+
let x, z;
|
1254 |
+
const edgeSpawn = Math.random() < 0.7; // 70% ํ๋ฅ ๋ก ๊ฐ์ฅ์๋ฆฌ์ ์์ฑ
|
1255 |
+
|
1256 |
+
if (edgeSpawn) {
|
1257 |
+
if (Math.random() < 0.5) {
|
1258 |
+
x = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
|
1259 |
+
z = (Math.random() - 0.5) * MAP_SIZE * 0.9;
|
1260 |
+
} else {
|
1261 |
+
x = (Math.random() - 0.5) * MAP_SIZE * 0.9;
|
1262 |
+
z = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
|
1263 |
+
}
|
1264 |
} else {
|
1265 |
+
x = (Math.random() - 0.5) * MAP_SIZE * 0.6;
|
1266 |
+
z = (Math.random() - 0.5) * MAP_SIZE * 0.6;
|
1267 |
}
|
|
|
|
|
|
|
|
|
|
|
1268 |
|
1269 |
+
building.position.set(x, 0, z);
|
1270 |
+
|
1271 |
+
// ๋๋ค ํ์
|
1272 |
+
building.rotation.y = Math.random() * Math.PI * 2;
|
1273 |
+
|
1274 |
+
// ์ค์ผ์ผ ์ค์ (ํ๋ ์ด์ด ํฑํฌ์ ๋์ผํ๊ฒ)
|
1275 |
+
building.scale.set(1, 1, 1);
|
1276 |
+
|
1277 |
+
// ๊ทธ๋ฆผ์ ์ค์
|
1278 |
+
building.traverse((child) => {
|
1279 |
+
if (child.isMesh) {
|
1280 |
+
child.castShadow = true;
|
1281 |
+
child.receiveShadow = true;
|
1282 |
+
}
|
1283 |
+
});
|
1284 |
+
|
1285 |
+
// ์ถฉ๋ ๋ฐ์ค ์์ฑ
|
1286 |
+
const boundingBox = new THREE.Box3().setFromObject(building);
|
1287 |
+
const boxSize = boundingBox.getSize(new THREE.Vector3());
|
1288 |
+
const collisionGeometry = new THREE.BoxGeometry(boxSize.x, boxSize.y, boxSize.z);
|
1289 |
+
const collisionMesh = new THREE.Mesh(collisionGeometry, collisionBoxMaterial);
|
1290 |
+
|
1291 |
+
collisionMesh.position.copy(building.position);
|
1292 |
+
collisionMesh.position.y += boxSize.y / 2; // ์ถฉ๋ ๋ฐ์ค๋ฅผ ๊ฑด๋ฌผ ์ค์ฌ์ ๋ง์ถค
|
1293 |
+
collisionMesh.rotation.copy(building.rotation);
|
1294 |
+
|
1295 |
+
// ์ถฉ๋ ๋ฐ์ดํฐ ์ค์
|
1296 |
+
building.userData.isCollidable = true;
|
1297 |
+
building.userData.type = 'building';
|
1298 |
+
building.userData.collisionMesh = collisionMesh;
|
1299 |
+
|
1300 |
+
// ๋ค๋ฅธ ๊ฑด๋ฌผ๋ค๊ณผ์ ๊ฑฐ๋ฆฌ ์ฒดํฌ
|
1301 |
+
let tooClose = false;
|
1302 |
+
for (const obstacle of this.obstacles) {
|
1303 |
+
const distance = building.position.distanceTo(obstacle.position);
|
1304 |
+
if (distance < 20) { // ์ต์ ๊ฑฐ๋ฆฌ ์ค์
|
1305 |
+
tooClose = true;
|
1306 |
+
break;
|
1307 |
+
}
|
1308 |
+
}
|
1309 |
+
|
1310 |
+
if (!tooClose) {
|
1311 |
+
this.obstacles.push(building);
|
1312 |
+
this.scene.add(building);
|
1313 |
+
this.scene.add(collisionMesh);
|
1314 |
}
|
|
|
1315 |
|
1316 |
+
} catch (error) {
|
1317 |
+
console.error('Error loading building model:', error);
|
|
|
|
|
1318 |
}
|
1319 |
}
|
1320 |
|
1321 |
+
// ์ ์ธ์ฅ ์ถ๊ฐ (๊ธฐ์กด ์ฝ๋ ์ ์ง)
|
1322 |
const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
|
1323 |
const cactusMaterial = new THREE.MeshStandardMaterial({
|
1324 |
color: 0x2F4F2F,
|
|
|
1334 |
);
|
1335 |
cactus.castShadow = true;
|
1336 |
cactus.receiveShadow = true;
|
1337 |
+
cactus.userData.isCollidable = false;
|
1338 |
cactus.userData.type = 'cactus';
|
1339 |
|
1340 |
this.scene.add(cactus);
|
|
|
1341 |
}
|
1342 |
}
|
1343 |
|