cutechicken commited on
Commit
22a2c1a
โ€ข
1 Parent(s): 989a374

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +53 -42
game.js CHANGED
@@ -38,6 +38,7 @@ class TankPlayer {
38
  this.reloadTime = 3000; // ์ถ”๊ฐ€: 3์ดˆ ์žฌ์žฅ์ „ ์‹œ๊ฐ„
39
  this.lastShootTime = 0;
40
  this.bullets = [];
 
41
  }
42
  // ๋ณ„๋„์˜ ๋ฉ”์„œ๋“œ๋กœ ๋ถ„๋ฆฌ
43
  createExplosionEffect(scene, position) {
@@ -1011,48 +1012,53 @@ this.scene.add(ground);
1011
  for (let i = 0; i < 100; i++) {
1012
  const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
1013
  const rock = new THREE.Mesh(rockGeometry, rockMaterial);
1014
- rock.position.set(
1015
- (Math.random() - 0.5) * MAP_SIZE * 0.9,
1016
- Math.random() * 2,
1017
- (Math.random() - 0.5) * MAP_SIZE * 0.9
1018
- );
1019
-
1020
- rock.rotation.set(
1021
- Math.random() * Math.PI,
1022
- Math.random() * Math.PI,
1023
- Math.random() * Math.PI
1024
- );
1025
-
1026
- rock.scale.set(
1027
- 1 + Math.random() * 0.5,
1028
- 1 + Math.random() * 0.5,
1029
- 1 + Math.random() * 0.5
1030
- );
1031
-
1032
- rock.castShadow = true;
1033
- rock.receiveShadow = true;
1034
- this.scene.add(rock);
1035
- }
 
 
1036
 
1037
- // ์„ ์ธ์žฅ ์ถ”๊ฐ€ (๊ฐ„๋‹จํ•œ geometry๋กœ ํ‘œํ˜„)
1038
- const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
1039
- const cactusMaterial = new THREE.MeshStandardMaterial({
1040
- color: 0x2F4F2F,
1041
- roughness: 0.8
1042
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1043
 
1044
- for (let i = 0; i < 50; i++) {
1045
- const cactus = new THREE.Mesh(cactusGeometry, cactusMaterial);
1046
- cactus.position.set(
1047
- (Math.random() - 0.5) * MAP_SIZE * 0.8,
1048
- 2,
1049
- (Math.random() - 0.5) * MAP_SIZE * 0.8
1050
- );
1051
- cactus.castShadow = true;
1052
- cactus.receiveShadow = true;
1053
- this.scene.add(cactus);
1054
- }
1055
- }
1056
 
1057
  getHeightAtPosition(x, z) {
1058
  return 0; // ํ•ญ์ƒ ๋†’์ด 0 ๋ฐ˜ํ™˜
@@ -1437,8 +1443,13 @@ this.scene.add(ground);
1437
 
1438
  // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ๋ฐฐ์—ด ์ •์˜
1439
  const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
1440
-
1441
- const tankPosition = this.tank.getPosition();
 
 
 
 
 
1442
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1443
  this.enemies.forEach(enemy => {
1444
  if (!enemy.mesh || !enemy.isLoaded) return;
 
38
  this.reloadTime = 3000; // ์ถ”๊ฐ€: 3์ดˆ ์žฌ์žฅ์ „ ์‹œ๊ฐ„
39
  this.lastShootTime = 0;
40
  this.bullets = [];
41
+ this.obstacles = [];
42
  }
43
  // ๋ณ„๋„์˜ ๋ฉ”์„œ๋“œ๋กœ ๋ถ„๋ฆฌ
44
  createExplosionEffect(scene, position) {
 
1012
  for (let i = 0; i < 100; i++) {
1013
  const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
1014
  const rock = new THREE.Mesh(rockGeometry, rockMaterial);
1015
+ rock.position.set(
1016
+ (Math.random() - 0.5) * MAP_SIZE * 0.9,
1017
+ Math.random() * 2,
1018
+ (Math.random() - 0.5) * MAP_SIZE * 0.9
1019
+ );
1020
+
1021
+ rock.rotation.set(
1022
+ Math.random() * Math.PI,
1023
+ Math.random() * Math.PI,
1024
+ Math.random() * Math.PI
1025
+ );
1026
+
1027
+ rock.scale.set(
1028
+ 1 + Math.random() * 0.5,
1029
+ 1 + Math.random() * 0.5,
1030
+ 1 + Math.random() * 0.5
1031
+ );
1032
+
1033
+ rock.castShadow = true;
1034
+ rock.receiveShadow = true;
1035
+ rock.userData.type = 'rock'; // ์žฅ์• ๋ฌผ ํƒ€์ž… ์ง€์ •
1036
+ this.obstacles.push(rock);
1037
+ this.scene.add(rock);
1038
+ }
1039
 
1040
+ // ์„ ์ธ์žฅ ์ถ”๊ฐ€
1041
+ const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
1042
+ const cactusMaterial = new THREE.MeshStandardMaterial({
1043
+ color: 0x2F4F2F,
1044
+ roughness: 0.8
1045
+ });
1046
+
1047
+ for (let i = 0; i < 50; i++) {
1048
+ const cactus = new THREE.Mesh(cactusGeometry, cactusMaterial);
1049
+ cactus.position.set(
1050
+ (Math.random() - 0.5) * MAP_SIZE * 0.8,
1051
+ 2,
1052
+ (Math.random() - 0.5) * MAP_SIZE * 0.8
1053
+ );
1054
+ cactus.castShadow = true;
1055
+ cactus.receiveShadow = true;
1056
+ cactus.userData.type = 'cactus'; // ์žฅ์• ๋ฌผ ํƒ€์ž… ์ง€์ •
1057
+ this.obstacles.push(cactus);
1058
+ this.scene.add(cactus);
1059
+ }
1060
+ }
1061
 
 
 
 
 
 
 
 
 
 
 
 
 
1062
 
1063
  getHeightAtPosition(x, z) {
1064
  return 0; // ํ•ญ์ƒ ๋†’์ด 0 ๋ฐ˜ํ™˜
 
1443
 
1444
  // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ๋ฐฐ์—ด ์ •์˜
1445
  const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
1446
+ // ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1447
+ const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
1448
+ this.obstacles.forEach(obstacle => {
1449
+ const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
1450
+ if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
1451
+ const tankPosition = this.tank.getPosition();
1452
+ //
1453
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1454
  this.enemies.forEach(enemy => {
1455
  if (!enemy.mesh || !enemy.isLoaded) return;