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 (weaponType == currentWeapon.type) return;
if (!weapons.containsKey(weaponType)) return;
if (weaponType == WeaponType.knife && ammo <= 0) return;
if (weaponType != WeaponType.knife && ammo <= 0) return;
pendingWeaponType = weaponType;
switchState = WeaponSwitchState.lowering;
@@ -162,6 +162,7 @@ class Player {
break;
case CollectibleType.weapon:
addAmmo(8);
if (item.mapId == 50) {
// Machine Gun Pickup
if (weapons[WeaponType.machineGun] == null) {
@@ -195,13 +196,14 @@ class Player {
void fire(int currentTime) {
if (switchState != WeaponSwitchState.idle) return;
bool shotFired = currentWeapon.fire(currentTime, currentAmmo: ammo);
// Check currentWeapon.type
// We pass the isFiring state to handle automatic vs semi-auto behavior
bool shotFired = currentWeapon.fire(
currentTime,
currentAmmo: ammo,
);
if (shotFired && currentWeapon.type != WeaponType.knife) {
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;
// 4. Handle Item Drops & Score (Matches KillActor in C code)
// Check if they just died this exact frame
if (entity.state == EntityState.dead &&
entity.isDying &&
!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.

View File

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