cutechicken commited on
Commit
5eeb328
โ€ข
1 Parent(s): d7b0f1e

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +20 -111
game.js CHANGED
@@ -75,123 +75,32 @@ class TankPlayer {
75
  }
76
 
77
  shoot(scene) {
78
- const currentTime = Date.now();
79
- if (currentTime - this.lastShootTime < this.shootInterval || this.ammo <= 0) {
80
- if (this.ammo === 0) {
81
- console.log('Out of ammo! Reload required.');
82
- }
83
- return null;
84
- }
85
-
86
- // ํฌ์‹  ๋ ์ขŒํ‘œ ๊ณ„์‚ฐ
87
- const barrelEndOffset = new THREE.Vector3(0, 0, 2); // ํฌ์‹  ๋ ์˜คํ”„์…‹ (Z ์ถ•)
88
- const barrelEndPosition = this.turret.localToWorld(barrelEndOffset.clone());
89
-
90
- const bulletGeometry = new THREE.SphereGeometry(0.2);
91
- const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
92
- const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
93
-
94
- bullet.position.copy(barrelEndPosition); // ํฌ์‹  ๋์—์„œ ๋ฐœ์‚ฌ
95
- bullet.velocity = new THREE.Vector3(0, 0, 1)
96
- .applyQuaternion(this.turret.quaternion)
97
- .multiplyScalar(2);
98
-
99
- scene.add(bullet);
100
- this.bullets.push(bullet);
101
- this.ammo--;
102
- this.lastShootTime = currentTime;
103
-
104
- // UI ์—…๋ฐ์ดํŠธ
105
- document.getElementById('ammo').textContent = `${this.ammo}/10`;
106
-
107
- // ์—ฐ๊ธฐ ๋ฐ ๋ถˆ๊ฝƒ ํšจ๊ณผ ์ƒ์„ฑ
108
- this.createSmokeEffect(scene, barrelEndPosition);
109
- this.createMuzzleFlashEffect(scene, barrelEndPosition);
110
-
111
- // ๋ฐœ์‚ฌ ์†Œ๋ฆฌ ์žฌ์ƒ
112
- this.playRandomFireSound();
113
-
114
- return bullet;
115
- }
116
-
117
- createMuzzleFlashEffect(scene, position) {
118
- // ๋น› ํšจ๊ณผ
119
- const flashLight = new THREE.PointLight(0xffaa00, 2, 10);
120
- flashLight.position.copy(position); // ํฌ์‹  ๋ ์œ„์น˜์—์„œ ๋ถˆ๊ฝƒ ์ƒ์„ฑ
121
- scene.add(flashLight);
122
-
123
- // ๋ถˆ๊ฝƒ ๊ตฌ์ฒด
124
- const flashGeometry = new THREE.SphereGeometry(0.3, 16, 16);
125
- const flashMaterial = new THREE.MeshBasicMaterial({ color: 0xffaa00 });
126
- const flashMesh = new THREE.Mesh(flashGeometry, flashMaterial);
127
- flashMesh.position.copy(position);
128
- scene.add(flashMesh);
129
-
130
- // ๋ถˆ๊ฝƒ ํšจ๊ณผ ์—…๋ฐ์ดํŠธ
131
- let lifetime = 10;
132
- const updateFlash = () => {
133
- if (lifetime <= 0) {
134
- scene.remove(flashMesh);
135
- scene.remove(flashLight);
136
- return;
137
- }
138
- lifetime--;
139
- flashMesh.scale.multiplyScalar(0.9);
140
- flashLight.intensity *= 0.9;
141
- requestAnimationFrame(updateFlash);
142
- };
143
- updateFlash();
144
- }
145
 
 
 
 
146
 
 
 
 
 
147
 
148
- // ์—ฐ๊ธฐ ํšจ๊ณผ ์ƒ์„ฑ ๋ฉ”์„œ๋“œ
149
- createSmokeEffect(scene, position) {
150
- const particleCount = 10;
151
- for (let i = 0; i < particleCount; i++) {
152
- const smokeGeometry = new THREE.SphereGeometry(0.1, 8, 8);
153
- const smokeMaterial = new THREE.MeshBasicMaterial({ color: 0x555555, transparent: true, opacity: 0.5 });
154
- const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
155
- smoke.position.copy(this.body.position.clone().add(position));
156
- smoke.velocity = new THREE.Vector3(
157
- (Math.random() - 0.5) * 0.5,
158
- Math.random() * 0.2,
159
- (Math.random() - 0.5) * 0.5
160
- );
161
- smoke.lifetime = 50;
162
 
163
- scene.add(smoke);
 
 
 
164
 
165
- // ์—ฐ๊ธฐ ์—…๋ฐ์ดํŠธ ๋กœ์ง
166
- const updateSmoke = () => {
167
- if (smoke.lifetime <= 0) {
168
- scene.remove(smoke);
169
- return;
170
- }
171
- smoke.lifetime--;
172
- smoke.position.add(smoke.velocity);
173
- smoke.material.opacity -= 0.01;
174
- requestAnimationFrame(updateSmoke);
175
- };
176
- updateSmoke();
177
  }
178
- }
179
-
180
- // ๋ฌด์ž‘์œ„ ๋ฐœ์‚ฌ ์†Œ๋ฆฌ ์žฌ์ƒ ๋ฉ”์„œ๋“œ
181
- playRandomFireSound() {
182
- const sounds = [
183
- "sounds/mbtfire1.ogg",
184
- "sounds/mbtfire2.ogg",
185
- "sounds/mbtfire3.ogg",
186
- "sounds/mbtfire4.ogg",
187
- "sounds/mbtfire5.ogg"
188
- ];
189
- const randomSound = sounds[Math.floor(Math.random() * sounds.length)];
190
- const audio = new Audio(randomSound);
191
- audio.volume = 0.5; // ์†Œ๋ฆฌ ํฌ๊ธฐ๋ฅผ 50%๋กœ ์ค„์ž„
192
- audio.play();
193
- }
194
-
195
 
196
  update(mouseX, mouseY, scene) {
197
  if (!this.body || !this.turretGroup) return;
 
75
  }
76
 
77
  shoot(scene) {
78
+ const currentTime = Date.now();
79
+ if (currentTime - this.lastShootTime < this.shootInterval || this.ammo <= 0) return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
+ const bulletGeometry = new THREE.SphereGeometry(0.2);
82
+ const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
83
+ const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
84
 
85
+ const bulletOffset = new THREE.Vector3(0, 0.5, 2);
86
+ bulletOffset.applyQuaternion(this.turretGroup.quaternion);
87
+ bulletOffset.applyQuaternion(this.body.quaternion);
88
+ bullet.position.copy(this.body.position).add(bulletOffset);
89
 
90
+ const direction = new THREE.Vector3(0, 0, 1);
91
+ direction.applyQuaternion(this.turretGroup.quaternion);
92
+ direction.applyQuaternion(this.body.quaternion);
93
+ bullet.velocity = direction.multiplyScalar(2);
 
 
 
 
 
 
 
 
 
 
94
 
95
+ scene.add(bullet);
96
+ this.bullets.push(bullet);
97
+ this.ammo--;
98
+ this.lastShootTime = currentTime;
99
 
100
+ document.getElementById('ammo').textContent = `Ammo: ${this.ammo}/10`;
101
+
102
+ return bullet;
 
 
 
 
 
 
 
 
 
103
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  update(mouseX, mouseY, scene) {
106
  if (!this.body || !this.turretGroup) return;