cutechicken commited on
Commit
cc6ae9c
โ€ข
1 Parent(s): 3374382

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +81 -82
game.js CHANGED
@@ -1222,25 +1222,18 @@ class Game {
1222
  this.lastRadarUpdate = currentTime;
1223
  }
1224
 
1225
- async addDesertDecorations() {
1226
- if (!this.obstacles) {
1227
- this.obstacles = []; // ๋ฐฐ์—ด์ด ์—†์œผ๋ฉด ์ดˆ๊ธฐํ™”
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 rockMaterial = new THREE.MeshStandardMaterial({
1240
- color: 0x8B4513,
1241
- roughness: 0.9,
1242
- metalness: 0.1
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 < ROCK_COUNT; i++) {
1253
- const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
1254
- const rock = new THREE.Mesh(rockGeometry, rockMaterial);
1255
-
1256
- // ๋ฐ”์œ„ ์œ„์น˜ ์„ค์ • - ๋งต ๊ฐ€์žฅ์ž๋ฆฌ์— ๋” ๋งŽ์ด ๋ฐฐ์น˜
1257
- let x, z;
1258
- const edgeSpawn = Math.random() < 0.7; // 70% ํ™•๋ฅ ๋กœ ๊ฐ€์žฅ์ž๋ฆฌ์— ์ƒ์„ฑ
1259
-
1260
- if (edgeSpawn) {
1261
- // ๋งต ๊ฐ€์žฅ์ž๋ฆฌ์— ์ƒ์„ฑ
1262
- if (Math.random() < 0.5) {
1263
- x = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
1264
- z = (Math.random() - 0.5) * MAP_SIZE * 0.9;
 
 
 
 
 
 
1265
  } else {
1266
- x = (Math.random() - 0.5) * MAP_SIZE * 0.9;
1267
- z = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
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
- rock.position.set(x, Math.random() * 2, z);
1276
-
1277
- rock.rotation.set(
1278
- Math.random() * Math.PI,
1279
- Math.random() * Math.PI,
1280
- Math.random() * Math.PI
1281
- );
1282
-
1283
- // ๋ฐ”์œ„ ํฌ๊ธฐ๋ฅผ ์ข€ ๋” ๋‹ค์–‘ํ•˜๊ฒŒ ์„ค์ •
1284
- const scale = 1 + Math.random() * 1.5; // 1.0 ~ 2.5 ์‚ฌ์ด์˜ ํฌ๊ธฐ
1285
- rock.scale.set(scale, scale, scale);
1286
-
1287
- // ์ถฉ๋Œ ๋ฐ•์Šค ์ƒ์„ฑ ๋ฐ ์„ค์ •
1288
- const boundingBox = new THREE.Box3().setFromObject(rock);
1289
- const boxSize = boundingBox.getSize(new THREE.Vector3());
1290
- const collisionGeometry = new THREE.BoxGeometry(boxSize.x, boxSize.y, boxSize.z);
1291
- const collisionMesh = new THREE.Mesh(collisionGeometry, collisionBoxMaterial);
1292
-
1293
- collisionMesh.position.copy(rock.position);
1294
- collisionMesh.rotation.copy(rock.rotation);
1295
-
1296
- // ๋ชจ๋“  ๋ฐ”์œ„๋ฅผ ์ถฉ๋Œ ๊ฐ€๋Šฅํ•˜๊ฒŒ ์„ค์ •
1297
- rock.userData.isCollidable = true;
1298
- rock.userData.type = 'rock';
1299
- rock.userData.collisionMesh = collisionMesh;
1300
-
1301
- rock.castShadow = true;
1302
- rock.receiveShadow = true;
1303
-
1304
- // ๋‹ค๋ฅธ ๋ฐ”์œ„๋“ค๊ณผ์˜ ๊ฑฐ๋ฆฌ ์ฒดํฌ
1305
- let tooClose = false;
1306
- for (const obstacle of this.obstacles) {
1307
- const distance = rock.position.distanceTo(obstacle.position);
1308
- if (distance < 15) { // ์ตœ์†Œ ๊ฑฐ๋ฆฌ ์„ค์ •
1309
- tooClose = true;
1310
- break;
 
 
 
 
 
 
 
 
 
1311
  }
1312
- }
1313
 
1314
- if (!tooClose) {
1315
- this.obstacles.push(rock);
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