feat: Enhance player and weapon logging for better debugging and tracking

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-19 17:32:45 +01:00
parent 7e1855ebda
commit 7b1ec777d3
3 changed files with 30 additions and 7 deletions

View File

@@ -102,6 +102,8 @@ class Player {
pendingWeaponType = weaponType; pendingWeaponType = weaponType;
switchState = WeaponSwitchState.lowering; switchState = WeaponSwitchState.lowering;
print("[PLAYER] Requesting weapon switch to ${weaponType.name}.");
} }
// --- Health & Damage --- // --- Health & Damage ---
@@ -114,16 +116,16 @@ class Player {
damageFlash = math.min(1.0, damageFlash + (damage * 0.05)); damageFlash = math.min(1.0, damageFlash + (damage * 0.05));
if (health <= 0) { if (health <= 0) {
print("YOU DIED!"); print("[PLAYER] Died! Final Score: $score");
} else { } else {
print("Ouch! ($health)"); print("[PLAYER] Took $damage damage ($health)");
} }
} }
void heal(int amount) { void heal(int amount) {
final int newHealth = math.min(100, health + amount); final int newHealth = math.min(100, health + amount);
if (health < 100) { if (health < 100) {
print("Feelin' better. ($newHealth)"); print("[PLAYER] Healed for $amount ($health -> $newHealth)");
} }
health = newHealth; health = newHealth;
} }
@@ -131,13 +133,14 @@ class Player {
void addAmmo(int amount) { void addAmmo(int amount) {
final int newAmmo = math.min(99, ammo + amount); final int newAmmo = math.min(99, ammo + amount);
if (ammo < 99) { if (ammo < 99) {
print("Hell yeah. ($newAmmo)"); print("[PLAYER] Picked up ammo $amount ($ammo -> $newAmmo)");
} }
ammo = newAmmo; ammo = newAmmo;
} }
void addLives(int amount) { void addLives(int amount) {
lives = math.min(9, lives + amount); lives = math.min(9, lives + amount);
print("[PLAYER] Adding $amount extra lives (Total Lives: $lives)");
} }
/// Attempts to collect [item] and returns the SFX to play. /// Attempts to collect [item] and returns the SFX to play.
@@ -157,6 +160,8 @@ class Player {
); );
if (effect == null) return null; if (effect == null) return null;
print("[PLAYER] Collected ${item.runtimeType} - Effect: $effect");
if (effect.healthToRestore > 0) { if (effect.healthToRestore > 0) {
heal(effect.healthToRestore); heal(effect.healthToRestore);
} }
@@ -166,6 +171,8 @@ class Player {
} }
if (effect.scoreToAdd > 0) { if (effect.scoreToAdd > 0) {
print("[PLAYER] Adding ${effect.scoreToAdd} score.");
score += effect.scoreToAdd; score += effect.scoreToAdd;
} }
@@ -174,10 +181,12 @@ class Player {
} }
if (effect.grantGoldKey) { if (effect.grantGoldKey) {
print("[PLAYER] Collected Gold Key.");
hasGoldKey = true; hasGoldKey = true;
} }
if (effect.grantSilverKey) { if (effect.grantSilverKey) {
print("[PLAYER] Collected Silver Key.");
hasSilverKey = true; hasSilverKey = true;
} }
@@ -193,6 +202,8 @@ class Player {
if (weaponType == WeaponType.machineGun) hasMachineGun = true; if (weaponType == WeaponType.machineGun) hasMachineGun = true;
if (weaponType == WeaponType.chainGun) hasChainGun = true; if (weaponType == WeaponType.chainGun) hasChainGun = true;
print("[PLAYER] Collected ${weaponType.name}.");
} }
if (effect.requestWeaponSwitch case final weaponType?) { if (effect.requestWeaponSwitch case final weaponType?) {
@@ -242,7 +253,7 @@ class Player {
onEnemyKilled: (Enemy killedEnemy) { onEnemyKilled: (Enemy killedEnemy) {
score += killedEnemy.scoreValue; score += killedEnemy.scoreValue;
print( print(
"Killed ${killedEnemy.runtimeType}! +${killedEnemy.scoreValue} (Score: $score)", "[PLAYER] Killed ${killedEnemy.runtimeType}! +${killedEnemy.scoreValue} (Score: $score)",
); );
}, },
); );
@@ -251,6 +262,7 @@ class Player {
if (currentWeapon.state == WeaponState.idle && if (currentWeapon.state == WeaponState.idle &&
ammo <= 0 && ammo <= 0 &&
currentWeapon.type != WeaponType.knife) { currentWeapon.type != WeaponType.knife) {
print("[PLAYER] Out of ammo, switching to knife.");
requestWeaponSwitch(WeaponType.knife); requestWeaponSwitch(WeaponType.knife);
} }
} }

View File

@@ -46,6 +46,11 @@ class CollectiblePickupEffect {
this.grantWeapon, this.grantWeapon,
this.requestWeaponSwitch, this.requestWeaponSwitch,
}); });
@override
String toString() {
return 'CollectiblePickupEffect(healthToRestore: $healthToRestore, ammoToAdd: $ammoToAdd, scoreToAdd: $scoreToAdd, extraLivesToAdd: $extraLivesToAdd, pickupSfxId: $pickupSfxId, grantGoldKey: $grantGoldKey, grantSilverKey: $grantSilverKey, grantWeapon: $grantWeapon, requestWeaponSwitch: $requestWeaponSwitch)';
}
} }
abstract class Collectible extends Entity { abstract class Collectible extends Entity {

View File

@@ -1,8 +1,8 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
import 'package:wolf_3d_dart/src/entities/entities/enemies/enemy.dart'; import 'package:wolf_3d_dart/src/entities/entities/enemies/enemy.dart';
import 'package:wolf_3d_dart/src/entities/entity.dart'; import 'package:wolf_3d_dart/src/entities/entity.dart';
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
enum WeaponState { idle, firing } enum WeaponState { idle, firing }
@@ -55,14 +55,20 @@ abstract class Weapon {
bool fire(int currentTime, {required int currentAmmo}) { bool fire(int currentTime, {required int currentAmmo}) {
if (state == WeaponState.idle && currentAmmo > 0) { if (state == WeaponState.idle && currentAmmo > 0) {
if (!isAutomatic && !_triggerReleased) return false; if (!isAutomatic && !_triggerReleased) {
return false;
}
state = WeaponState.firing; state = WeaponState.firing;
frameIndex = 0; frameIndex = 0;
lastFrameTime = currentTime; lastFrameTime = currentTime;
_triggerReleased = false; _triggerReleased = false;
print("[WEAPON] $type fired.");
return true; return true;
} }
return false; return false;
} }