Step 4: Track shots fired
Some checks failed
Build / build (push) Failing after 20s

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 <noreply@anthropic.com>
This commit is contained in:
Michael Mainguy 2025-11-08 03:59:06 -06:00
parent 8fc956f112
commit 739f140ea4
2 changed files with 15 additions and 0 deletions

View File

@ -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);

View File

@ -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();