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