cutechicken commited on
Commit
2ecc8f4
โ€ข
1 Parent(s): df489df

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +79 -20
game.js CHANGED
@@ -75,32 +75,91 @@ class TankPlayer {
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;
 
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
+ const bulletGeometry = new THREE.SphereGeometry(0.2);
87
+ const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
88
+ const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
89
 
90
+ const bulletOffset = new THREE.Vector3(0, 0.5, 2);
91
+ bulletOffset.applyQuaternion(this.turretGroup.quaternion);
92
+ bulletOffset.applyQuaternion(this.body.quaternion);
93
+ bullet.position.copy(this.body.position).add(bulletOffset);
94
 
95
+ const direction = new THREE.Vector3(0, 0, 1);
96
+ direction.applyQuaternion(this.turretGroup.quaternion);
97
+ direction.applyQuaternion(this.body.quaternion);
98
+ bullet.velocity = direction.multiplyScalar(2);
99
 
100
+ scene.add(bullet);
101
+ this.bullets.push(bullet);
102
+ this.ammo--;
103
+ this.lastShootTime = currentTime;
104
 
105
+ // UI ์—…๋ฐ์ดํŠธ
106
+ document.getElementById('ammo').textContent = `${this.ammo}/10`;
107
+
108
+ // ์—ฐ๊ธฐ ํšจ๊ณผ ์ƒ์„ฑ
109
+ this.createSmokeEffect(scene, bulletOffset);
110
+
111
+ // ๋ฐœ์‚ฌ ์†Œ๋ฆฌ ์žฌ์ƒ
112
+ this.playRandomFireSound();
113
+
114
+ return bullet;
115
+ }
116
+
117
+ // ์—ฐ๊ธฐ ํšจ๊ณผ ์ƒ์„ฑ ๋ฉ”์„œ๋“œ
118
+ createSmokeEffect(scene, position) {
119
+ const particleCount = 10;
120
+ for (let i = 0; i < particleCount; i++) {
121
+ const smokeGeometry = new THREE.SphereGeometry(0.1, 8, 8);
122
+ const smokeMaterial = new THREE.MeshBasicMaterial({ color: 0x555555, transparent: true, opacity: 0.5 });
123
+ const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
124
+ smoke.position.copy(this.body.position.clone().add(position));
125
+ smoke.velocity = new THREE.Vector3(
126
+ (Math.random() - 0.5) * 0.5,
127
+ Math.random() * 0.2,
128
+ (Math.random() - 0.5) * 0.5
129
+ );
130
+ smoke.lifetime = 50;
131
+
132
+ scene.add(smoke);
133
+
134
+ // ์—ฐ๊ธฐ ์—…๋ฐ์ดํŠธ ๋กœ์ง
135
+ const updateSmoke = () => {
136
+ if (smoke.lifetime <= 0) {
137
+ scene.remove(smoke);
138
+ return;
139
+ }
140
+ smoke.lifetime--;
141
+ smoke.position.add(smoke.velocity);
142
+ smoke.material.opacity -= 0.01;
143
+ requestAnimationFrame(updateSmoke);
144
+ };
145
+ updateSmoke();
146
  }
147
+ }
148
+
149
+ // ๋ฌด์ž‘์œ„ ๋ฐœ์‚ฌ ์†Œ๋ฆฌ ์žฌ์ƒ ๋ฉ”์„œ๋“œ
150
+ playRandomFireSound() {
151
+ const sounds = [
152
+ "sounds/mbtfire1.ogg",
153
+ "sounds/mbtfire2.ogg",
154
+ "sounds/mbtfire3.ogg",
155
+ "sounds/mbtfire4.ogg",
156
+ "sounds/mbtfire5.ogg"
157
+ ];
158
+ const randomSound = sounds[Math.floor(Math.random() * sounds.length)];
159
+ const audio = new Audio(randomSound);
160
+ audio.play();
161
+ }
162
+
163
 
164
  update(mouseX, mouseY, scene) {
165
  if (!this.body || !this.turretGroup) return;