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:
@@ -102,6 +102,8 @@ class Player {
|
||||
|
||||
pendingWeaponType = weaponType;
|
||||
switchState = WeaponSwitchState.lowering;
|
||||
|
||||
print("[PLAYER] Requesting weapon switch to ${weaponType.name}.");
|
||||
}
|
||||
|
||||
// --- Health & Damage ---
|
||||
@@ -114,16 +116,16 @@ class Player {
|
||||
damageFlash = math.min(1.0, damageFlash + (damage * 0.05));
|
||||
|
||||
if (health <= 0) {
|
||||
print("YOU DIED!");
|
||||
print("[PLAYER] Died! Final Score: $score");
|
||||
} else {
|
||||
print("Ouch! ($health)");
|
||||
print("[PLAYER] Took $damage damage ($health)");
|
||||
}
|
||||
}
|
||||
|
||||
void heal(int amount) {
|
||||
final int newHealth = math.min(100, health + amount);
|
||||
if (health < 100) {
|
||||
print("Feelin' better. ($newHealth)");
|
||||
print("[PLAYER] Healed for $amount ($health -> $newHealth)");
|
||||
}
|
||||
health = newHealth;
|
||||
}
|
||||
@@ -131,13 +133,14 @@ class Player {
|
||||
void addAmmo(int amount) {
|
||||
final int newAmmo = math.min(99, ammo + amount);
|
||||
if (ammo < 99) {
|
||||
print("Hell yeah. ($newAmmo)");
|
||||
print("[PLAYER] Picked up ammo $amount ($ammo -> $newAmmo)");
|
||||
}
|
||||
ammo = newAmmo;
|
||||
}
|
||||
|
||||
void addLives(int 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.
|
||||
@@ -157,6 +160,8 @@ class Player {
|
||||
);
|
||||
if (effect == null) return null;
|
||||
|
||||
print("[PLAYER] Collected ${item.runtimeType} - Effect: $effect");
|
||||
|
||||
if (effect.healthToRestore > 0) {
|
||||
heal(effect.healthToRestore);
|
||||
}
|
||||
@@ -166,6 +171,8 @@ class Player {
|
||||
}
|
||||
|
||||
if (effect.scoreToAdd > 0) {
|
||||
print("[PLAYER] Adding ${effect.scoreToAdd} score.");
|
||||
|
||||
score += effect.scoreToAdd;
|
||||
}
|
||||
|
||||
@@ -174,10 +181,12 @@ class Player {
|
||||
}
|
||||
|
||||
if (effect.grantGoldKey) {
|
||||
print("[PLAYER] Collected Gold Key.");
|
||||
hasGoldKey = true;
|
||||
}
|
||||
|
||||
if (effect.grantSilverKey) {
|
||||
print("[PLAYER] Collected Silver Key.");
|
||||
hasSilverKey = true;
|
||||
}
|
||||
|
||||
@@ -193,6 +202,8 @@ class Player {
|
||||
|
||||
if (weaponType == WeaponType.machineGun) hasMachineGun = true;
|
||||
if (weaponType == WeaponType.chainGun) hasChainGun = true;
|
||||
|
||||
print("[PLAYER] Collected ${weaponType.name}.");
|
||||
}
|
||||
|
||||
if (effect.requestWeaponSwitch case final weaponType?) {
|
||||
@@ -242,7 +253,7 @@ class Player {
|
||||
onEnemyKilled: (Enemy killedEnemy) {
|
||||
score += killedEnemy.scoreValue;
|
||||
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 &&
|
||||
ammo <= 0 &&
|
||||
currentWeapon.type != WeaponType.knife) {
|
||||
print("[PLAYER] Out of ammo, switching to knife.");
|
||||
requestWeaponSwitch(WeaponType.knife);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ class CollectiblePickupEffect {
|
||||
this.grantWeapon,
|
||||
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 {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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/entity.dart';
|
||||
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
|
||||
|
||||
enum WeaponState { idle, firing }
|
||||
|
||||
@@ -55,14 +55,20 @@ abstract class Weapon {
|
||||
|
||||
bool fire(int currentTime, {required int currentAmmo}) {
|
||||
if (state == WeaponState.idle && currentAmmo > 0) {
|
||||
if (!isAutomatic && !_triggerReleased) return false;
|
||||
if (!isAutomatic && !_triggerReleased) {
|
||||
return false;
|
||||
}
|
||||
|
||||
state = WeaponState.firing;
|
||||
frameIndex = 0;
|
||||
lastFrameTime = currentTime;
|
||||
_triggerReleased = false;
|
||||
|
||||
print("[WEAPON] $type fired.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user