From dfc6a94e885250d3f8b0bec85cf42614505ffc6f Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Sat, 14 Mar 2026 15:51:23 +0100 Subject: [PATCH] Enemies drop ammo now Signed-off-by: Hans Kokx --- lib/features/player/player.dart | 20 ++++++++++++++------ lib/features/renderer/renderer.dart | 16 ++++++++++++++-- lib/features/weapon/weapons/machine_gun.dart | 3 ++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/features/player/player.dart b/lib/features/player/player.dart index 920d5bb..659b209 100644 --- a/lib/features/player/player.dart +++ b/lib/features/player/player.dart @@ -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); + } } } diff --git a/lib/features/renderer/renderer.dart b/lib/features/renderer/renderer.dart index d12f336..687d28b 100644 --- a/lib/features/renderer/renderer.dart +++ b/lib/features/renderer/renderer.dart @@ -337,11 +337,23 @@ class _WolfRendererState extends State 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. diff --git a/lib/features/weapon/weapons/machine_gun.dart b/lib/features/weapon/weapons/machine_gun.dart index 6f2800a..1743c3a 100644 --- a/lib/features/weapon/weapons/machine_gun.dart +++ b/lib/features/weapon/weapons/machine_gun.dart @@ -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! ); }