Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -19,7 +19,7 @@ const GAME_CONSTANTS = {
|
|
19 |
ENEMY_COUNT: 4,
|
20 |
MISSILE_COUNT: 6,
|
21 |
AMMO_COUNT: 940, // 940๋ฐ๋ก ๋ณ๊ฒฝ
|
22 |
-
BULLET_DAMAGE: 50, // ๋ฐ๋น
|
23 |
MAX_HEALTH: 1000 // ์ฒด๋ ฅ 1000
|
24 |
};
|
25 |
|
@@ -311,427 +311,489 @@ class Fighter {
|
|
311 |
this.targetYaw += deltaTime * 1.2;
|
312 |
}
|
313 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
let abnormalG = 0;
|
388 |
-
|
389 |
-
// ๋ค์งํ ์ํ (๋กค์ด 90๋ ์ด์)
|
390 |
-
const isInverted = Math.abs(this.rotation.z) > Math.PI / 2;
|
391 |
-
if (isInverted) {
|
392 |
-
const baseG = 3.0 + Math.abs(Math.abs(this.rotation.z) - Math.PI / 2) * 2;
|
393 |
-
abnormalG += baseG * altitudeMultiplier * (1 + throttleGMultiplier); // ์ค๋กํ ๋ฐฐ์จ ์ถ๊ฐ
|
394 |
-
}
|
395 |
-
|
396 |
-
// ๋กค์ด ยฑ30๋ ์ด์์ผ ๋ ์ถ๊ฐ G-Force
|
397 |
-
const rollDegrees = Math.abs(this.rotation.z) * (180 / Math.PI);
|
398 |
-
if (rollDegrees > 30) {
|
399 |
-
// 30๋ ์ด๊ณผ๋ถ๋น 0.1G ์ถ๊ฐ
|
400 |
-
const extremeRollG = (rollDegrees - 30) * 0.1;
|
401 |
-
abnormalG += extremeRollG * altitudeMultiplier * (1 + throttleGMultiplier);
|
402 |
-
}
|
403 |
-
|
404 |
-
// ํผ์น ๊ฐ๋๊ฐ ยฑ40๋ ์ด์์ผ ๋ ์ถ๊ฐ G-Force
|
405 |
-
if (pitchDegrees >= 40) {
|
406 |
-
// 40๋ ์ด์์ผ ๋ ๊ธ๊ฒฉํ G-Force ์ฆ๊ฐ
|
407 |
-
const extremePitchG = (pitchDegrees - 40) * 0.15; // 40๋ ์ด๊ณผ๋ถ๋น 0.15G ์ถ๊ฐ
|
408 |
-
abnormalG += extremePitchG * altitudeMultiplier * (1 + throttleGMultiplier);
|
409 |
-
}
|
410 |
-
|
411 |
-
// ๊ธฐ์๊ฐ ๊ณ์ ์๋ฅผ ํฅํ๊ณ ์๋ ๊ฒฝ์ฐ (ํผ์น๊ฐ -30๋ ์ดํ)
|
412 |
-
if (pitchAngle < -Math.PI / 6) {
|
413 |
-
const baseG = 2.0 + Math.abs(pitchAngle + Math.PI / 6) * 3;
|
414 |
-
abnormalG += baseG * altitudeMultiplier * (1 + throttleGMultiplier); // ์ค๋กํ ๋ฐฐ์จ ์ถ๊ฐ
|
415 |
-
}
|
416 |
-
|
417 |
-
// ๊ธฐ์๊ฐ ๊ณผ๋ํ๊ฒ ์๋๋ฅผ ํฅํ๊ณ ์๋ ๊ฒฝ์ฐ (ํผ์น๊ฐ 60๋ ์ด์)
|
418 |
-
if (pitchAngle > Math.PI / 3) {
|
419 |
-
const baseG = 2.0 + Math.abs(pitchAngle - Math.PI / 3) * 3;
|
420 |
-
abnormalG += baseG * altitudeMultiplier * (1 + throttleGMultiplier); // ์ค๋กํ ๋ฐฐ์จ ์ถ๊ฐ
|
421 |
-
}
|
422 |
-
|
423 |
-
// ๊ธ๊ฒฉํ ๊ธฐ๋์ ์ํ G-Force
|
424 |
-
const maneuverG = (turnRate + pitchRate + (Math.abs(this.rotation.z) * 3)) * (1 + throttleGMultiplier * 0.5);
|
425 |
-
|
426 |
-
// ์ด G-Force ๊ณ์ฐ
|
427 |
-
this.gForce = 1.0 + maneuverG + abnormalG;
|
428 |
-
|
429 |
-
// G-Force ํ๋ณต ์กฐ๊ฑด ์์
|
430 |
-
// 1. Over-G ์ํ๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ํ๋ณต
|
431 |
-
// 2. ํผ์น๊ฐ ยฑ10๋ ์ด๋ด์ผ ๋๋ง ํ๋ณต
|
432 |
-
// 3. ์คํจ ์ํ๊ฐ ์๋ ๋๋ง ํ๋ณต
|
433 |
-
const isPitchNeutral = Math.abs(pitchDegrees) <= 10;
|
434 |
-
|
435 |
-
if (!this.overG && isPitchNeutral && !isInverted && !this.stallWarning) {
|
436 |
-
// ์ค๋กํ์ด ๋์์๋ก G-Force๊ฐ ์ฒ์ฒํ ๊ฐ์
|
437 |
-
const recoveryRate = 2.0 - throttleGMultiplier * 1.5; // THR 100%์ผ ๋ 0.5, THR 50%์ผ ๋ 2.0
|
438 |
-
this.gForce = THREE.MathUtils.lerp(this.gForce, 1.0 + maneuverG, deltaTime * recoveryRate);
|
439 |
-
} else if (this.overG) {
|
440 |
-
// Over-G ์ํ์์๋ ํผ์น๊ฐ 0๋ ๊ทผ์ฒ(ยฑ10๋)๊ฐ ๋๊ณ ์คํจ์ด ํ๋ณต๋ ๋๊น์ง ํ๋ณตํ์ง ์์
|
441 |
-
if (!isPitchNeutral || this.stallWarning) {
|
442 |
-
// ํผ์น๊ฐ ์ค๋ฆฝ์ด ์๋๊ฑฐ๋ ์คํจ ์ํ๋ฉด G-Force ์ ์ง ๋๋ ์ฆ๊ฐ๋ง ๊ฐ๋ฅ
|
443 |
-
this.gForce = Math.max(this.gForce, 1.0 + maneuverG + abnormalG);
|
444 |
-
} else {
|
445 |
-
// ํผ์น๊ฐ ์ค๋ฆฝ์ด๊ณ ์คํจ์ด ์๋ ๋๋ง ๋งค์ฐ ์ฒ์ฒํ ํ๋ณต
|
446 |
-
const overGRecoveryRate = 0.3 - throttleGMultiplier * 0.2; // Over-G ์ํ์์๋ ๋ ๋๋ฆฐ ํ๋ณต
|
447 |
-
this.gForce = THREE.MathUtils.lerp(this.gForce, 1.0 + maneuverG, deltaTime * overGRecoveryRate);
|
448 |
-
}
|
449 |
-
}
|
450 |
-
|
451 |
-
// ์คํจ ์ํ์์๋ Over-G๊ฐ ๊ฐ์ํ์ง ์๋๋ก ์ถ๊ฐ ์ฒ๋ฆฌ
|
452 |
-
if (this.stallWarning && this.overG) {
|
453 |
-
// ์คํจ ์ค์๋ G-Force๋ฅผ 9.0 ์ด์์ผ๋ก ์ ์ง
|
454 |
-
this.gForce = Math.max(this.gForce, 9.0);
|
455 |
-
}
|
456 |
-
|
457 |
-
this.overG = this.gForce > this.maxGForce;
|
458 |
-
|
459 |
-
// Over-G ํ์ด๋จธ ์
๋ฐ์ดํธ
|
460 |
-
if (this.overG) {
|
461 |
-
this.overGTimer += deltaTime;
|
462 |
-
|
463 |
-
// 1.5์ด ์ด์ Over-G ์ํ์ผ ๊ฒฝ์ฐ ์์ผ ํ๋ฆผ ์์
|
464 |
-
if (this.overGTimer > 1.5) {
|
465 |
-
// ์๋ ๊ธ๊ฒฉํ ๊ฐ์ (2.5์ด๋ถํฐ)
|
466 |
-
if (this.overGTimer > 2.5) {
|
467 |
-
targetSpeed *= Math.max(0.3, 1 - (this.overGTimer - 2.5) * 0.3);
|
468 |
-
}
|
469 |
-
// ์์ผ ํ๋ฆผ ํจ๊ณผ๋ UI์์ ์ฒ๋ฆฌ (1.5์ด๋ถํฐ)
|
470 |
-
}
|
471 |
-
} else {
|
472 |
-
this.overGTimer = 0; // Over-G ์ํ๊ฐ ์๋๋ฉด ํ์ด๋จธ ๋ฆฌ์
|
473 |
-
}
|
474 |
-
|
475 |
-
// ์คํจ ๊ฒฝ๊ณ : 300kt ์ดํ์์ ์คํจ ์ํ
|
476 |
-
const speedKnots = this.speed * 1.94384; // m/s to knots
|
477 |
-
const wasStalling = this.stallWarning;
|
478 |
-
|
479 |
-
// ์คํจ ์ง์
์กฐ๊ฑด
|
480 |
-
if (!this.stallWarning && speedKnots < GAME_CONSTANTS.STALL_SPEED) {
|
481 |
-
this.stallWarning = true;
|
482 |
-
this.stallEscapeProgress = 0; // ์คํจ ์ง์
์ ์งํ๋ ์ด๊ธฐํ
|
483 |
-
}
|
484 |
-
|
485 |
-
// ์คํจ ํ์ถ ์กฐ๊ฑด
|
486 |
-
if (this.stallWarning) {
|
487 |
-
if (this.escapeKeyPressed) {
|
488 |
-
// Fํค๋ฅผ ๋๋ฅด๊ณ ์์ผ๋ฉด ์งํ๋ ์ฆ๊ฐ
|
489 |
-
this.stallEscapeProgress += deltaTime;
|
490 |
-
|
491 |
-
// 2์ด ์ด์ ๋๋ฅด๋ฉด ์คํจ์์ ํ์ถ
|
492 |
-
if (this.stallEscapeProgress >= 2.0 && speedKnots >= 350) {
|
493 |
-
this.stallWarning = false;
|
494 |
-
this.stallEscapeProgress = 0;
|
495 |
-
// ์คํจ์์ ๋ฒ์ด๋๋ฉด ์์ธ๋ฅผ ์ฝ๊ฐ ์์ ํ
|
496 |
-
this.targetPitch = Math.max(-0.2, Math.min(0.2, this.targetPitch));
|
497 |
-
}
|
498 |
-
} else {
|
499 |
-
// Fํค๋ฅผ ๋์ผ๋ฉด ์งํ๋ ๊ฐ์
|
500 |
-
this.stallEscapeProgress = Math.max(0, this.stallEscapeProgress - deltaTime * 2);
|
501 |
-
}
|
502 |
-
}
|
503 |
-
|
504 |
-
// ์๋ ๋ณํ ์ ์ฉ
|
505 |
-
if (this.stallWarning) {
|
506 |
-
// ์คํจ ์ํ์์์ ์๋ ๋ณํ
|
507 |
-
if (pitchAngle > 0.1) { // ๊ธฐ์๊ฐ ์๋๋ฅผ ํฅํ ๋
|
508 |
-
// ๋ค์ด๋น์ผ๋ก ์ธํ ์๋ ์ฆ๊ฐ
|
509 |
-
const diveSpeedGain = Math.min(pitchAngle * 300, 200); // ์ต๋ 200m/s ์ฆ๊ฐ
|
510 |
-
this.speed = Math.min(maxSpeed, this.speed + diveSpeedGain * deltaTime);
|
511 |
-
} else {
|
512 |
-
// ๊ธฐ์๊ฐ ์๋ฅผ ํฅํ๊ฑฐ๋ ์ํ์ผ ๋๋ ์๋ ๊ฐ์
|
513 |
-
this.speed = Math.max(0, this.speed - deltaTime * 100);
|
514 |
-
}
|
515 |
-
} else {
|
516 |
-
// ์ ์ ๋นํ ์ ์๋ ๋ณํ
|
517 |
-
this.speed = THREE.MathUtils.lerp(this.speed, targetSpeed, deltaTime * 0.5);
|
518 |
-
}
|
519 |
-
|
520 |
-
// ์คํจ ์ํ์์์ ๋ฌผ๋ฆฌ ํจ๊ณผ
|
521 |
-
if (this.stallWarning) {
|
522 |
-
// ๋ฐ๋ฅ์ผ๋ก ์ถ๋ฝํ๋ฉฐ ๊ฐ์๋๊ฐ ๋น ๋ฅด๊ฒ ๋ถ์
|
523 |
-
this.targetPitch = Math.min(Math.PI / 2.5, this.targetPitch + deltaTime * 2.5); // ๊ธฐ์๊ฐ ๋ ๊ทน๋จ์ ์ผ๋ก ์๋๋ก (72๋๊น์ง)
|
524 |
-
|
525 |
-
// ์กฐ์ข
๋ถ๋ฅ ์ํ - ๋ ์ฌํ ํ๋ค๋ฆผ
|
526 |
-
this.rotation.x += (Math.random() - 0.5) * deltaTime * 0.8;
|
527 |
-
this.rotation.z += (Math.random() - 0.5) * deltaTime * 0.8;
|
528 |
-
|
529 |
-
// ์ค๋ ฅ์ ์ํ ๊ฐ์
|
530 |
-
const gravityAcceleration = GAME_CONSTANTS.GRAVITY * deltaTime * 3.0; // 3๋ฐฐ ์ค๋ ฅ
|
531 |
-
this.velocity.y -= gravityAcceleration;
|
532 |
-
}
|
533 |
-
|
534 |
-
// ์๋ ๋ฒกํฐ ๊ณ์ฐ - ๋งคํธ๋ฆญ์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ง๋ฒ ๋ฝ ํํผ
|
535 |
-
const noseDirection = new THREE.Vector3(0, 0, 1);
|
536 |
-
|
537 |
-
// ํ์ ๋งคํธ๋ฆญ์ค๋ฅผ ์ง์ ๊ตฌ์ฑํ์ฌ ์ ์ฉ
|
538 |
-
const rotationMatrix = new THREE.Matrix4();
|
539 |
-
rotationMatrix.makeRotationFromEuler(new THREE.Euler(this.rotation.x, this.rotation.y, this.rotation.z, 'YXZ'));
|
540 |
-
noseDirection.applyMatrix4(rotationMatrix);
|
541 |
-
|
542 |
-
if (!this.stallWarning) {
|
543 |
-
// ์ ์ ๋นํ ์
|
544 |
-
this.velocity = noseDirection.multiplyScalar(this.speed);
|
545 |
-
} else {
|
546 |
-
// ์คํจ ์์๋ ์ค๋ ฅ์ด ์ฃผ๋์ ์ด์ง๋ง ๋ค์ด๋น ์๋๋ ๋ฐ์
|
547 |
-
this.velocity.x = noseDirection.x * this.speed * 0.5; // ์ ๋ฐฉ ์๋ ์ฆ๊ฐ
|
548 |
-
this.velocity.z = noseDirection.z * this.speed * 0.5;
|
549 |
-
// y ์๋๋ ์์์ ์ค๋ ฅ์ผ๋ก ์ฒ๋ฆฌ๋จ
|
550 |
-
}
|
551 |
-
|
552 |
-
// ์ ์ ๋นํ ์ ์ค๋ ฅ ํจ๊ณผ
|
553 |
-
if (!this.stallWarning) {
|
554 |
-
const gravityEffect = GAME_CONSTANTS.GRAVITY * deltaTime * 0.15;
|
555 |
-
this.velocity.y -= gravityEffect;
|
556 |
-
|
557 |
-
// ์๋ ฅ ํจ๊ณผ (์๋์ ๋น๋ก)
|
558 |
-
const liftFactor = (this.speed / maxSpeed) * 0.8;
|
559 |
-
const lift = gravityEffect * liftFactor;
|
560 |
-
this.velocity.y += lift;
|
561 |
-
}
|
562 |
-
|
563 |
-
// ์์น ์
๋ฐ์ดํธ
|
564 |
-
this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
|
565 |
-
|
566 |
-
// ์ง๋ฉด ์ถฉ๋
|
567 |
-
if (this.position.y <= GAME_CONSTANTS.MIN_ALTITUDE) {
|
568 |
-
this.position.y = GAME_CONSTANTS.MIN_ALTITUDE;
|
569 |
-
this.health = 0;
|
570 |
-
|
571 |
-
// ์ง๋ฉด ์ถฉ๋ ์ ํญ๋ฐ ํจ๊ณผ ์ถ๊ฐ
|
572 |
-
if (window.gameInstance) {
|
573 |
-
window.gameInstance.createExplosionEffect(this.position);
|
574 |
-
}
|
575 |
-
|
576 |
-
return;
|
577 |
-
}
|
578 |
-
|
579 |
-
// ์ต๋ ๊ณ ๋ ์ ํ
|
580 |
-
if (this.position.y > GAME_CONSTANTS.MAX_ALTITUDE) {
|
581 |
-
this.position.y = GAME_CONSTANTS.MAX_ALTITUDE;
|
582 |
-
this.altitudeWarning = true;
|
583 |
-
if (this.velocity.y > 0) this.velocity.y = 0;
|
584 |
-
} else {
|
585 |
-
this.altitudeWarning = false;
|
586 |
-
}
|
587 |
-
|
588 |
-
// ๋งต ๊ฒฝ๊ณ ์ฒ๋ฆฌ
|
589 |
-
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
590 |
-
if (this.position.x > mapLimit) this.position.x = -mapLimit;
|
591 |
-
if (this.position.x < -mapLimit) this.position.x = mapLimit;
|
592 |
-
if (this.position.z > mapLimit) this.position.z = -mapLimit;
|
593 |
-
if (this.position.z < -mapLimit) this.position.z = mapLimit;
|
594 |
-
|
595 |
-
// ๋ฉ์ ์์น ๋ฐ ํ์ ์
๋ฐ์ดํธ
|
596 |
-
this.mesh.position.copy(this.position);
|
597 |
-
this.mesh.rotation.x = this.rotation.x;
|
598 |
-
this.mesh.rotation.y = this.rotation.y + 3 * Math.PI / 2;
|
599 |
-
this.mesh.rotation.z = this.rotation.z;
|
600 |
-
|
601 |
-
// ๊ฒฝ๊ณ ๊น๋นก์ ํ์ด๋จธ
|
602 |
-
this.warningBlinkTimer += deltaTime;
|
603 |
-
if (this.warningBlinkTimer >= 1.0) {
|
604 |
-
this.warningBlinkTimer = 0;
|
605 |
-
this.warningBlinkState = !this.warningBlinkState;
|
606 |
-
}
|
607 |
-
|
608 |
-
// ๊ณ ๋ ๊ณ์ฐ
|
609 |
-
this.altitude = this.position.y;
|
610 |
-
|
611 |
-
// ๊ฒฝ๊ณ ์ ์
๋ฐ์ดํธ (์์ง ์๋ฆฌ๋ ๊ณ์ ์ ์ง)
|
612 |
-
this.updateWarningAudios();
|
613 |
-
|
614 |
-
// ์์ง ์๋ฆฌ ๋ณผ๋ฅจ์ ์ค๋กํ์ ์ฐ๋
|
615 |
-
if (this.warningAudios.normal && !this.warningAudios.normal.paused) {
|
616 |
-
this.warningAudios.normal.volume = 0.3 + this.throttle * 0.4; // 0.3~0.7
|
617 |
-
}
|
618 |
-
}
|
619 |
-
|
620 |
-
shoot(scene) {
|
621 |
-
// ํ์ฝ์ด ์์ผ๋ฉด ๋ฐ์ฌํ์ง ์์
|
622 |
-
if (this.ammo <= 0) return;
|
623 |
-
|
624 |
-
this.ammo--;
|
625 |
-
|
626 |
-
// ์ง์ ๋ชจ์์ ํํ (100% ๋ ํฌ๊ฒ)
|
627 |
-
const bulletGeometry = new THREE.CylinderGeometry(1.0, 1.0, 16, 8); // ๋ฐ์ง๋ฆ 0.75โ1.0, ๊ธธ์ด 12โ16
|
628 |
-
const bulletMaterial = new THREE.MeshBasicMaterial({
|
629 |
-
color: 0xffff00,
|
630 |
-
emissive: 0xffff00,
|
631 |
-
emissiveIntensity: 1.0
|
632 |
-
});
|
633 |
-
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
634 |
-
|
635 |
-
// ๊ธฐ์ ๋์์ ๋ฐ์ฌ (๋ ์์ชฝ์์)
|
636 |
-
const muzzleOffset = new THREE.Vector3(0, 0, 10);
|
637 |
-
const rotationMatrix = new THREE.Matrix4();
|
638 |
-
rotationMatrix.makeRotationFromEuler(new THREE.Euler(this.rotation.x, this.rotation.y, this.rotation.z, 'YXZ'));
|
639 |
-
muzzleOffset.applyMatrix4(rotationMatrix);
|
640 |
-
bullet.position.copy(this.position).add(muzzleOffset);
|
641 |
-
|
642 |
-
// ํํ์ ๋ฐ์ฌ ๋ฐฉํฅ์ผ๋ก ํ์
|
643 |
-
bullet.rotation.copy(this.rotation);
|
644 |
-
bullet.rotateX(Math.PI / 2); // ์ค๋ฆฐ๋๊ฐ Z์ถ ๋ฐฉํฅ์ ํฅํ๋๋ก
|
645 |
-
|
646 |
-
// ํํ ์ด๊ธฐ ์์น ์ ์ฅ
|
647 |
-
bullet.startPosition = bullet.position.clone();
|
648 |
-
|
649 |
-
const bulletSpeed = 1500; // 1000์์ 1500์ผ๋ก ์ฆ๊ฐ (50% ๋น ๋ฅด๊ฒ)
|
650 |
-
const direction = new THREE.Vector3(0, 0, 1);
|
651 |
-
direction.applyMatrix4(rotationMatrix);
|
652 |
-
bullet.velocity = direction.multiplyScalar(bulletSpeed);
|
653 |
-
|
654 |
-
scene.add(bullet);
|
655 |
-
this.bullets.push(bullet);
|
656 |
-
|
657 |
-
// m134.ogg ์๋ฆฌ ์ฌ์ - ์ค์ฒฉ ์ ํ ํด์ , ๋๋ค ํผ์น
|
658 |
-
try {
|
659 |
-
const audio = new Audio('sounds/m134.ogg');
|
660 |
-
audio.volume = 0.15; // 0.3์์ 0.15๋ก ๊ฐ์ (50% ์ค์)
|
661 |
-
|
662 |
-
// -2 ~ +2 ์ฌ์ด์ ๋๋ค ํผ์น (playbackRate๋ก ์๋ฎฌ๋ ์ด์
)
|
663 |
-
const randomPitch = 0.8 + Math.random() * 0.4; // 0.8 ~ 1.2 ๋ฒ์
|
664 |
-
audio.playbackRate = randomPitch;
|
665 |
-
|
666 |
-
audio.play().catch(e => console.log('Gunfire sound failed to play'));
|
667 |
-
|
668 |
-
// ์ฌ์ ์๋ฃ ์ ๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ๋ฅผ ์ํด ์ฐธ์กฐ ์ ๊ฑฐ
|
669 |
-
audio.addEventListener('ended', () => {
|
670 |
-
audio.remove();
|
671 |
-
});
|
672 |
-
} catch (e) {
|
673 |
-
console.log('Audio error:', e);
|
674 |
-
}
|
675 |
-
}
|
676 |
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
726 |
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
}
|
736 |
|
737 |
// ์ ์ ํฌ๊ธฐ ํด๋์ค - ์์ ํ ์ฌ์ค๊ณ
|
|
|
19 |
ENEMY_COUNT: 4,
|
20 |
MISSILE_COUNT: 6,
|
21 |
AMMO_COUNT: 940, // 940๋ฐ๋ก ๋ณ๊ฒฝ
|
22 |
+
BULLET_DAMAGE: 50, // ๋ฐ๋น 50 ๋ฐ๋ฏธ์ง
|
23 |
MAX_HEALTH: 1000 // ์ฒด๋ ฅ 1000
|
24 |
};
|
25 |
|
|
|
311 |
this.targetYaw += deltaTime * 1.2;
|
312 |
}
|
313 |
}
|
314 |
+
updatePhysics(deltaTime) {
|
315 |
+
if (!this.mesh) return;
|
316 |
+
|
317 |
+
// ๋ถ๋๋ฌ์ด ํ์ ๋ณด๊ฐ
|
318 |
+
const rotationSpeed = deltaTime * 2.0;
|
319 |
+
const yawRotationSpeed = deltaTime * 3.0;
|
320 |
+
|
321 |
+
// ํผ์น์ ๋กค์ ์ง์ ๋ณด๊ฐ
|
322 |
+
this.rotation.x = THREE.MathUtils.lerp(this.rotation.x, this.targetPitch, rotationSpeed);
|
323 |
+
this.rotation.z = THREE.MathUtils.lerp(this.rotation.z, this.targetRoll, rotationSpeed * 1.5);
|
324 |
+
|
325 |
+
// Yaw ๋ณด๊ฐ (์ต๋จ ๊ฒฝ๋ก)
|
326 |
+
let yawDiff = this.normalizeAngle(this.targetYaw - this.rotation.y);
|
327 |
+
this.rotation.y += yawDiff * yawRotationSpeed;
|
328 |
+
|
329 |
+
// rotation.y๋ฅผ -ฯ ~ ฯ ๋ฒ์๋ก ์ ์ง
|
330 |
+
this.rotation.y = this.normalizeAngle(this.rotation.y);
|
331 |
+
this.targetYaw = this.normalizeAngle(this.targetYaw);
|
332 |
+
|
333 |
+
// ๋กค ์๋ ๋ณต๊ท ์์คํ
|
334 |
+
if (Math.abs(yawDiff) < 0.05) {
|
335 |
+
// ์ ํ์ ์ด ๊ฑฐ์ ์์ ๋ ๋กค์ 0์ผ๋ก ๋ณต๊ท
|
336 |
+
this.targetRoll *= 0.95;
|
337 |
+
}
|
338 |
+
|
339 |
+
// ์์ฌ๋ ์คํ์ผ: ์ ํ์ ์ด ์ฃผ๋์ , ๋กค์ ๋ณด์กฐ์
|
340 |
+
let bankTurnRate = 0;
|
341 |
+
if (Math.abs(this.rotation.z) > 0.3) { // ๋กค์ด ์ถฉ๋ถํ ํด ๋๋ง
|
342 |
+
const bankAngle = this.rotation.z;
|
343 |
+
bankTurnRate = Math.sin(bankAngle) * deltaTime * 0.1; // ๋งค์ฐ ์์ ์ ํ์จ
|
344 |
+
this.targetYaw += bankTurnRate;
|
345 |
+
}
|
346 |
+
|
347 |
+
// ํ์ค์ ์ธ ์๋ ๊ณ์ฐ
|
348 |
+
const minSpeed = 0; // ์ต์ ์๋ 0kt
|
349 |
+
const maxSpeed = 600; // ์ต๋ ์๋ 600kt
|
350 |
+
let targetSpeed = minSpeed + (maxSpeed - minSpeed) * this.throttle;
|
351 |
+
|
352 |
+
// ํผ์น ๊ฐ๋์ ๋ฐ๋ฅธ ์๋ ๋ณํ
|
353 |
+
const pitchAngle = this.rotation.x;
|
354 |
+
const pitchDegrees = Math.abs(pitchAngle) * (180 / Math.PI);
|
355 |
+
|
356 |
+
// ๊ธฐ์๊ฐ ์๋ฅผ ํฅํ๊ณ ์์ ๊ฒฝ์ฐ ๋น ๋ฅธ ์๋ ๊ฐ์
|
357 |
+
if (pitchAngle < -0.1 && !this.stallWarning) { // ์คํจ์ด ์๋ ๋๋ง ์์น์ผ๋ก ์ธํ ๊ฐ์
|
358 |
+
const climbFactor = Math.abs(pitchAngle) / (Math.PI / 2); // 90๋ ๊ธฐ์ค
|
359 |
+
if (pitchDegrees > 30) { // 30๋ ์ด์์ผ ๋ ๊ธ๊ฒฉํ ๊ฐ์
|
360 |
+
targetSpeed *= Math.max(0, 1 - climbFactor * 1.5); // ์ต๋ 150% ๊ฐ์ (0kt๊น์ง)
|
361 |
+
} else {
|
362 |
+
targetSpeed *= (1 - climbFactor * 0.3); // ์ ์์ ์ธ ๊ฐ์
|
363 |
+
}
|
364 |
+
} else if (pitchAngle > 0.1) { // ๊ธฐ์๊ฐ ์๋๋ก (ํ๊ฐ) - ์คํจ ์ํ์์๋ ์ ์ฉ
|
365 |
+
const diveFactor = pitchAngle / (Math.PI / 3);
|
366 |
+
targetSpeed *= (1 + diveFactor * 0.4); // ํ๊ฐ ์ ๊ฐ์ ์ฆ๊ฐ (0.2 -> 0.4)
|
367 |
+
}
|
368 |
+
|
369 |
+
// G-Force ๊ณ์ฐ ๊ฐ์
|
370 |
+
const turnRate = Math.abs(bankTurnRate) * 100;
|
371 |
+
const pitchRate = Math.abs(this.rotation.x - this.targetPitch) * 10;
|
372 |
+
|
373 |
+
// ๊ณ ๋์ ๋ฐ๋ฅธ G-Force ์ฆ๊ฐ ๋ฐฐ์จ ๊ณ์ฐ
|
374 |
+
const altitudeInKm = this.position.y / 1000; // ๋ฏธํฐ๋ฅผ ํฌ๋ก๋ฏธํฐ๋ก ๋ณํ
|
375 |
+
const altitudeMultiplier = 1 + (altitudeInKm * 0.2); // 1km๋น 20% ์ฆ๊ฐ
|
376 |
+
|
377 |
+
// ์ค๋กํ์ ๋ฐ๋ฅธ G-Force ์ฆ๊ฐ ๋ฐฐ์จ ๊ณ์ฐ
|
378 |
+
// THR 50% ์ดํ: 0๋ฐฐ, THR 75%: 0.5๋ฐฐ, THR 100%: 1.0๋ฐฐ
|
379 |
+
let throttleGMultiplier = 0;
|
380 |
+
if (this.throttle > 0.5) {
|
381 |
+
// 0.5 ~ 1.0 ๋ฒ์๋ฅผ 0 ~ 1.0์ผ๋ก ๋งคํ
|
382 |
+
throttleGMultiplier = (this.throttle - 0.5) * 2.0;
|
383 |
+
}
|
384 |
+
|
385 |
+
// ๋น์ ์์ ์ธ ์์ธ์ ์ํ G-Force ์ถ๊ฐ
|
386 |
+
let abnormalG = 0;
|
387 |
+
|
388 |
+
// ๋ค์งํ ์ํ (๋กค์ด 90๋ ์ด์)
|
389 |
+
const isInverted = Math.abs(this.rotation.z) > Math.PI / 2;
|
390 |
+
if (isInverted) {
|
391 |
+
const baseG = 3.0 + Math.abs(Math.abs(this.rotation.z) - Math.PI / 2) * 2;
|
392 |
+
abnormalG += baseG * altitudeMultiplier * (1 + throttleGMultiplier); // ์ค๋กํ ๋ฐฐ์จ ์ถ๊ฐ
|
393 |
+
}
|
394 |
+
|
395 |
+
// ๋กค์ด ยฑ30๋ ์ด์์ผ ๋ ์ถ๊ฐ G-Force
|
396 |
+
const rollDegrees = Math.abs(this.rotation.z) * (180 / Math.PI);
|
397 |
+
if (rollDegrees > 30) {
|
398 |
+
// 30๋ ์ด๊ณผ๋ถ๋น 0.1G ์ถ๊ฐ
|
399 |
+
const extremeRollG = (rollDegrees - 30) * 0.1;
|
400 |
+
abnormalG += extremeRollG * altitudeMultiplier * (1 + throttleGMultiplier);
|
401 |
+
}
|
402 |
+
|
403 |
+
// ํผ์น ๊ฐ๋๊ฐ ยฑ40๋ ์ด์์ผ ๋ ์ถ๊ฐ G-Force
|
404 |
+
if (pitchDegrees >= 40) {
|
405 |
+
// 40๋ ์ด์์ผ ๋ ๊ธ๊ฒฉํ G-Force ์ฆ๊ฐ
|
406 |
+
const extremePitchG = (pitchDegrees - 40) * 0.15; // 40๋ ์ด๊ณผ๋ถ๋น 0.15G ์ถ๊ฐ
|
407 |
+
abnormalG += extremePitchG * altitudeMultiplier * (1 + throttleGMultiplier);
|
408 |
+
}
|
409 |
+
|
410 |
+
// ๊ธฐ์๊ฐ ๊ณ์ ์๋ฅผ ํฅํ๊ณ ์๋ ๊ฒฝ์ฐ (ํผ์น๊ฐ -30๋ ์ดํ)
|
411 |
+
if (pitchAngle < -Math.PI / 6) {
|
412 |
+
const baseG = 2.0 + Math.abs(pitchAngle + Math.PI / 6) * 3;
|
413 |
+
abnormalG += baseG * altitudeMultiplier * (1 + throttleGMultiplier); // ์ค๋กํ ๋ฐฐ์จ ์ถ๊ฐ
|
414 |
+
}
|
415 |
+
|
416 |
+
// ๊ธฐ์๊ฐ ๊ณผ๋ํ๊ฒ ์๋๋ฅผ ํฅํ๊ณ ์๋ ๊ฒฝ์ฐ (ํผ์น๊ฐ 60๋ ์ด์)
|
417 |
+
if (pitchAngle > Math.PI / 3) {
|
418 |
+
const baseG = 2.0 + Math.abs(pitchAngle - Math.PI / 3) * 3;
|
419 |
+
abnormalG += baseG * altitudeMultiplier * (1 + throttleGMultiplier); // ์ค๋กํ ๋ฐฐ์จ ์ถ๊ฐ
|
420 |
+
}
|
421 |
+
|
422 |
+
// ๊ธ๊ฒฉํ ๊ธฐ๋์ ์ํ G-Force
|
423 |
+
const maneuverG = (turnRate + pitchRate + (Math.abs(this.rotation.z) * 3)) * (1 + throttleGMultiplier * 0.5);
|
424 |
+
|
425 |
+
// ์ด G-Force ๊ณ์ฐ
|
426 |
+
this.gForce = 1.0 + maneuverG + abnormalG;
|
427 |
+
|
428 |
+
// G-Force ํ๋ณต ์กฐ๊ฑด ์์
|
429 |
+
// 1. Over-G ์ํ๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ํ๋ณต
|
430 |
+
// 2. ํผ์น๊ฐ ยฑ10๋ ์ด๋ด์ผ ๋๋ง ํ๋ณต
|
431 |
+
// 3. ์คํจ ์ํ๊ฐ ์๋ ๋๋ง ํ๋ณต
|
432 |
+
const isPitchNeutral = Math.abs(pitchDegrees) <= 10;
|
433 |
+
|
434 |
+
if (!this.overG && isPitchNeutral && !isInverted && !this.stallWarning) {
|
435 |
+
// ์ค๋กํ์ด ๋์์๋ก G-Force๊ฐ ์ฒ์ฒํ ๊ฐ์
|
436 |
+
const recoveryRate = 2.0 - throttleGMultiplier * 1.5; // THR 100%์ผ ๋ 0.5, THR 50%์ผ ๋ 2.0
|
437 |
+
this.gForce = THREE.MathUtils.lerp(this.gForce, 1.0 + maneuverG, deltaTime * recoveryRate);
|
438 |
+
} else if (this.overG) {
|
439 |
+
// Over-G ์ํ์์๋ ํผ์น๊ฐ 0๋ ๊ทผ์ฒ(ยฑ10๋)๊ฐ ๋๊ณ ์คํจ์ด ํ๋ณต๋ ๋๊น์ง ํ๋ณตํ์ง ์์
|
440 |
+
if (!isPitchNeutral || this.stallWarning) {
|
441 |
+
// ํผ์น๊ฐ ์ค๋ฆฝ์ด ์๋๊ฑฐ๋ ์คํจ ์ํ๋ฉด G-Force ์ ์ง ๋๋ ์ฆ๊ฐ๋ง ๊ฐ๋ฅ
|
442 |
+
this.gForce = Math.max(this.gForce, 1.0 + maneuverG + abnormalG);
|
443 |
+
} else {
|
444 |
+
// ํผ์น๊ฐ ์ค๋ฆฝ์ด๊ณ ์คํจ์ด ์๋ ๋๋ง ๋งค์ฐ ์ฒ์ฒํ ํ๋ณต
|
445 |
+
const overGRecoveryRate = 0.3 - throttleGMultiplier * 0.2; // Over-G ์ํ์์๋ ๋ ๋๋ฆฐ ํ๋ณต
|
446 |
+
this.gForce = THREE.MathUtils.lerp(this.gForce, 1.0 + maneuverG, deltaTime * overGRecoveryRate);
|
447 |
+
}
|
448 |
+
}
|
449 |
+
|
450 |
+
// ์คํจ ์ํ์์๋ Over-G๊ฐ ๊ฐ์ํ์ง ์๋๋ก ์ถ๊ฐ ์ฒ๋ฆฌ
|
451 |
+
if (this.stallWarning && this.overG) {
|
452 |
+
// ์คํจ ์ค์๋ G-Force๋ฅผ 9.0 ์ด์์ผ๋ก ์ ์ง
|
453 |
+
this.gForce = Math.max(this.gForce, 9.0);
|
454 |
+
}
|
455 |
+
|
456 |
+
this.overG = this.gForce > this.maxGForce;
|
457 |
+
|
458 |
+
// Over-G ํ์ด๋จธ ์
๋ฐ์ดํธ
|
459 |
+
if (this.overG) {
|
460 |
+
this.overGTimer += deltaTime;
|
461 |
+
|
462 |
+
// 1.5์ด ์ด์ Over-G ์ํ์ผ ๊ฒฝ์ฐ ์์ผ ํ๋ฆผ ์์
|
463 |
+
if (this.overGTimer > 1.5) {
|
464 |
+
// ์๋ ๊ธ๊ฒฉํ ๊ฐ์ (2.5์ด๋ถํฐ)
|
465 |
+
if (this.overGTimer > 2.5) {
|
466 |
+
targetSpeed *= Math.max(0.3, 1 - (this.overGTimer - 2.5) * 0.3);
|
467 |
+
}
|
468 |
+
// ์์ผ ํ๋ฆผ ํจ๊ณผ๋ UI์์ ์ฒ๋ฆฌ (1.5์ด๋ถํฐ)
|
469 |
+
}
|
470 |
+
} else {
|
471 |
+
this.overGTimer = 0; // Over-G ์ํ๊ฐ ์๋๋ฉด ํ์ด๋จธ ๋ฆฌ์
|
472 |
+
}
|
473 |
+
|
474 |
+
// ์คํจ ๊ฒฝ๊ณ : 300kt ์ดํ์์ ์คํจ ์ํ
|
475 |
+
const speedKnots = this.speed * 1.94384; // m/s to knots
|
476 |
+
const wasStalling = this.stallWarning;
|
477 |
+
|
478 |
+
// ์คํจ ์ง์
์กฐ๊ฑด
|
479 |
+
if (!this.stallWarning && speedKnots < GAME_CONSTANTS.STALL_SPEED) {
|
480 |
+
this.stallWarning = true;
|
481 |
+
this.stallEscapeProgress = 0; // ์คํจ ์ง์
์ ์งํ๋ ์ด๊ธฐํ
|
482 |
+
}
|
483 |
+
|
484 |
+
// ์คํจ ํ์ถ ์กฐ๊ฑด
|
485 |
+
if (this.stallWarning) {
|
486 |
+
if (this.escapeKeyPressed) {
|
487 |
+
// Fํค๋ฅผ ๋๋ฅด๊ณ ์์ผ๋ฉด ์งํ๋ ์ฆ๊ฐ
|
488 |
+
this.stallEscapeProgress += deltaTime;
|
489 |
+
|
490 |
+
// 2์ด ์ด์ ๋๋ฅด๋ฉด ์คํจ์์ ํ์ถ
|
491 |
+
if (this.stallEscapeProgress >= 2.0 && speedKnots >= 350) {
|
492 |
+
this.stallWarning = false;
|
493 |
+
this.stallEscapeProgress = 0;
|
494 |
+
// ์คํจ์์ ๋ฒ์ด๋๋ฉด ์์ธ๋ฅผ ์ฝ๊ฐ ์์ ํ
|
495 |
+
this.targetPitch = Math.max(-0.2, Math.min(0.2, this.targetPitch));
|
496 |
+
}
|
497 |
+
} else {
|
498 |
+
// Fํค๋ฅผ ๋์ผ๋ฉด ์งํ๋ ๊ฐ์
|
499 |
+
this.stallEscapeProgress = Math.max(0, this.stallEscapeProgress - deltaTime * 2);
|
500 |
+
}
|
501 |
+
}
|
502 |
+
|
503 |
+
// ์๋ ๋ณํ ์ ์ฉ
|
504 |
+
if (this.stallWarning) {
|
505 |
+
// ์คํจ ์ํ์์์ ์๋ ๋ณํ
|
506 |
+
if (pitchAngle > 0.1) { // ๊ธฐ์๊ฐ ์๋๋ฅผ ํฅํ ๋
|
507 |
+
// ๋ค์ด๋น์ผ๋ก ์ธํ ์๋ ์ฆ๊ฐ
|
508 |
+
const diveSpeedGain = Math.min(pitchAngle * 300, 200); // ์ต๋ 200m/s ์ฆ๊ฐ
|
509 |
+
this.speed = Math.min(maxSpeed, this.speed + diveSpeedGain * deltaTime);
|
510 |
+
} else {
|
511 |
+
// ๊ธฐ์๊ฐ ์๋ฅผ ํฅํ๊ฑฐ๋ ์ํ์ผ ๋๋ ์๋ ๊ฐ์
|
512 |
+
this.speed = Math.max(0, this.speed - deltaTime * 100);
|
513 |
+
}
|
514 |
+
} else {
|
515 |
+
// ์ ์ ๋นํ ์ ์๋ ๋ณํ
|
516 |
+
this.speed = THREE.MathUtils.lerp(this.speed, targetSpeed, deltaTime * 0.5);
|
517 |
+
}
|
518 |
+
|
519 |
+
// ์คํจ ์ํ์์์ ๋ฌผ๋ฆฌ ํจ๊ณผ
|
520 |
+
if (this.stallWarning) {
|
521 |
+
// ๋ฐ๋ฅ์ผ๋ก ์ถ๋ฝํ๋ฉฐ ๊ฐ์๋๊ฐ ๋น ๋ฅด๊ฒ ๋ถ์
|
522 |
+
this.targetPitch = Math.min(Math.PI / 2.5, this.targetPitch + deltaTime * 2.5); // ๊ธฐ์๊ฐ ๋ ๊ทน๋จ์ ์ผ๋ก ์๋๋ก (72๋๊น์ง)
|
523 |
+
|
524 |
+
// ์กฐ์ข
๋ถ๋ฅ ์ํ - ๋ ์ฌํ ํ๋ค๋ฆผ
|
525 |
+
this.rotation.x += (Math.random() - 0.5) * deltaTime * 0.8;
|
526 |
+
this.rotation.z += (Math.random() - 0.5) * deltaTime * 0.8;
|
527 |
+
|
528 |
+
// ์ค๋ ฅ์ ์ํ ๊ฐ์
|
529 |
+
const gravityAcceleration = GAME_CONSTANTS.GRAVITY * deltaTime * 3.0; // 3๋ฐฐ ์ค๋ ฅ
|
530 |
+
this.velocity.y -= gravityAcceleration;
|
531 |
+
}
|
532 |
+
// ์๋ ๋ฒกํฐ ๊ณ์ฐ - ์ฟผํฐ๋์ธ์ ์ฌ์ฉํ์ฌ ์ง๋ฒ ๋ฝ ์์ ํํผ
|
533 |
+
const noseDirection = new THREE.Vector3(0, 0, 1);
|
534 |
+
|
535 |
+
// ์ฟผํฐ๋์ธ ๊ธฐ๋ฐ ํ์ ์์คํ
|
536 |
+
const quaternion = new THREE.Quaternion();
|
537 |
+
|
538 |
+
// ๊ฐ ์ถ์ ํ์ ์ ๊ฐ๋ณ ์ฟผํฐ๋์ธ์ผ๋ก ์์ฑ
|
539 |
+
const pitchQuat = new THREE.Quaternion();
|
540 |
+
const yawQuat = new THREE.Quaternion();
|
541 |
+
const rollQuat = new THREE.Quaternion();
|
542 |
+
|
543 |
+
// ์ถ ๋ฒกํฐ ์ ์
|
544 |
+
const xAxis = new THREE.Vector3(1, 0, 0);
|
545 |
+
const yAxis = new THREE.Vector3(0, 1, 0);
|
546 |
+
const zAxis = new THREE.Vector3(0, 0, 1);
|
547 |
+
|
548 |
+
// ๊ฐ ์ถ์ ๋ํ ํ์ ์ค์
|
549 |
+
pitchQuat.setFromAxisAngle(xAxis, this.rotation.x);
|
550 |
+
yawQuat.setFromAxisAngle(yAxis, this.rotation.y);
|
551 |
+
rollQuat.setFromAxisAngle(zAxis, this.rotation.z);
|
552 |
+
|
553 |
+
// ์ฟผํฐ๋์ธ ํฉ์ฑ (ํญ๊ณต๊ธฐ ํ์ค ์์: Yaw -> Pitch -> Roll)
|
554 |
+
quaternion.multiply(yawQuat);
|
555 |
+
quaternion.multiply(pitchQuat);
|
556 |
+
quaternion.multiply(rollQuat);
|
557 |
+
|
558 |
+
// ๋ฐฉํฅ ๋ฒกํฐ์ ํ์ ์ ์ฉ
|
559 |
+
noseDirection.applyQuaternion(quaternion);
|
560 |
+
|
561 |
+
if (!this.stallWarning) {
|
562 |
+
// ์ ์ ๋นํ ์
|
563 |
+
this.velocity = noseDirection.multiplyScalar(this.speed);
|
564 |
+
} else {
|
565 |
+
// ์คํจ ์์๋ ์ค๋ ฅ์ด ์ฃผ๋์ ์ด์ง๋ง ๋ค์ด๋น ์๋๋ ๋ฐ์
|
566 |
+
this.velocity.x = noseDirection.x * this.speed * 0.5; // ์ ๋ฐฉ ์๋ ์ฆ๊ฐ
|
567 |
+
this.velocity.z = noseDirection.z * this.speed * 0.5;
|
568 |
+
// y ์๋๋ ์์์ ์ค๋ ฅ์ผ๋ก ์ฒ๋ฆฌ๋จ
|
569 |
+
}
|
570 |
+
|
571 |
+
// ์ ์ ๋นํ ์ ์ค๋ ฅ ํจ๊ณผ
|
572 |
+
if (!this.stallWarning) {
|
573 |
+
const gravityEffect = GAME_CONSTANTS.GRAVITY * deltaTime * 0.15;
|
574 |
+
this.velocity.y -= gravityEffect;
|
575 |
+
|
576 |
+
// ์๋ ฅ ํจ๊ณผ (์๋์ ๋น๋ก)
|
577 |
+
const liftFactor = (this.speed / maxSpeed) * 0.8;
|
578 |
+
const lift = gravityEffect * liftFactor;
|
579 |
+
this.velocity.y += lift;
|
580 |
+
}
|
581 |
+
|
582 |
+
// ์์น ์
๋ฐ์ดํธ
|
583 |
+
this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
|
584 |
+
|
585 |
+
// ์ง๋ฉด ์ถฉ๋
|
586 |
+
if (this.position.y <= GAME_CONSTANTS.MIN_ALTITUDE) {
|
587 |
+
this.position.y = GAME_CONSTANTS.MIN_ALTITUDE;
|
588 |
+
this.health = 0;
|
589 |
+
|
590 |
+
// ์ง๋ฉด ์ถฉ๋ ์ ํญ๋ฐ ํจ๊ณผ ์ถ๊ฐ
|
591 |
+
if (window.gameInstance) {
|
592 |
+
window.gameInstance.createExplosionEffect(this.position);
|
593 |
+
}
|
594 |
+
|
595 |
+
return;
|
596 |
+
}
|
597 |
+
|
598 |
+
// ์ต๋ ๊ณ ๋ ์ ํ
|
599 |
+
if (this.position.y > GAME_CONSTANTS.MAX_ALTITUDE) {
|
600 |
+
this.position.y = GAME_CONSTANTS.MAX_ALTITUDE;
|
601 |
+
this.altitudeWarning = true;
|
602 |
+
if (this.velocity.y > 0) this.velocity.y = 0;
|
603 |
+
} else {
|
604 |
+
this.altitudeWarning = false;
|
605 |
+
}
|
606 |
+
|
607 |
+
// ๋งต ๊ฒฝ๊ณ ์ฒ๋ฆฌ
|
608 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
609 |
+
if (this.position.x > mapLimit) this.position.x = -mapLimit;
|
610 |
+
if (this.position.x < -mapLimit) this.position.x = mapLimit;
|
611 |
+
if (this.position.z > mapLimit) this.position.z = -mapLimit;
|
612 |
+
if (this.position.z < -mapLimit) this.position.z = mapLimit;
|
613 |
+
|
614 |
+
// ๋ฉ์ ์์น ๋ฐ ํ์ ์
๋ฐ์ดํธ - ์ฟผํฐ๋์ธ ์ฌ์ฉ
|
615 |
+
this.mesh.position.copy(this.position);
|
616 |
+
|
617 |
+
// ๋ฉ์ ํ์ ์ ์ฟผํฐ๋์ธ์ผ๋ก ์ค์
|
618 |
+
const meshQuaternion = new THREE.Quaternion();
|
619 |
+
|
620 |
+
// Y์ถ ํ์ ์ 3ฯ/2 ์ถ๊ฐ (๋ชจ๋ธ ์คํ์
)
|
621 |
+
const meshPitchQuat = new THREE.Quaternion();
|
622 |
+
const meshYawQuat = new THREE.Quaternion();
|
623 |
+
const meshRollQuat = new THREE.Quaternion();
|
624 |
+
|
625 |
+
meshPitchQuat.setFromAxisAngle(new THREE.Vector3(1, 0, 0), this.rotation.x);
|
626 |
+
meshYawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y + 3 * Math.PI / 2);
|
627 |
+
meshRollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
628 |
+
|
629 |
+
// ์ฟผํฐ๋์ธ ํฉ์ฑ
|
630 |
+
meshQuaternion.multiply(meshYawQuat);
|
631 |
+
meshQuaternion.multiply(meshPitchQuat);
|
632 |
+
meshQuaternion.multiply(meshRollQuat);
|
633 |
+
|
634 |
+
this.mesh.quaternion.copy(meshQuaternion);
|
635 |
+
|
636 |
+
// ๊ฒฝ๊ณ ๊น๋นก์ ํ์ด๋จธ
|
637 |
+
this.warningBlinkTimer += deltaTime;
|
638 |
+
if (this.warningBlinkTimer >= 1.0) {
|
639 |
+
this.warningBlinkTimer = 0;
|
640 |
+
this.warningBlinkState = !this.warningBlinkState;
|
641 |
+
}
|
642 |
+
|
643 |
+
// ๊ณ ๋ ๊ณ์ฐ
|
644 |
+
this.altitude = this.position.y;
|
645 |
+
|
646 |
+
// ๊ฒฝ๊ณ ์ ์
๋ฐ์ดํธ (์์ง ์๋ฆฌ๋ ๊ณ์ ์ ์ง)
|
647 |
+
this.updateWarningAudios();
|
648 |
+
|
649 |
+
// ์์ง ์๋ฆฌ ๋ณผ๋ฅจ์ ์ค๋กํ์ ์ฐ๋
|
650 |
+
if (this.warningAudios.normal && !this.warningAudios.normal.paused) {
|
651 |
+
this.warningAudios.normal.volume = 0.3 + this.throttle * 0.4; // 0.3~0.7
|
652 |
+
}
|
653 |
+
}
|
654 |
|
655 |
+
shoot(scene) {
|
656 |
+
// ํ์ฝ์ด ์์ผ๋ฉด ๋ฐ์ฌํ์ง ์์
|
657 |
+
if (this.ammo <= 0) return;
|
658 |
+
|
659 |
+
this.ammo--;
|
660 |
+
|
661 |
+
// ์ง์ ๋ชจ์์ ํํ (100% ๋ ํฌ๊ฒ)
|
662 |
+
const bulletGeometry = new THREE.CylinderGeometry(1.0, 1.0, 16, 8); // ๋ฐ์ง๋ฆ 0.75โ1.0, ๊ธธ์ด 12โ16
|
663 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
664 |
+
color: 0xffff00,
|
665 |
+
emissive: 0xffff00,
|
666 |
+
emissiveIntensity: 1.0
|
667 |
+
});
|
668 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
669 |
+
|
670 |
+
// ๊ธฐ์ ๋์์ ๋ฐ์ฌ (์ฟผํฐ๋์ธ ์ฌ์ฉ)
|
671 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 10);
|
672 |
+
|
673 |
+
// ์ ํฌ๊ธฐ์ ๋์ผํ ์ฟผํฐ๋์ธ ์์ฑ
|
674 |
+
const quaternion = new THREE.Quaternion();
|
675 |
+
const pitchQuat = new THREE.Quaternion();
|
676 |
+
const yawQuat = new THREE.Quaternion();
|
677 |
+
const rollQuat = new THREE.Quaternion();
|
678 |
+
|
679 |
+
pitchQuat.setFromAxisAngle(new THREE.Vector3(1, 0, 0), this.rotation.x);
|
680 |
+
yawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
|
681 |
+
rollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
682 |
+
|
683 |
+
quaternion.multiply(yawQuat);
|
684 |
+
quaternion.multiply(pitchQuat);
|
685 |
+
quaternion.multiply(rollQuat);
|
686 |
+
|
687 |
+
muzzleOffset.applyQuaternion(quaternion);
|
688 |
+
bullet.position.copy(this.position).add(muzzleOffset);
|
689 |
+
|
690 |
+
// ํํ์ ๋ฐ์ฌ ๋ฐฉํฅ์ผ๋ก ํ์
|
691 |
+
bullet.quaternion.copy(quaternion);
|
692 |
+
// ์ค๋ฆฐ๋๊ฐ Z์ถ ๋ฐฉํฅ์ ํฅํ๋๋ก ์ถ๊ฐ ํ์
|
693 |
+
const cylinderRotation = new THREE.Quaternion();
|
694 |
+
cylinderRotation.setFromAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI / 2);
|
695 |
+
bullet.quaternion.multiply(cylinderRotation);
|
696 |
+
|
697 |
+
// ํํ ์ด๊ธฐ ์์น ์ ์ฅ
|
698 |
+
bullet.startPosition = bullet.position.clone();
|
699 |
+
|
700 |
+
const bulletSpeed = 1500; // 1000์์ 1500์ผ๋ก ์ฆ๊ฐ (50% ๋น ๋ฅด๊ฒ)
|
701 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
702 |
+
direction.applyQuaternion(quaternion);
|
703 |
+
bullet.velocity = direction.multiplyScalar(bulletSpeed);
|
704 |
+
|
705 |
+
scene.add(bullet);
|
706 |
+
this.bullets.push(bullet);
|
707 |
+
|
708 |
+
// m134.ogg ์๋ฆฌ ์ฌ์ - ์ค์ฒฉ ์ ํ ํด์ , ๋๋ค ํผ์น
|
709 |
+
try {
|
710 |
+
const audio = new Audio('sounds/m134.ogg');
|
711 |
+
audio.volume = 0.15; // 0.3์์ 0.15๋ก ๊ฐ์ (50% ์ค์)
|
712 |
+
|
713 |
+
// -2 ~ +2 ์ฌ์ด์ ๋๋ค ํผ์น (playbackRate๋ก ์๋ฎฌ๋ ์ด์
)
|
714 |
+
const randomPitch = 0.8 + Math.random() * 0.4; // 0.8 ~ 1.2 ๋ฒ์
|
715 |
+
audio.playbackRate = randomPitch;
|
716 |
+
|
717 |
+
audio.play().catch(e => console.log('Gunfire sound failed to play'));
|
718 |
+
|
719 |
+
// ์ฌ์ ์๋ฃ ์ ๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ๋ฅผ ์ํด ์ฐธ์กฐ ์ ๊ฑฐ
|
720 |
+
audio.addEventListener('ended', () => {
|
721 |
+
audio.remove();
|
722 |
+
});
|
723 |
+
} catch (e) {
|
724 |
+
console.log('Audio error:', e);
|
725 |
+
}
|
726 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
727 |
|
728 |
+
updateBullets(scene, deltaTime, gameInstance) {
|
729 |
+
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
730 |
+
const bullet = this.bullets[i];
|
731 |
+
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
732 |
+
|
733 |
+
// ํํ๋ ๊ฐ์ ๋ฐฉํฅ์ ์ ์งํ๋๋ก ํ์ ์
๋ฐ์ดํธ
|
734 |
+
const direction = bullet.velocity.clone().normalize();
|
735 |
+
const angle = Math.atan2(direction.x, direction.z);
|
736 |
+
bullet.rotation.y = angle;
|
737 |
+
|
738 |
+
// ์ง๋ฉด ์ถฉ๋ ์ฒดํฌ ์ถ๊ฐ
|
739 |
+
if (bullet.position.y <= 0) {
|
740 |
+
// ํฌ๊ณ ํ๋ คํ ์ง๋ฉด ์ถฉ๋ ํจ๊ณผ
|
741 |
+
gameInstance.createGroundImpactEffect(bullet.position);
|
742 |
+
scene.remove(bullet);
|
743 |
+
this.bullets.splice(i, 1);
|
744 |
+
continue;
|
745 |
+
}
|
746 |
+
|
747 |
+
// 6000m ์ด์ ๋ ์๊ฐ๊ฑฐ๋ ๋์ด ์ ํ ์ด๊ณผ ์ ์ ๊ฑฐ
|
748 |
+
if (bullet.position.distanceTo(bullet.startPosition) > 6000 ||
|
749 |
+
bullet.position.y > GAME_CONSTANTS.MAX_ALTITUDE + 500) {
|
750 |
+
scene.remove(bullet);
|
751 |
+
this.bullets.splice(i, 1);
|
752 |
+
}
|
753 |
+
}
|
754 |
+
}
|
755 |
|
756 |
+
takeDamage(damage) {
|
757 |
+
this.health -= damage;
|
758 |
+
return this.health <= 0;
|
759 |
+
}
|
760 |
|
761 |
+
getCameraPosition() {
|
762 |
+
const backward = new THREE.Vector3(0, 0, -1);
|
763 |
+
const up = new THREE.Vector3(0, 1, 0);
|
764 |
+
|
765 |
+
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ์๋ ์ฟผํฐ๋์ธ ์ฌ์ฉ
|
766 |
+
const quaternion = new THREE.Quaternion();
|
767 |
+
const pitchQuat = new THREE.Quaternion();
|
768 |
+
const yawQuat = new THREE.Quaternion();
|
769 |
+
const rollQuat = new THREE.Quaternion();
|
770 |
+
|
771 |
+
pitchQuat.setFromAxisAngle(new THREE.Vector3(1, 0, 0), this.rotation.x);
|
772 |
+
yawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
|
773 |
+
rollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
774 |
+
|
775 |
+
quaternion.multiply(yawQuat);
|
776 |
+
quaternion.multiply(pitchQuat);
|
777 |
+
quaternion.multiply(rollQuat);
|
778 |
+
|
779 |
+
backward.applyQuaternion(quaternion);
|
780 |
+
up.applyQuaternion(quaternion);
|
781 |
+
|
782 |
+
const cameraPosition = this.position.clone()
|
783 |
+
.add(backward.multiplyScalar(this.cameraDistance))
|
784 |
+
.add(up.multiplyScalar(this.cameraHeight));
|
785 |
+
|
786 |
+
return cameraPosition;
|
787 |
+
}
|
788 |
|
789 |
+
getCameraTarget() {
|
790 |
+
return this.position.clone();
|
791 |
+
}
|
792 |
+
|
793 |
+
// HUD ํ์์ฉ ํค๋ฉ getter (0~360๋)
|
794 |
+
getHeadingDegrees() {
|
795 |
+
return this.normalizeHeading(this.rotation.y);
|
796 |
+
}
|
797 |
}
|
798 |
|
799 |
// ์ ์ ํฌ๊ธฐ ํด๋์ค - ์์ ํ ์ฌ์ค๊ณ
|