Spaces:
Running
Running
cutechicken
commited on
Commit
โข
6aab0c5
1
Parent(s):
2f9f159
Update game.js
Browse files
game.js
CHANGED
@@ -1135,67 +1135,94 @@ class Game {
|
|
1135 |
}
|
1136 |
|
1137 |
// ๋ฐ์ ์์ฑ
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
|
|
1143 |
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
(Math.random() - 0.5) * MAP_SIZE * 0.9
|
1157 |
-
);
|
1158 |
-
|
1159 |
-
rock.rotation.set(
|
1160 |
-
Math.random() * Math.PI,
|
1161 |
-
Math.random() * Math.PI,
|
1162 |
-
Math.random() * Math.PI
|
1163 |
-
);
|
1164 |
-
|
1165 |
-
rock.scale.set(
|
1166 |
-
1 + Math.random() * 0.5,
|
1167 |
-
1 + Math.random() * 0.5,
|
1168 |
-
1 + Math.random() * 0.5
|
1169 |
-
);
|
1170 |
-
|
1171 |
-
rock.castShadow = true;
|
1172 |
-
rock.receiveShadow = true;
|
1173 |
-
rock.userData.type = 'rock'; // ์ฅ์ ๋ฌผ ํ์
์ง์
|
1174 |
-
this.obstacles.push(rock);
|
1175 |
-
this.scene.add(rock);
|
1176 |
-
}
|
1177 |
|
1178 |
-
|
1179 |
-
const
|
1180 |
-
const
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1184 |
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1198 |
}
|
|
|
1199 |
|
1200 |
|
1201 |
getHeightAtPosition(x, z) {
|
@@ -1587,17 +1614,13 @@ class Game {
|
|
1587 |
|
1588 |
// ํฑํฌ์ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ (๊ฐ์ )
|
1589 |
this.obstacles.forEach(obstacle => {
|
|
|
1590 |
const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
|
1591 |
if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
|
1592 |
-
// ์ถฉ๋ ์ ์ด์ ์์น๋ก ๋๋๋ฆฌ๊ธฐ
|
1593 |
this.tank.body.position.copy(this.previousTankPosition);
|
1594 |
-
|
1595 |
-
// ์ถฉ๋ ์ฌ์ด๋ ์ฌ์
|
1596 |
-
//const collisionSound = new Audio('sounds/collision.ogg');
|
1597 |
-
//collisionSound.volume = 0.3;
|
1598 |
-
//collisionSound.play();
|
1599 |
}
|
1600 |
-
}
|
|
|
1601 |
// ์ ํฑํฌ์ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ (์ถ๊ฐ)
|
1602 |
this.enemies.forEach(enemy => {
|
1603 |
if (!enemy.mesh || !enemy.isLoaded) return;
|
@@ -1638,13 +1661,14 @@ class Game {
|
|
1638 |
});
|
1639 |
});
|
1640 |
|
1641 |
-
// ํฌํ๊ณผ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ (์ถ๊ฐ)
|
1642 |
// ํ๋ ์ด์ด ํฌํ
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
|
|
1646 |
|
1647 |
-
|
|
|
1648 |
const obstacleBox = new THREE.Box3().setFromObject(obstacle);
|
1649 |
if (bulletBox.intersectsBox(obstacleBox)) {
|
1650 |
// ํญ๋ฐ ์ดํํธ ์์ฑ
|
@@ -1657,29 +1681,24 @@ class Game {
|
|
1657 |
}
|
1658 |
}
|
1659 |
}
|
|
|
1660 |
|
1661 |
-
// ์
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
this.tank.createExplosionEffect(this.scene, bullet.position);
|
1674 |
-
|
1675 |
-
// ํฌํ ์ ๊ฑฐ
|
1676 |
-
this.scene.remove(bullet);
|
1677 |
-
enemy.bullets.splice(i, 1);
|
1678 |
-
break;
|
1679 |
-
}
|
1680 |
}
|
1681 |
}
|
1682 |
});
|
|
|
1683 |
|
1684 |
|
1685 |
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋ ์ฒดํฌ
|
|
|
1135 |
}
|
1136 |
|
1137 |
// ๋ฐ์ ์์ฑ
|
1138 |
+
// ๋ฐ์ ์์ฑ
|
1139 |
+
const rockGeometries = [
|
1140 |
+
new THREE.DodecahedronGeometry(3),
|
1141 |
+
new THREE.DodecahedronGeometry(2),
|
1142 |
+
new THREE.DodecahedronGeometry(4)
|
1143 |
+
];
|
1144 |
|
1145 |
+
const rockMaterial = new THREE.MeshStandardMaterial({
|
1146 |
+
color: 0x8B4513,
|
1147 |
+
roughness: 0.9,
|
1148 |
+
metalness: 0.1
|
1149 |
+
});
|
1150 |
|
1151 |
+
// ๋ฐ์์ฉ ์ถฉ๋ ๋ฐ์ค๋ฅผ ์๊ฐํํ๋ ์ฌ์ง (๋๋ฒ๊น
์ฉ)
|
1152 |
+
const collisionBoxMaterial = new THREE.MeshBasicMaterial({
|
1153 |
+
color: 0xff0000,
|
1154 |
+
wireframe: true,
|
1155 |
+
visible: false // ํ์์ true๋ก ๋ณ๊ฒฝํ์ฌ ์ถฉ๋ ๋ฐ์ค ํ์ธ
|
1156 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1157 |
|
1158 |
+
for (let i = 0; i < 100; i++) {
|
1159 |
+
const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
|
1160 |
+
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
|
1161 |
+
|
1162 |
+
// ๋ฐ์ ์์น ์ค์
|
1163 |
+
rock.position.set(
|
1164 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.9,
|
1165 |
+
Math.random() * 2,
|
1166 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.9
|
1167 |
+
);
|
1168 |
+
|
1169 |
+
rock.rotation.set(
|
1170 |
+
Math.random() * Math.PI,
|
1171 |
+
Math.random() * Math.PI,
|
1172 |
+
Math.random() * Math.PI
|
1173 |
+
);
|
1174 |
+
|
1175 |
+
rock.scale.set(
|
1176 |
+
1 + Math.random() * 0.5,
|
1177 |
+
1 + Math.random() * 0.5,
|
1178 |
+
1 + Math.random() * 0.5
|
1179 |
+
);
|
1180 |
+
|
1181 |
+
// ์ถฉ๋ ๋ฐ์ค ์์ฑ ๋ฐ ์ค์
|
1182 |
+
const boundingBox = new THREE.Box3().setFromObject(rock);
|
1183 |
+
const boxSize = boundingBox.getSize(new THREE.Vector3());
|
1184 |
+
const collisionGeometry = new THREE.BoxGeometry(boxSize.x, boxSize.y, boxSize.z);
|
1185 |
+
const collisionMesh = new THREE.Mesh(collisionGeometry, collisionBoxMaterial);
|
1186 |
+
|
1187 |
+
collisionMesh.position.copy(rock.position);
|
1188 |
+
collisionMesh.rotation.copy(rock.rotation);
|
1189 |
+
|
1190 |
+
// ๋ฐ์์ ์ถฉ๋ ์์ฑ ์ถ๊ฐ
|
1191 |
+
rock.userData.isCollidable = true;
|
1192 |
+
rock.userData.type = 'rock';
|
1193 |
+
rock.userData.collisionMesh = collisionMesh;
|
1194 |
+
|
1195 |
+
rock.castShadow = true;
|
1196 |
+
rock.receiveShadow = true;
|
1197 |
+
|
1198 |
+
this.obstacles.push(rock);
|
1199 |
+
this.scene.add(rock);
|
1200 |
+
this.scene.add(collisionMesh); // ๋๋ฒ๊น
์ฉ ์ถฉ๋ ๋ฐ์ค
|
1201 |
+
}
|
1202 |
|
1203 |
+
// ์ ์ธ์ฅ ์ถ๊ฐ
|
1204 |
+
const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
|
1205 |
+
const cactusMaterial = new THREE.MeshStandardMaterial({
|
1206 |
+
color: 0x2F4F2F,
|
1207 |
+
roughness: 0.8
|
1208 |
+
});
|
1209 |
+
|
1210 |
+
for (let i = 0; i < 50; i++) {
|
1211 |
+
const cactus = new THREE.Mesh(cactusGeometry, cactusMaterial);
|
1212 |
+
cactus.position.set(
|
1213 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.8,
|
1214 |
+
2,
|
1215 |
+
(Math.random() - 0.5) * MAP_SIZE * 0.8
|
1216 |
+
);
|
1217 |
+
cactus.castShadow = true;
|
1218 |
+
cactus.receiveShadow = true;
|
1219 |
+
cactus.userData.isCollidable = false; // ์ ์ธ์ฅ์ ์ถฉ๋ํ์ง ์์
|
1220 |
+
cactus.userData.type = 'cactus';
|
1221 |
+
|
1222 |
+
this.scene.add(cactus);
|
1223 |
+
// ์ ์ธ์ฅ์ obstacles ๋ฐฐ์ด์ ์ถ๊ฐํ์ง ์์
|
1224 |
}
|
1225 |
+
}
|
1226 |
|
1227 |
|
1228 |
getHeightAtPosition(x, z) {
|
|
|
1614 |
|
1615 |
// ํฑํฌ์ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ (๊ฐ์ )
|
1616 |
this.obstacles.forEach(obstacle => {
|
1617 |
+
if (obstacle.userData.isCollidable) { // ์ถฉ๋ ๊ฐ๋ฅํ ๊ฐ์ฒด๋ง ๊ฒ์ฌ
|
1618 |
const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
|
1619 |
if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
|
|
|
1620 |
this.tank.body.position.copy(this.previousTankPosition);
|
|
|
|
|
|
|
|
|
|
|
1621 |
}
|
1622 |
+
}
|
1623 |
+
});
|
1624 |
// ์ ํฑํฌ์ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ (์ถ๊ฐ)
|
1625 |
this.enemies.forEach(enemy => {
|
1626 |
if (!enemy.mesh || !enemy.isLoaded) return;
|
|
|
1661 |
});
|
1662 |
});
|
1663 |
|
|
|
1664 |
// ํ๋ ์ด์ด ํฌํ
|
1665 |
+
// ํฌํ๊ณผ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ
|
1666 |
+
for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
|
1667 |
+
const bullet = this.tank.bullets[i];
|
1668 |
+
const bulletBox = new THREE.Box3().setFromObject(bullet);
|
1669 |
|
1670 |
+
for (const obstacle of this.obstacles) {
|
1671 |
+
if (obstacle.userData.isCollidable) { // ์ถฉ๋ ๊ฐ๋ฅํ ๊ฐ์ฒด๋ง ๊ฒ์ฌ
|
1672 |
const obstacleBox = new THREE.Box3().setFromObject(obstacle);
|
1673 |
if (bulletBox.intersectsBox(obstacleBox)) {
|
1674 |
// ํญ๋ฐ ์ดํํธ ์์ฑ
|
|
|
1681 |
}
|
1682 |
}
|
1683 |
}
|
1684 |
+
}
|
1685 |
|
1686 |
+
// ์ ํฑํฌ์ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ
|
1687 |
+
this.enemies.forEach(enemy => {
|
1688 |
+
if (!enemy.mesh || !enemy.isLoaded) return;
|
1689 |
+
|
1690 |
+
const enemyBoundingBox = new THREE.Box3().setFromObject(enemy.mesh);
|
1691 |
+
const enemyPreviousPosition = enemy.mesh.position.clone();
|
1692 |
+
|
1693 |
+
this.obstacles.forEach(obstacle => {
|
1694 |
+
if (obstacle.userData.isCollidable) { // ์ถฉ๋ ๊ฐ๋ฅํ ๊ฐ์ฒด๋ง ๊ฒ์ฌ
|
1695 |
+
const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
|
1696 |
+
if (enemyBoundingBox.intersectsBox(obstacleBoundingBox)) {
|
1697 |
+
enemy.mesh.position.copy(enemyPreviousPosition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1698 |
}
|
1699 |
}
|
1700 |
});
|
1701 |
+
});
|
1702 |
|
1703 |
|
1704 |
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋ ์ฒดํฌ
|