Spaces:
Running
Running
cutechicken
commited on
Commit
•
e5248b4
1
Parent(s):
516edb9
Update game.js
Browse files
game.js
CHANGED
@@ -1608,12 +1608,17 @@ class Game {
|
|
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 |
|
@@ -1633,7 +1638,7 @@ class Game {
|
|
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 |
// 그림자 설정
|
1638 |
building.traverse((child) => {
|
1639 |
if (child.isMesh) {
|
@@ -1650,11 +1655,11 @@ class Game {
|
|
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));
|
@@ -1670,7 +1675,7 @@ class Game {
|
|
1670 |
let tooClose = false;
|
1671 |
for (const obstacle of this.obstacles) {
|
1672 |
const distance = building.position.distanceTo(obstacle.position);
|
1673 |
-
if (distance <
|
1674 |
tooClose = true;
|
1675 |
break;
|
1676 |
}
|
@@ -1687,7 +1692,6 @@ class Game {
|
|
1687 |
}
|
1688 |
}
|
1689 |
|
1690 |
-
|
1691 |
// 선인장 추가 (기존 코드 유지)
|
1692 |
const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
|
1693 |
const cactusMaterial = new THREE.MeshStandardMaterial({
|
@@ -1706,12 +1710,13 @@ class Game {
|
|
1706 |
cactus.receiveShadow = true;
|
1707 |
cactus.userData.isCollidable = false;
|
1708 |
cactus.userData.type = 'cactus';
|
1709 |
-
|
1710 |
this.scene.add(cactus);
|
1711 |
}
|
1712 |
}
|
1713 |
|
1714 |
|
|
|
1715 |
getHeightAtPosition(x, z) {
|
1716 |
return 0; // 항상 높이 0 반환
|
1717 |
}
|
|
|
1608 |
linewidth: 2
|
1609 |
});
|
1610 |
|
1611 |
+
// 플레이어 충돌 반경 및 최소 거리 계산
|
1612 |
+
const playerCollisionRadius = 2; // 플레이어 충돌 반경 (탱크의 크기 기준)
|
1613 |
+
const clearanceBuffer = 1; // 여유 공간
|
1614 |
+
const minimumDistance = playerCollisionRadius * 2 + clearanceBuffer; // 건물 간 최소 거리
|
1615 |
+
|
1616 |
for (let i = 0; i < BUILDING_COUNT; i++) {
|
1617 |
try {
|
1618 |
const modelPath = buildingModels[Math.floor(Math.random() * buildingModels.length)];
|
1619 |
const result = await this.loader.loadAsync(modelPath);
|
1620 |
const building = result.scene;
|
1621 |
+
|
1622 |
let x, z;
|
1623 |
const edgeSpawn = Math.random() < 0.7;
|
1624 |
|
|
|
1638 |
building.position.set(x, 0, z);
|
1639 |
building.rotation.y = Math.random() * Math.PI * 2;
|
1640 |
building.scale.set(1, 1, 1);
|
1641 |
+
|
1642 |
// 그림자 설정
|
1643 |
building.traverse((child) => {
|
1644 |
if (child.isMesh) {
|
|
|
1655 |
const boxGeometry = new THREE.BufferGeometry();
|
1656 |
const positions = new Float32Array([
|
1657 |
// 바닥 사각형
|
1658 |
+
-boxSize.x / 2, 0.1, -boxSize.z / 2,
|
1659 |
+
-boxSize.x / 2, 0.1, boxSize.z / 2,
|
1660 |
+
boxSize.x / 2, 0.1, boxSize.z / 2,
|
1661 |
+
boxSize.x / 2, 0.1, -boxSize.z / 2,
|
1662 |
+
-boxSize.x / 2, 0.1, -boxSize.z / 2
|
1663 |
]);
|
1664 |
|
1665 |
boxGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
|
|
1675 |
let tooClose = false;
|
1676 |
for (const obstacle of this.obstacles) {
|
1677 |
const distance = building.position.distanceTo(obstacle.position);
|
1678 |
+
if (distance < minimumDistance) { // 최소 거리 조건 추가
|
1679 |
tooClose = true;
|
1680 |
break;
|
1681 |
}
|
|
|
1692 |
}
|
1693 |
}
|
1694 |
|
|
|
1695 |
// 선인장 추가 (기존 코드 유지)
|
1696 |
const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
|
1697 |
const cactusMaterial = new THREE.MeshStandardMaterial({
|
|
|
1710 |
cactus.receiveShadow = true;
|
1711 |
cactus.userData.isCollidable = false;
|
1712 |
cactus.userData.type = 'cactus';
|
1713 |
+
|
1714 |
this.scene.add(cactus);
|
1715 |
}
|
1716 |
}
|
1717 |
|
1718 |
|
1719 |
+
|
1720 |
getHeightAtPosition(x, z) {
|
1721 |
return 0; // 항상 높이 0 반환
|
1722 |
}
|