Spaces:
Running
Running
cutechicken
commited on
Commit
โข
954c69c
1
Parent(s):
cec0881
Update game.js
Browse files
game.js
CHANGED
@@ -160,6 +160,15 @@ class TankPlayer {
|
|
160 |
|
161 |
async initialize(scene, loader) {
|
162 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
const bodyResult = await loader.loadAsync('/models/abramsBody.glb');
|
164 |
this.body = bodyResult.scene;
|
165 |
|
@@ -169,13 +178,15 @@ class TankPlayer {
|
|
169 |
this.turretGroup.position.y = 0.2;
|
170 |
this.turretGroup.add(this.turret);
|
171 |
this.body.add(this.turretGroup);
|
|
|
172 |
// ํฑํฌ ์์น ๋์ด ์กฐ์
|
173 |
-
this.body.position.y = 1.5;
|
174 |
|
175 |
-
// ๊ทธ๋ฆผ์ ํ๋ฉด
|
176 |
this.shadowPlane.position.y = -1.0;
|
|
|
177 |
|
178 |
-
// ๊ทธ๋ฆผ์
|
179 |
this.body.traverse((child) => {
|
180 |
if (child.isMesh) {
|
181 |
child.castShadow = true;
|
@@ -194,68 +205,15 @@ class TankPlayer {
|
|
194 |
}
|
195 |
});
|
196 |
|
197 |
-
//
|
198 |
-
const shadowPlaneGeometry = new THREE.PlaneGeometry(8, 8);
|
199 |
-
const shadowPlaneMaterial = new THREE.ShadowMaterial({
|
200 |
-
opacity: 0.3
|
201 |
-
});
|
202 |
-
this.shadowPlane = new THREE.Mesh(shadowPlaneGeometry, shadowPlaneMaterial);
|
203 |
-
this.shadowPlane.receiveShadow = true;
|
204 |
-
this.shadowPlane.rotation.x = -Math.PI / 2;
|
205 |
-
this.shadowPlane.position.y = 0.1;
|
206 |
-
this.body.add(this.shadowPlane);
|
207 |
-
|
208 |
-
// ๊ฐ๋จํ ์คํฐ ์์น ์ค์
|
209 |
const spawnPosition = new THREE.Vector3(
|
210 |
-
(Math.random() - 0.5) * (MAP_SIZE * 0.8),
|
211 |
-
TANK_HEIGHT,
|
212 |
(Math.random() - 0.5) * (MAP_SIZE * 0.8)
|
213 |
);
|
214 |
|
215 |
this.body.position.copy(spawnPosition);
|
216 |
|
217 |
-
// ํญ๋ฐ ์ดํํธ ๋ฉ์๋ ์ถ๊ฐ
|
218 |
-
this.createExplosionEffect = (scene, position) => {
|
219 |
-
// ํญ๋ฐ ํํฐํด
|
220 |
-
for (let i = 0; i < 15; i++) {
|
221 |
-
const size = Math.random() * 0.2 + 0.1;
|
222 |
-
const geometry = new THREE.SphereGeometry(size);
|
223 |
-
const material = new THREE.MeshBasicMaterial({
|
224 |
-
color: Math.random() < 0.5 ? 0xff4500 : 0xff8c00
|
225 |
-
});
|
226 |
-
const particle = new THREE.Mesh(geometry, material);
|
227 |
-
particle.position.copy(position);
|
228 |
-
|
229 |
-
const speed = Math.random() * 0.3 + 0.2;
|
230 |
-
const angle = Math.random() * Math.PI * 2;
|
231 |
-
const elevation = Math.random() * Math.PI - Math.PI / 2;
|
232 |
-
|
233 |
-
particle.velocity = new THREE.Vector3(
|
234 |
-
Math.cos(angle) * Math.cos(elevation) * speed,
|
235 |
-
Math.sin(elevation) * speed,
|
236 |
-
Math.sin(angle) * Math.cos(elevation) * speed
|
237 |
-
);
|
238 |
-
|
239 |
-
particle.gravity = -0.01;
|
240 |
-
particle.life = Math.random() * 20 + 20;
|
241 |
-
particle.fadeRate = 1 / particle.life;
|
242 |
-
|
243 |
-
scene.add(particle);
|
244 |
-
window.gameInstance.particles.push({
|
245 |
-
mesh: particle,
|
246 |
-
velocity: particle.velocity,
|
247 |
-
gravity: particle.gravity,
|
248 |
-
life: particle.life,
|
249 |
-
fadeRate: particle.fadeRate
|
250 |
-
});
|
251 |
-
}
|
252 |
-
|
253 |
-
// ์ถฉ๋ ์ฌ์ด๋ ์ฌ์
|
254 |
-
const explosionSound = new Audio('sounds/explosion.ogg');
|
255 |
-
explosionSound.volume = 0.3;
|
256 |
-
explosionSound.play();
|
257 |
-
};
|
258 |
-
|
259 |
scene.add(this.body);
|
260 |
this.isLoaded = true;
|
261 |
this.updateAmmoDisplay();
|
|
|
160 |
|
161 |
async initialize(scene, loader) {
|
162 |
try {
|
163 |
+
// ๊ทธ๋ฆผ์ ํ๋ฉด ๋จผ์ ์์ฑ
|
164 |
+
const shadowPlaneGeometry = new THREE.PlaneGeometry(8, 8);
|
165 |
+
const shadowPlaneMaterial = new THREE.ShadowMaterial({
|
166 |
+
opacity: 0.3
|
167 |
+
});
|
168 |
+
this.shadowPlane = new THREE.Mesh(shadowPlaneGeometry, shadowPlaneMaterial);
|
169 |
+
this.shadowPlane.receiveShadow = true;
|
170 |
+
this.shadowPlane.rotation.x = -Math.PI / 2;
|
171 |
+
|
172 |
const bodyResult = await loader.loadAsync('/models/abramsBody.glb');
|
173 |
this.body = bodyResult.scene;
|
174 |
|
|
|
178 |
this.turretGroup.position.y = 0.2;
|
179 |
this.turretGroup.add(this.turret);
|
180 |
this.body.add(this.turretGroup);
|
181 |
+
|
182 |
// ํฑํฌ ์์น ๋์ด ์กฐ์
|
183 |
+
this.body.position.y = 1.5;
|
184 |
|
185 |
+
// ๊ทธ๋ฆผ์ ํ๋ฉด ์์น ์กฐ์ (body๊ฐ ์์ฑ๋ ํ์)
|
186 |
this.shadowPlane.position.y = -1.0;
|
187 |
+
this.body.add(this.shadowPlane);
|
188 |
|
189 |
+
// ๊ทธ๋ฆผ์ ์ค์
|
190 |
this.body.traverse((child) => {
|
191 |
if (child.isMesh) {
|
192 |
child.castShadow = true;
|
|
|
205 |
}
|
206 |
});
|
207 |
|
208 |
+
// ์คํฐ ์์น ์ค์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
const spawnPosition = new THREE.Vector3(
|
210 |
+
(Math.random() - 0.5) * (MAP_SIZE * 0.8),
|
211 |
+
TANK_HEIGHT,
|
212 |
(Math.random() - 0.5) * (MAP_SIZE * 0.8)
|
213 |
);
|
214 |
|
215 |
this.body.position.copy(spawnPosition);
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
scene.add(this.body);
|
218 |
this.isLoaded = true;
|
219 |
this.updateAmmoDisplay();
|