Spaces:
Running
Running
cutechicken
commited on
Commit
โข
5eeb328
1
Parent(s):
d7b0f1e
Update game.js
Browse files
game.js
CHANGED
@@ -75,123 +75,32 @@ class TankPlayer {
|
|
75 |
}
|
76 |
|
77 |
shoot(scene) {
|
78 |
-
|
79 |
-
|
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 |
-
|
150 |
-
|
151 |
-
|
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(
|
|
|
|
|
|
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
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;
|