From 739f140ea45fe3c7bcd0264156704d8f3380272f Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Sat, 8 Nov 2025 03:59:06 -0600 Subject: [PATCH] Step 4: Track shots fired MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added real-time tracking of shots fired in the weapon system. **Modified: src/weaponSystem.ts** - Added GameStats import and _gameStats property - Added setGameStats() method to receive GameStats instance - Call gameStats.recordShotFired() in fire() method after creating projectile - Tracks every shot fired regardless of whether it hits **Modified: src/ship.ts** - Wire up weapon system with GameStats via setGameStats() - Called immediately after weapon initialization The Shots Fired statistic now updates in real-time on the status screen whenever the player fires their weapon. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/ship.ts | 1 + src/weaponSystem.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) 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();