cutechicken commited on
Commit
03060e2
β€’
1 Parent(s): 2a18e50

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +112 -26
game.js CHANGED
@@ -74,6 +74,48 @@ class TankPlayer {
74
  this.body.position.copy(this.position);
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  scene.add(this.body);
78
  this.isLoaded = true;
79
  this.updateAmmoDisplay();
@@ -125,25 +167,36 @@ class TankPlayer {
125
  }
126
 
127
  update(mouseX, mouseY, scene) {
128
- if (!this.body || !this.turretGroup) return;
129
-
130
- const absoluteTurretRotation = mouseX;
131
- this.turretGroup.rotation.y = absoluteTurretRotation - this.body.rotation.y;
132
- this.turretRotation = absoluteTurretRotation;
133
-
134
- for (let i = this.bullets.length - 1; i >= 0; i--) {
135
- const bullet = this.bullets[i];
136
- bullet.position.add(bullet.velocity);
137
-
138
- if (
139
- Math.abs(bullet.position.x) > MAP_SIZE / 2 ||
140
- Math.abs(bullet.position.z) > MAP_SIZE / 2
141
- ) {
142
- scene.remove(bullet);
143
- this.bullets.splice(i, 1);
144
- }
 
 
 
 
 
 
 
 
 
 
145
  }
146
  }
 
147
 
148
  move(direction) {
149
  if (!this.body) return;
@@ -517,11 +570,34 @@ class Game {
517
  const groundMaterial = new THREE.MeshStandardMaterial({
518
  color: 0xD2B48C,
519
  roughness: 0.8,
520
- metalness: 0.2
 
521
  });
 
522
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
523
  ground.rotation.x = -Math.PI / 2;
524
  ground.receiveShadow = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
 
526
  // 더 λ‹€μ–‘ν•œ μ§€ν˜• 생성
527
  const vertices = ground.geometry.attributes.position.array;
@@ -1051,14 +1127,24 @@ class Game {
1051
  return null;
1052
  }
1053
  updateParticles() {
1054
- for (let i = this.particles.length - 1; i >= 0; i--) {
1055
- const particle = this.particles[i];
1056
- if (!particle.update()) {
1057
- particle.destroy(this.scene);
1058
- this.particles.splice(i, 1);
1059
- }
1060
- }
1061
- }
 
 
 
 
 
 
 
 
 
 
1062
 
1063
  createExplosion(position) {
1064
  for (let i = 0; i < PARTICLE_COUNT; i++) {
 
74
  this.body.position.copy(this.position);
75
  }
76
 
77
+ // 폭발 μ΄νŽ™νŠΈ λ©”μ„œλ“œ μΆ”κ°€
78
+ this.createExplosionEffect = (scene, position) => {
79
+ // 폭발 νŒŒν‹°ν΄
80
+ for (let i = 0; i < 15; i++) {
81
+ const size = Math.random() * 0.2 + 0.1;
82
+ const geometry = new THREE.SphereGeometry(size);
83
+ const material = new THREE.MeshBasicMaterial({
84
+ color: Math.random() < 0.5 ? 0xff4500 : 0xff8c00
85
+ });
86
+ const particle = new THREE.Mesh(geometry, material);
87
+ particle.position.copy(position);
88
+
89
+ const speed = Math.random() * 0.3 + 0.2;
90
+ const angle = Math.random() * Math.PI * 2;
91
+ const elevation = Math.random() * Math.PI - Math.PI / 2;
92
+
93
+ particle.velocity = new THREE.Vector3(
94
+ Math.cos(angle) * Math.cos(elevation) * speed,
95
+ Math.sin(elevation) * speed,
96
+ Math.sin(angle) * Math.cos(elevation) * speed
97
+ );
98
+
99
+ particle.gravity = -0.01;
100
+ particle.life = Math.random() * 20 + 20;
101
+ particle.fadeRate = 1 / particle.life;
102
+
103
+ scene.add(particle);
104
+ window.gameInstance.particles.push({
105
+ mesh: particle,
106
+ velocity: particle.velocity,
107
+ gravity: particle.gravity,
108
+ life: particle.life,
109
+ fadeRate: particle.fadeRate
110
+ });
111
+ }
112
+
113
+ // 좩돌 μ‚¬μš΄λ“œ μž¬μƒ
114
+ const explosionSound = new Audio('sounds/explosion.ogg');
115
+ explosionSound.volume = 0.3;
116
+ explosionSound.play();
117
+ };
118
+
119
  scene.add(this.body);
120
  this.isLoaded = true;
121
  this.updateAmmoDisplay();
 
167
  }
168
 
169
  update(mouseX, mouseY, scene) {
170
+ if (!this.body || !this.turretGroup) return;
171
+
172
+ const absoluteTurretRotation = mouseX;
173
+ this.turretGroup.rotation.y = absoluteTurretRotation - this.body.rotation.y;
174
+ this.turretRotation = absoluteTurretRotation;
175
+
176
+ // μ΄μ•Œ μ—…λ°μ΄νŠΈ 및 좩돌 체크
177
+ for (let i = this.bullets.length - 1; i >= 0; i--) {
178
+ const bullet = this.bullets[i];
179
+ const oldPosition = bullet.position.clone();
180
+ bullet.position.add(bullet.velocity);
181
+
182
+ // μ§€ν˜• 높이 체크
183
+ const terrainHeight = window.gameInstance.getHeightAtPosition(
184
+ bullet.position.x,
185
+ bullet.position.z
186
+ );
187
+
188
+ if (bullet.position.y < terrainHeight ||
189
+ Math.abs(bullet.position.x) > MAP_SIZE / 2 ||
190
+ Math.abs(bullet.position.z) > MAP_SIZE / 2) {
191
+
192
+ // 폭발 μ΄νŽ™νŠΈ 생성
193
+ this.createExplosionEffect(scene, bullet.position);
194
+
195
+ scene.remove(bullet);
196
+ this.bullets.splice(i, 1);
197
  }
198
  }
199
+ }
200
 
201
  move(direction) {
202
  if (!this.body) return;
 
570
  const groundMaterial = new THREE.MeshStandardMaterial({
571
  color: 0xD2B48C,
572
  roughness: 0.8,
573
+ metalness: 0.2,
574
+ wireframe: false
575
  });
576
+
577
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
578
  ground.rotation.x = -Math.PI / 2;
579
  ground.receiveShadow = true;
580
+
581
+ // 격자 효과λ₯Ό μœ„ν•œ 라인 μΆ”κ°€
582
+ const gridSize = 50; // 격자 크기
583
+ const gridHelper = new THREE.GridHelper(MAP_SIZE, gridSize, 0x000000, 0x000000);
584
+ gridHelper.material.opacity = 0.1;
585
+ gridHelper.material.transparent = true;
586
+ gridHelper.position.y = 0.1; // 지면보닀 μ•½κ°„ μœ„μ— 배치
587
+ this.scene.add(gridHelper);
588
+
589
+ // λ“±κ³ μ„  효과λ₯Ό μœ„ν•œ μ§€ν˜• μ»¨νˆ¬μ–΄
590
+ const contourLines = new THREE.LineSegments(
591
+ new THREE.EdgesGeometry(groundGeometry),
592
+ new THREE.LineBasicMaterial({
593
+ color: 0x000000,
594
+ opacity: 0.15,
595
+ transparent: true
596
+ })
597
+ );
598
+ contourLines.rotation.x = -Math.PI / 2;
599
+ contourLines.position.y = 0.1;
600
+ this.scene.add(contourLines);
601
 
602
  // 더 λ‹€μ–‘ν•œ μ§€ν˜• 생성
603
  const vertices = ground.geometry.attributes.position.array;
 
1127
  return null;
1128
  }
1129
  updateParticles() {
1130
+ for (let i = this.particles.length - 1; i >= 0; i--) {
1131
+ const particle = this.particles[i];
1132
+
1133
+ // 쀑λ ₯ 적용
1134
+ particle.velocity.y += particle.gravity;
1135
+ particle.mesh.position.add(particle.velocity);
1136
+
1137
+ // 투λͺ…도 κ°μ†Œ
1138
+ particle.mesh.material.opacity -= particle.fadeRate;
1139
+ particle.life--;
1140
+
1141
+ // νŒŒν‹°ν΄ 제거
1142
+ if (particle.life <= 0 || particle.mesh.material.opacity <= 0) {
1143
+ this.scene.remove(particle.mesh);
1144
+ this.particles.splice(i, 1);
1145
+ }
1146
+ }
1147
+ }
1148
 
1149
  createExplosion(position) {
1150
  for (let i = 0; i < PARTICLE_COUNT; i++) {