Add ammo consumption to weapon firing system
All checks were successful
Build / build (push) Successful in 1m28s

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 <noreply@anthropic.com>
This commit is contained in:
Michael Mainguy 2025-11-07 15:20:00 -06:00
parent 65e7c496b7
commit eea82da395
2 changed files with 20 additions and 0 deletions

View File

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

View File

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