From 690ac1e7e6c14eefb5134d9d6a780def347a7f7d Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Sat, 14 Mar 2026 16:00:37 +0100 Subject: [PATCH] Added a class to map object ids so they can be called by name Signed-off-by: Hans Kokx --- lib/features/entities/map_objects.dart | 104 ++++++++++++++++++++ lib/features/entities/pushwall_manager.dart | 4 +- lib/features/player/player.dart | 31 +++--- lib/features/renderer/renderer.dart | 20 ++-- 4 files changed, 128 insertions(+), 31 deletions(-) create mode 100644 lib/features/entities/map_objects.dart diff --git a/lib/features/entities/map_objects.dart b/lib/features/entities/map_objects.dart new file mode 100644 index 0000000..2aea815 --- /dev/null +++ b/lib/features/entities/map_objects.dart @@ -0,0 +1,104 @@ +abstract class MapObjectId { + // --- Player Spawns --- + static const int playerNorth = 19; + static const int playerEast = 20; + static const int playerSouth = 21; + static const int playerWest = 22; + + // --- Static Decorations --- + static const int waterPuddle = 23; + static const int greenBarrel = 24; + static const int chairTable = 25; + static const int floorLamp = 26; + static const int chandelier = 27; + static const int hangingSkeleton = 28; + static const int dogFood = 29; // Also used as decoration + static const int whiteColumn = 30; + static const int pottedPlant = 31; + static const int blueSkeleton = 32; + static const int vent = 33; + static const int kitchenCans = 34; + static const int exitSign = 35; + static const int brownPlant = 36; + static const int bowl = 37; + static const int armoredSuit = 38; + static const int emptyCage = 39; + static const int cageWithSkeleton = 40; + static const int bones = 41; + static const int goldenKeybowl = 42; // Decorative only + + // --- Collectibles & Items --- + static const int goldKey = 43; + static const int silverKey = 44; + static const int bed = 45; // Bed is usually non-collectible but in this range + static const int basket = 46; + static const int food = 47; + static const int medkit = 48; + static const int ammoClip = 49; + static const int machineGun = 50; + static const int chainGun = 51; + static const int cross = 52; + static const int chalice = 53; + static const int chest = 54; + static const int crown = 55; + static const int extraLife = 56; + + // --- More Decorations --- + static const int bloodPool = 57; + static const int barrel = 58; + static const int well = 59; + static const int emptyWell = 60; + static const int bloodPoolLarge = 61; + static const int flag = 62; + static const int callanard = 63; // Aardwolf sign / hidden message + static const int bonesAndSkull = 64; + static const int wallHanging = 65; + static const int stove = 66; + static const int spearRack = 67; + static const int vines = 68; + + // --- Special Objects --- + static const int secretDoor = 98; // Often used for the Pushwall trigger + static const int elevatorToSecretLevel = 99; + static const int exitTrigger = 100; + + // --- Enemies (Spawn Points) --- + // Guards + static const int guardEasyNorth = 108; + static const int guardEasyEast = 109; + static const int guardEasySouth = 110; + static const int guardEasyWest = 111; + + // SS Guards + static const int ssEasyNorth = 124; + static const int ssEasyEast = 125; + static const int ssEasySouth = 126; + static const int ssEasyWest = 127; + + // Dogs + static const int dogEasyNorth = 140; + static const int dogEasyEast = 141; + static const int dogEasySouth = 142; + static const int dogEasyWest = 143; + + // Mutants + static const int mutantEasyNorth = 156; + static const int mutantEasyEast = 157; + static const int mutantEasySouth = 158; + static const int mutantEasyWest = 159; + + // Officers + static const int officerEasyNorth = 172; + static const int officerEasyEast = 173; + static const int officerEasySouth = 174; + static const int officerEasyWest = 175; + + // Bosses (Single spawn points) + static const int bossHansGrosse = 214; + static const int bossDrSchabbs = 215; + static const int bossFakeHitler = 216; + static const int bossMechaHitler = 217; + static const int bossOttoGiftmacher = 218; + static const int bossGretelGrosse = 219; + static const int bossGeneralFettgesicht = 220; +} diff --git a/lib/features/entities/pushwall_manager.dart b/lib/features/entities/pushwall_manager.dart index 278b7a3..b0a3244 100644 --- a/lib/features/entities/pushwall_manager.dart +++ b/lib/features/entities/pushwall_manager.dart @@ -1,6 +1,7 @@ import 'dart:math' as math; import 'package:wolf_dart/classes/matrix.dart'; +import 'package:wolf_dart/features/entities/map_objects.dart'; class Pushwall { int x; @@ -24,8 +25,7 @@ class PushwallManager { for (int y = 0; y < objectGrid.length; y++) { for (int x = 0; x < objectGrid[y].length; x++) { - // Map ID 98 in the object grid marks a pushwall! - if (objectGrid[y][x] == 98) { + if (objectGrid[y][x] == MapObjectId.secretDoor) { pushwalls['$x,$y'] = Pushwall(x, y, wallGrid[y][x]); } } diff --git a/lib/features/player/player.dart b/lib/features/player/player.dart index 659b209..d7971e8 100644 --- a/lib/features/player/player.dart +++ b/lib/features/player/player.dart @@ -4,6 +4,7 @@ import 'package:wolf_dart/classes/coordinate_2d.dart'; import 'package:wolf_dart/features/entities/collectible.dart'; import 'package:wolf_dart/features/entities/enemies/enemy.dart'; import 'package:wolf_dart/features/entities/entity.dart'; +import 'package:wolf_dart/features/entities/map_objects.dart'; import 'package:wolf_dart/features/weapon/weapon.dart'; import 'package:wolf_dart/features/weapon/weapons/chain_gun.dart'; import 'package:wolf_dart/features/weapon/weapons/knife.dart'; @@ -131,18 +132,14 @@ class Player { switch (item.type) { case CollectibleType.health: if (health >= 100) return false; - // Map IDs 47 (Dog Food) and 48 (Medkit) - heal(item.mapId == 47 ? 4 : 25); + heal(item.mapId == MapObjectId.dogFood ? 4 : 25); pickedUp = true; break; case CollectibleType.ammo: if (ammo >= 99) return false; - int previousAmmo = ammo; addAmmo(8); - - // Auto-switch back to Pistol if holding Knife and just got ammo if (currentWeapon is Knife && previousAmmo <= 0) { requestWeaponSwitch(WeaponType.pistol); } @@ -150,11 +147,11 @@ class Player { break; case CollectibleType.treasure: - if (item.mapId == 52) score += 100; - if (item.mapId == 53) score += 500; - if (item.mapId == 54) score += 1000; - if (item.mapId == 55) score += 5000; - if (item.mapId == 56) { + if (item.mapId == MapObjectId.cross) score += 100; + if (item.mapId == MapObjectId.chalice) score += 500; + if (item.mapId == MapObjectId.chest) score += 1000; + if (item.mapId == MapObjectId.crown) score += 5000; + if (item.mapId == MapObjectId.extraLife) { heal(100); addAmmo(25); } @@ -162,31 +159,29 @@ class Player { break; case CollectibleType.weapon: - addAmmo(8); - if (item.mapId == 50) { - // Machine Gun Pickup + if (item.mapId == MapObjectId.machineGun) { if (weapons[WeaponType.machineGun] == null) { weapons[WeaponType.machineGun] = MachineGun(); hasMachineGun = true; } - // The original game ALWAYS switches to a superior weapon on pickup + addAmmo(8); requestWeaponSwitch(WeaponType.machineGun); pickedUp = true; } - if (item.mapId == 51) { - // Chain Gun Pickup + if (item.mapId == MapObjectId.chainGun) { if (weapons[WeaponType.chainGun] == null) { weapons[WeaponType.chainGun] = ChainGun(); hasChainGun = true; } + addAmmo(8); requestWeaponSwitch(WeaponType.chainGun); pickedUp = true; } break; case CollectibleType.key: - if (item.mapId == 43) hasGoldKey = true; - if (item.mapId == 44) hasSilverKey = true; + if (item.mapId == MapObjectId.goldKey) hasGoldKey = true; + if (item.mapId == MapObjectId.silverKey) hasSilverKey = true; pickedUp = true; break; } diff --git a/lib/features/renderer/renderer.dart b/lib/features/renderer/renderer.dart index 687d28b..34f7afa 100644 --- a/lib/features/renderer/renderer.dart +++ b/lib/features/renderer/renderer.dart @@ -10,6 +10,7 @@ import 'package:wolf_dart/features/entities/door_manager.dart'; import 'package:wolf_dart/features/entities/enemies/enemy.dart'; import 'package:wolf_dart/features/entities/entity.dart'; import 'package:wolf_dart/features/entities/entity_registry.dart'; +import 'package:wolf_dart/features/entities/map_objects.dart'; import 'package:wolf_dart/features/entities/pushwall_manager.dart'; import 'package:wolf_dart/features/input/input_manager.dart'; import 'package:wolf_dart/features/map/wolf_map.dart'; @@ -76,27 +77,24 @@ class _WolfRendererState extends State for (int x = 0; x < 64; x++) { int objId = objectLevel[y][x]; - if (objId >= 19 && objId <= 22) { + if (objId >= MapObjectId.playerNorth && + objId <= MapObjectId.playerWest) { double spawnAngle = 0.0; switch (objId) { - case 19: + case MapObjectId.playerNorth: spawnAngle = 3 * math.pi / 2; break; - case 20: + case MapObjectId.playerEast: spawnAngle = 0.0; break; - case 21: + case MapObjectId.playerSouth: spawnAngle = math.pi / 2; break; - case 22: + case MapObjectId.playerWest: spawnAngle = math.pi; break; } - player = Player( - x: x + 0.5, - y: y + 0.5, - angle: spawnAngle, - ); + player = Player(x: x + 0.5, y: y + 0.5, angle: spawnAngle); } else { Entity? newEntity = EntityRegistry.spawn( objId, @@ -344,7 +342,7 @@ class _WolfRendererState extends State // 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 + MapObjectId.ammoClip, entity.x, entity.y, widget.difficulty.level,