cutechicken commited on
Commit
cc6ae9c
·
verified ·
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