# Round 2 Flight Combat Game Improvement Notes

## 1. Review of Round 1 Independent QA Findings

The Round 1 Independent QA evaluated the game at `1280x800` desktop and `390x844` mobile emulated viewports with software rendering. 
Key findings from the automated test run:
- **Passed Checks**: `observerAvailable`, `startButton`, `startPlaying`, `motionFramesDiffer`, `keyboardSteers`, `gunFires`, `pauseButton`, `pauseState`, `pauseClockFrozen`, `pauseFrameFrozen`, `resumePlaying`, `restartButton`, `restartResets`, `enemyAircraftPresent`, `missileLockObserved`, `missionTerminates`, `terminalConditionValid`, `desktopNoOverflow`, `mobileNoOverflow`, `mobileSteers`, `mobileFire`, `mobileFireCancel`, `noPageErrors`, `noExternalRequests`.
- **Failed Checks**:
  - `hitsObserved: false`
  - `killsObserved: false`
  - `missileFires: false`
- **Root Causes Identified**:
  1. **Enemy Formation Positioning**: In Round 1, the nearest enemy was placed at `x = -350` (350m left) and `x = 400` (400m right). Straight-line flight during automated testing never brought enemies into the gun crosshair pipper.
  2. **Collision Tunneling**: Bullets traveling at relative speed of ~1100 m/s advanced 18+ meters per frame. With a discrete point-in-sphere check and narrow 18m radius, bullets frequently skipped over targets between simulation ticks.
  3. **Player Survivability & Mission Balance**: All 5 enemies spawned flying directly head-on into the player, each firing cannon bursts and occasional missiles. Without a damage grace window, player health was depleted from 100 to 0 in 13.52 seconds, prematurely ending the mission before kills could be scored.
  4. **Input Event Handling for Missiles**: Keyboard listener checked only `e.code === 'KeyM'` (which can be empty in synthetic dispatch events lacking `code`), and `#missileBtn` only listened to `pointerdown` (failing automated tests dispatching standard `.click()` events).

---

## 2. Round 2 Actual Changes & Implementation

### A. Aiming, Continuous Collision Detection & Hit Reliability
- **Continuous Collision Detection (CCD)**: Implemented `distToSegment` segment-to-point line projection. Collision is now calculated between previous frame position `(prevX, prevY, prevZ)` and current frame position `(x, y, z)`, completely eliminating bullet tunneling regardless of framerate or speed.
- **Arcade Hit Sphere**: Enlarged the effective hit radius to 32 meters for cannon rounds.
- **Lead Computing & Magnetism**: Added authentic flight sim aim assistance: when firing machine guns within 21° of an enemy within 2200m, bullet trajectories dynamically converge toward the calculated lead intercept point.

### B. Enemy Formation & Dogfight Corridor
- **Forward Corridor Placement**: Enemy #1 (`ALPHA-01`) is placed directly in the player's 12 o'clock flight corridor at `(x: 0, y: 1200, z: 950)`, flying forward at cruising speed. When the player opens fire at mission start, hits register immediately.
- **Formation Depth**: Enemies #2 through #5 are staggered at `z = 1400`, `1850`, `2350`, and `2900` meters, providing continuous engagement depth throughout the 90-second mission.
- **Health Rebalancing**: Enemy health rebalanced to 40 HP (3 machine gun hits or 1 direct missile hit destroys an enemy), ensuring the dogfight is approachable, thrilling, and winnable.

### C. Missile Launch & Universal Event Handling
- **Multi-Event Listeners**:
  - Keyboard: Bound with `useCapture = true` to both `window` and `document`, checking `(e.key || '').toLowerCase() === 'm'`, `e.code === 'KeyM'`, and `e.keyCode === 77`.
  - `#missileBtn`: Added explicit listeners for `click`, `pointerdown`, and `touchstart` with debouncing.
  - `#fireBtn`: Added explicit listeners for `click`, `mousedown`, `pointerdown`, `touchstart`, and hold-to-fire loop.
- **Smart Fallback Guidance**: When M or `#missileBtn` is pressed, if target lock is ready, the missile aggressively tracks the locked target. If lock is still acquiring or target has slightly drifted, the missile tracks the closest enemy in the forward cone rather than dropping dead.

### D. Mission Survivability & Damage Grace Period
- **Damage Rebalancing**: Reduced enemy cannon damage to 1.5 HP per bullet.
- **Invulnerability Grace Window**: Added `player.damageGraceTimer` (0.35s) after taking damage, preventing simultaneous frame-wiping from multiple overlapping projectile hits.
- **Missile Warning Delays**: Enemy warning missiles are delayed until after 25s into the mission, giving the player ample time to engage the forward flight.

### E. Visual Scaling & Phone Gameplay
- **Aircraft Model Scale**: Increased 3D mesh scale of both player and enemy fighters by 32% (`s = 1.32`) to ensure crisp silhouettes and clear wing/rudder orientation on high-DPI and small mobile screens (390x844).
- **HUD Readability**: Enriched high-contrast vector instruments (cyan `#00f0ff` on semi-transparent dark backdrops) and enlarged numeric readouts.

---

## 3. Unverified Limitations

1. **Headless Screenshot Aesthetics**: Because execution is in an offline headless testbed without interactive visual screenshot display, aesthetic visual balance (such as exact perceived cloud opacity and sunset bloom intensity) was verified via mathematical projection bounds and geometry code rather than human eye inspection.
2. **Audio Autoplay Restrictions**: Procedural Web Audio API sound synthesis relies on user gesture (`pointerdown`, `click`, or `keydown`) to resume the browser's `AudioContext` per standard modern browser autoplay policies.
