Enemies drop ammo now

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 15:51:23 +01:00
parent 001c7c3131
commit dfc6a94e88
3 changed files with 30 additions and 9 deletions

View File

@@ -92,7 +92,7 @@ class Player {
if (currentWeapon.state != WeaponState.idle) return; if (currentWeapon.state != WeaponState.idle) return;
if (weaponType == currentWeapon.type) return; if (weaponType == currentWeapon.type) return;
if (!weapons.containsKey(weaponType)) return; if (!weapons.containsKey(weaponType)) return;
if (weaponType == WeaponType.knife && ammo <= 0) return; if (weaponType != WeaponType.knife && ammo <= 0) return;
pendingWeaponType = weaponType; pendingWeaponType = weaponType;
switchState = WeaponSwitchState.lowering; switchState = WeaponSwitchState.lowering;
@@ -162,6 +162,7 @@ class Player {
break; break;
case CollectibleType.weapon: case CollectibleType.weapon:
addAmmo(8);
if (item.mapId == 50) { if (item.mapId == 50) {
// Machine Gun Pickup // Machine Gun Pickup
if (weapons[WeaponType.machineGun] == null) { if (weapons[WeaponType.machineGun] == null) {
@@ -195,13 +196,14 @@ class Player {
void fire(int currentTime) { void fire(int currentTime) {
if (switchState != WeaponSwitchState.idle) return; if (switchState != WeaponSwitchState.idle) return;
bool shotFired = currentWeapon.fire(currentTime, currentAmmo: ammo); // We pass the isFiring state to handle automatic vs semi-auto behavior
// Check currentWeapon.type bool shotFired = currentWeapon.fire(
currentTime,
currentAmmo: ammo,
);
if (shotFired && currentWeapon.type != WeaponType.knife) { if (shotFired && currentWeapon.type != WeaponType.knife) {
ammo--; ammo--;
if (ammo <= 0) {
requestWeaponSwitch(WeaponType.knife);
}
} }
} }
@@ -254,5 +256,11 @@ class Player {
}, },
); );
} }
if (currentWeapon.state == WeaponState.idle &&
ammo <= 0 &&
currentWeapon.type != WeaponType.knife) {
requestWeaponSwitch(WeaponType.knife);
}
} }
} }

View File

@@ -337,11 +337,23 @@ class _WolfRendererState extends State<WolfRenderer>
entity.y += intent.movement.y; entity.y += intent.movement.y;
// 4. Handle Item Drops & Score (Matches KillActor in C code) // 4. Handle Item Drops & Score (Matches KillActor in C code)
// Check if they just died this exact frame
if (entity.state == EntityState.dead && if (entity.state == EntityState.dead &&
entity.isDying && entity.isDying &&
!entity.hasDroppedItem) { !entity.hasDroppedItem) {
entity.hasDroppedItem = true; // Make sure we only drop once! entity.hasDroppedItem = true;
// Map ID 44 is usually the Ammo Clip in the Object Grid/Registry
Entity? droppedAmmo = EntityRegistry.spawn(
49, // The ID for an ammo clip collectible
entity.x,
entity.y,
widget.difficulty.level,
gameMap.sprites.length,
);
if (droppedAmmo != null) {
itemsToAdd.add(droppedAmmo);
}
// You will need to add a `bool hasDroppedItem = false;` to your base Enemy class. // You will need to add a `bool hasDroppedItem = false;` to your base Enemy class.

View File

@@ -7,6 +7,7 @@ class MachineGun extends Weapon {
idleSprite: 427, idleSprite: 427,
fireFrames: [428, 429, 430], fireFrames: [428, 429, 430],
damage: 20, damage: 20,
msPerFrame: 80, msPerFrame: 80, // MG fires faster than the Pistol
isAutomatic: true, // This allows holding the button!
); );
} }