cutechicken commited on
Commit
7e2879b
โ€ข
1 Parent(s): b32bcd4

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +28 -25
game.js CHANGED
@@ -1594,7 +1594,7 @@ class Game {
1594
  this.obstacles = [];
1595
  }
1596
 
1597
- const BUILDING_COUNT = 50; // ๋ฐ”์œ„ ๋Œ€์‹  ๊ฑด๋ฌผ๋กœ ๋ณ€๊ฒฝ
1598
  const buildingModels = [
1599
  'models/house1.glb',
1600
  'models/house2.glb',
@@ -1602,23 +1602,20 @@ class Game {
1602
  'models/house4.glb'
1603
  ];
1604
 
1605
- // ์ถฉ๋Œ ๋ฐ•์Šค ์‹œ๊ฐํ™”์šฉ ์žฌ์งˆ (๋””๋ฒ„๊น…์šฉ)
1606
- const collisionBoxMaterial = new THREE.MeshBasicMaterial({
1607
  color: 0xff0000,
1608
- wireframe: true,
1609
- visible: false // ํ•„์š”์‹œ true๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ถฉ๋Œ ๋ฐ•์Šค ํ™•์ธ
1610
  });
1611
 
1612
  for (let i = 0; i < BUILDING_COUNT; i++) {
1613
  try {
1614
- // ๋ฌด์ž‘์œ„๋กœ ๊ฑด๋ฌผ ๋ชจ๋ธ ์„ ํƒ
1615
  const modelPath = buildingModels[Math.floor(Math.random() * buildingModels.length)];
1616
  const result = await this.loader.loadAsync(modelPath);
1617
  const building = result.scene;
1618
 
1619
- // ๊ฑด๋ฌผ ์œ„์น˜ ์„ค์ • - ๋งต ๊ฐ€์žฅ์ž๋ฆฌ์— ๋” ๋งŽ์ด ๋ฐฐ์น˜
1620
  let x, z;
1621
- const edgeSpawn = Math.random() < 0.7; // 70% ํ™•๋ฅ ๋กœ ๊ฐ€์žฅ์ž๋ฆฌ์— ์ƒ์„ฑ
1622
 
1623
  if (edgeSpawn) {
1624
  if (Math.random() < 0.5) {
@@ -1634,11 +1631,7 @@ class Game {
1634
  }
1635
 
1636
  building.position.set(x, 0, z);
1637
-
1638
- // ๋žœ๋ค ํšŒ์ „
1639
  building.rotation.y = Math.random() * Math.PI * 2;
1640
-
1641
- // ์Šค์ผ€์ผ ์„ค์ • (ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ์™€ ๋™์ผํ•˜๊ฒŒ)
1642
  building.scale.set(1, 1, 1);
1643
 
1644
  // ๊ทธ๋ฆผ์ž ์„ค์ •
@@ -1649,26 +1642,35 @@ class Game {
1649
  }
1650
  });
1651
 
1652
- // ์ถฉ๋Œ ๋ฐ•์Šค ์ƒ์„ฑ
1653
  const boundingBox = new THREE.Box3().setFromObject(building);
1654
  const boxSize = boundingBox.getSize(new THREE.Vector3());
1655
- const collisionGeometry = new THREE.BoxGeometry(boxSize.x, boxSize.y, boxSize.z);
1656
- const collisionMesh = new THREE.Mesh(collisionGeometry, collisionBoxMaterial);
1657
-
1658
- collisionMesh.position.copy(building.position);
1659
- collisionMesh.position.y += boxSize.y / 2; // ์ถฉ๋Œ ๋ฐ•์Šค๋ฅผ ๊ฑด๋ฌผ ์ค‘์‹ฌ์— ๋งž์ถค
1660
- collisionMesh.rotation.copy(building.rotation);
1661
-
 
 
 
 
 
 
 
 
 
 
1662
  // ์ถฉ๋Œ ๋ฐ์ดํ„ฐ ์„ค์ •
1663
  building.userData.isCollidable = true;
1664
  building.userData.type = 'building';
1665
- building.userData.collisionMesh = collisionMesh;
1666
-
1667
- // ๋‹ค๋ฅธ ๊ฑด๋ฌผ๋“ค๊ณผ์˜ ๊ฑฐ๋ฆฌ ์ฒดํฌ
1668
  let tooClose = false;
1669
  for (const obstacle of this.obstacles) {
1670
  const distance = building.position.distanceTo(obstacle.position);
1671
- if (distance < 20) { // ์ตœ์†Œ ๊ฑฐ๋ฆฌ ์„ค์ •
1672
  tooClose = true;
1673
  break;
1674
  }
@@ -1677,7 +1679,7 @@ class Game {
1677
  if (!tooClose) {
1678
  this.obstacles.push(building);
1679
  this.scene.add(building);
1680
- this.scene.add(collisionMesh);
1681
  }
1682
 
1683
  } catch (error) {
@@ -1685,6 +1687,7 @@ class Game {
1685
  }
1686
  }
1687
 
 
1688
  // ์„ ์ธ์žฅ ์ถ”๊ฐ€ (๊ธฐ์กด ์ฝ”๋“œ ์œ ์ง€)
1689
  const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
1690
  const cactusMaterial = new THREE.MeshStandardMaterial({
 
1594
  this.obstacles = [];
1595
  }
1596
 
1597
+ const BUILDING_COUNT = 50;
1598
  const buildingModels = [
1599
  'models/house1.glb',
1600
  'models/house2.glb',
 
1602
  'models/house4.glb'
1603
  ];
1604
 
1605
+ // ์ถฉ๋Œ ๋ฐ•์Šค ์‹œ๊ฐํ™”๋ฅผ ์œ„ํ•œ ์žฌ์งˆ
1606
+ const collisionBoxMaterial = new THREE.LineBasicMaterial({
1607
  color: 0xff0000,
1608
+ linewidth: 2
 
1609
  });
1610
 
1611
  for (let i = 0; i < BUILDING_COUNT; i++) {
1612
  try {
 
1613
  const modelPath = buildingModels[Math.floor(Math.random() * buildingModels.length)];
1614
  const result = await this.loader.loadAsync(modelPath);
1615
  const building = result.scene;
1616
 
 
1617
  let x, z;
1618
+ const edgeSpawn = Math.random() < 0.7;
1619
 
1620
  if (edgeSpawn) {
1621
  if (Math.random() < 0.5) {
 
1631
  }
1632
 
1633
  building.position.set(x, 0, z);
 
 
1634
  building.rotation.y = Math.random() * Math.PI * 2;
 
 
1635
  building.scale.set(1, 1, 1);
1636
 
1637
  // ๊ทธ๋ฆผ์ž ์„ค์ •
 
1642
  }
1643
  });
1644
 
1645
+ // ์ถฉ๋Œ ๋ฐ•์Šค ์ƒ์„ฑ ๋ฐ ์‹œ๊ฐํ™”
1646
  const boundingBox = new THREE.Box3().setFromObject(building);
1647
  const boxSize = boundingBox.getSize(new THREE.Vector3());
1648
+
1649
+ // ์ถฉ๋Œ ๋ฐ•์Šค์˜ ์™€์ด์–ดํ”„๋ ˆ์ž„ ์ƒ์„ฑ
1650
+ const boxGeometry = new THREE.BufferGeometry();
1651
+ const positions = new Float32Array([
1652
+ // ๋ฐ”๋‹ฅ ์‚ฌ๊ฐํ˜•
1653
+ -boxSize.x/2, 0.1, -boxSize.z/2,
1654
+ -boxSize.x/2, 0.1, boxSize.z/2,
1655
+ boxSize.x/2, 0.1, boxSize.z/2,
1656
+ boxSize.x/2, 0.1, -boxSize.z/2,
1657
+ -boxSize.x/2, 0.1, -boxSize.z/2
1658
+ ]);
1659
+
1660
+ boxGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
1661
+ const collisionBoxLine = new THREE.Line(boxGeometry, collisionBoxMaterial);
1662
+ collisionBoxLine.position.copy(building.position);
1663
+ collisionBoxLine.rotation.y = building.rotation.y;
1664
+
1665
  // ์ถฉ๋Œ ๋ฐ์ดํ„ฐ ์„ค์ •
1666
  building.userData.isCollidable = true;
1667
  building.userData.type = 'building';
1668
+ building.userData.collisionBox = collisionBoxLine;
1669
+
 
1670
  let tooClose = false;
1671
  for (const obstacle of this.obstacles) {
1672
  const distance = building.position.distanceTo(obstacle.position);
1673
+ if (distance < 20) {
1674
  tooClose = true;
1675
  break;
1676
  }
 
1679
  if (!tooClose) {
1680
  this.obstacles.push(building);
1681
  this.scene.add(building);
1682
+ this.scene.add(collisionBoxLine); // ์ถฉ๋Œ ๋ฐ•์Šค ๋ผ์ธ ์ถ”๊ฐ€
1683
  }
1684
 
1685
  } catch (error) {
 
1687
  }
1688
  }
1689
 
1690
+
1691
  // ์„ ์ธ์žฅ ์ถ”๊ฐ€ (๊ธฐ์กด ์ฝ”๋“œ ์œ ์ง€)
1692
  const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
1693
  const cactusMaterial = new THREE.MeshStandardMaterial({