From eea82da3959c6010dd380b47fcf460a4f2c3b055 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Fri, 7 Nov 2025 15:20:00 -0600 Subject: [PATCH] Add ammo consumption to weapon firing system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integrated ammo tracking into the weapon system to consume ammo with each shot fired. **Modified: src/weaponSystem.ts** - Added ShipStatus import and private _shipStatus property - Added setShipStatus() method to connect ship status manager - Added ammo check in fire() method - prevents firing when ammo <= 0 - Added ammo consumption: consumeAmmo(0.01) after each shot - Shots are blocked when out of ammo **Modified: src/ship.ts** - Connected WeaponSystem to Scoreboard's ShipStatus via setShipStatus() - Called immediately after weapon initialization (line 111) This completes the resource management system: - Linear thrust consumes fuel (0.005 per frame max) - Angular thrust consumes fuel (0.005 per frame max) - Weapon firing consumes ammo (0.01 per shot) - All gauges update automatically via observable events - Actions are blocked when resources are depleted 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/ship.ts | 1 + src/weaponSystem.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/ship.ts b/src/ship.ts index b6c1dd7..6696b10 100644 --- a/src/ship.ts +++ b/src/ship.ts @@ -108,6 +108,7 @@ export class Ship { // Initialize weapon system this._weapons = new WeaponSystem(DefaultScene.MainScene); this._weapons.initialize(); + this._weapons.setShipStatus(this._scoreboard.shipStatus); // Initialize input systems this._keyboardInput = new KeyboardInput(DefaultScene.MainScene); diff --git a/src/weaponSystem.ts b/src/weaponSystem.ts index f69ad00..5d44dcd 100644 --- a/src/weaponSystem.ts +++ b/src/weaponSystem.ts @@ -13,6 +13,7 @@ import { Vector3, } from "@babylonjs/core"; import { GameConfig } from "./gameConfig"; +import { ShipStatus } from "./shipStatus"; /** * Handles weapon firing and projectile lifecycle @@ -21,11 +22,19 @@ export class WeaponSystem { private _ammoBaseMesh: AbstractMesh; private _ammoMaterial: StandardMaterial; private _scene: Scene; + private _shipStatus: ShipStatus | null = null; constructor(scene: Scene) { this._scene = scene; } + /** + * Set the ship status instance for ammo tracking + */ + public setShipStatus(shipStatus: ShipStatus): void { + this._shipStatus = shipStatus; + } + /** * Initialize weapon system (create ammo template) */ @@ -57,6 +66,11 @@ export class WeaponSystem { return; } + // Check if we have ammo before firing + if (this._shipStatus && this._shipStatus.ammo <= 0) { + return; + } + // Create projectile instance const ammo = new InstancedMesh("ammo", this._ammoBaseMesh as Mesh); ammo.parent = shipTransform; @@ -82,6 +96,11 @@ export class WeaponSystem { // Set projectile velocity (already includes ship velocity) ammoAggregate.body.setLinearVelocity(velocityVector); + // Consume ammo + if (this._shipStatus) { + this._shipStatus.consumeAmmo(0.01); + } + // Auto-dispose after 2 seconds window.setTimeout(() => { ammoAggregate.dispose();