diff --git a/src/ship.ts b/src/ship.ts index 9c51599..9e30004 100644 --- a/src/ship.ts +++ b/src/ship.ts @@ -132,6 +132,7 @@ export class Ship { this._weapons = new WeaponSystem(DefaultScene.MainScene); this._weapons.initialize(); this._weapons.setShipStatus(this._scoreboard.shipStatus); + this._weapons.setGameStats(this._gameStats); // Initialize input systems this._keyboardInput = new KeyboardInput(DefaultScene.MainScene); diff --git a/src/weaponSystem.ts b/src/weaponSystem.ts index 5d44dcd..3752fb6 100644 --- a/src/weaponSystem.ts +++ b/src/weaponSystem.ts @@ -14,6 +14,7 @@ import { } from "@babylonjs/core"; import { GameConfig } from "./gameConfig"; import { ShipStatus } from "./shipStatus"; +import { GameStats } from "./gameStats"; /** * Handles weapon firing and projectile lifecycle @@ -23,6 +24,7 @@ export class WeaponSystem { private _ammoMaterial: StandardMaterial; private _scene: Scene; private _shipStatus: ShipStatus | null = null; + private _gameStats: GameStats | null = null; constructor(scene: Scene) { this._scene = scene; @@ -35,6 +37,13 @@ export class WeaponSystem { this._shipStatus = shipStatus; } + /** + * Set the game stats instance for tracking shots fired + */ + public setGameStats(gameStats: GameStats): void { + this._gameStats = gameStats; + } + /** * Initialize weapon system (create ammo template) */ @@ -101,6 +110,11 @@ export class WeaponSystem { this._shipStatus.consumeAmmo(0.01); } + // Track shot fired + if (this._gameStats) { + this._gameStats.recordShotFired(); + } + // Auto-dispose after 2 seconds window.setTimeout(() => { ammoAggregate.dispose();