cutechicken commited on
Commit
6aab0c5
โ€ข
1 Parent(s): 2f9f159

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +106 -87
game.js CHANGED
@@ -1135,67 +1135,94 @@ class Game {
1135
  }
1136
 
1137
  // ๋ฐ”์œ„ ์ƒ์„ฑ
1138
- const rockGeometries = [
1139
- new THREE.DodecahedronGeometry(3),
1140
- new THREE.DodecahedronGeometry(2),
1141
- new THREE.DodecahedronGeometry(4)
1142
- ];
 
1143
 
1144
- const rockMaterial = new THREE.MeshStandardMaterial({
1145
- color: 0x8B4513,
1146
- roughness: 0.9,
1147
- metalness: 0.1
1148
- });
1149
 
1150
- for (let i = 0; i < 100; i++) {
1151
- const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
1152
- const rock = new THREE.Mesh(rockGeometry, rockMaterial);
1153
- rock.position.set(
1154
- (Math.random() - 0.5) * MAP_SIZE * 0.9,
1155
- Math.random() * 2,
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 cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
1180
- const cactusMaterial = new THREE.MeshStandardMaterial({
1181
- color: 0x2F4F2F,
1182
- roughness: 0.8
1183
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1184
 
1185
- for (let i = 0; i < 50; i++) {
1186
- const cactus = new THREE.Mesh(cactusGeometry, cactusMaterial);
1187
- cactus.position.set(
1188
- (Math.random() - 0.5) * MAP_SIZE * 0.8,
1189
- 2,
1190
- (Math.random() - 0.5) * MAP_SIZE * 0.8
1191
- );
1192
- cactus.castShadow = true;
1193
- cactus.receiveShadow = true;
1194
- cactus.userData.type = 'cactus'; // ์žฅ์• ๋ฌผ ํƒ€์ž… ์ง€์ •
1195
- this.obstacles.push(cactus);
1196
- this.scene.add(cactus);
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
- for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
1644
- const bullet = this.tank.bullets[i];
1645
- const bulletBox = new THREE.Box3().setFromObject(bullet);
 
1646
 
1647
- for (const obstacle of this.obstacles) {
 
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
- this.enemies.forEach(enemy => {
1663
- if (!enemy.bullets) return;
1664
-
1665
- for (let i = enemy.bullets.length - 1; i >= 0; i--) {
1666
- const bullet = enemy.bullets[i];
1667
- const bulletBox = new THREE.Box3().setFromObject(bullet);
1668
-
1669
- for (const obstacle of this.obstacles) {
1670
- const obstacleBox = new THREE.Box3().setFromObject(obstacle);
1671
- if (bulletBox.intersectsBox(obstacleBox)) {
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
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ