Spaces:
Running
Running
cutechicken
commited on
Commit
โข
7e2879b
1
Parent(s):
b32bcd4
Update game.js
Browse files
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.
|
1607 |
color: 0xff0000,
|
1608 |
-
|
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;
|
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 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1662 |
// ์ถฉ๋ ๋ฐ์ดํฐ ์ค์
|
1663 |
building.userData.isCollidable = true;
|
1664 |
building.userData.type = 'building';
|
1665 |
-
building.userData.
|
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(
|
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({
|