Abstracted more functionality into the base rasterizer
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -16,6 +16,10 @@ class Player {
|
||||
int ammo = 8;
|
||||
int score = 0;
|
||||
|
||||
// Damage flash
|
||||
double damageFlash = 0.0; // 0.0 is none, 1.0 is maximum red
|
||||
final double damageFlashFadeSpeed = 0.05; // How fast it fades per tick
|
||||
|
||||
// Inventory
|
||||
bool hasGoldKey = false;
|
||||
bool hasSilverKey = false;
|
||||
@@ -40,17 +44,25 @@ class Player {
|
||||
// How fast the weapon drops/raises per tick
|
||||
final double switchSpeed = 30.0;
|
||||
|
||||
Player({
|
||||
required this.x,
|
||||
required this.y,
|
||||
required this.angle,
|
||||
}) {
|
||||
Player({required this.x, required this.y, required this.angle}) {
|
||||
currentWeapon = weapons[WeaponType.pistol]!;
|
||||
}
|
||||
|
||||
// Helper getter to interface with the RaycasterPainter
|
||||
Coordinate2D get position => Coordinate2D(x, y);
|
||||
|
||||
// --- General Update ---
|
||||
|
||||
void tick(Duration elapsed) {
|
||||
// Fade the damage flash over time
|
||||
if (damageFlash > 0.0) {
|
||||
// Assuming 60fps, we fade it out
|
||||
damageFlash = math.max(0.0, damageFlash - damageFlashFadeSpeed);
|
||||
}
|
||||
|
||||
updateWeaponSwitch();
|
||||
}
|
||||
|
||||
// --- Weapon Switching & Animation Logic ---
|
||||
|
||||
void updateWeaponSwitch() {
|
||||
@@ -95,6 +107,11 @@ class Player {
|
||||
|
||||
void takeDamage(int damage) {
|
||||
health = math.max(0, health - damage);
|
||||
|
||||
// Spike the damage flash based on how much damage was taken
|
||||
// A 10 damage hit gives a 0.5 flash, a 20 damage hit maxes it out at 1.0
|
||||
damageFlash = math.min(1.0, damageFlash + (damage * 0.05));
|
||||
|
||||
if (health <= 0) {
|
||||
print("YOU DIED!");
|
||||
} else {
|
||||
@@ -184,10 +201,7 @@ class Player {
|
||||
if (switchState != WeaponSwitchState.idle) return;
|
||||
|
||||
// We pass the isFiring state to handle automatic vs semi-auto behavior
|
||||
bool shotFired = currentWeapon.fire(
|
||||
currentTime,
|
||||
currentAmmo: ammo,
|
||||
);
|
||||
bool shotFired = currentWeapon.fire(currentTime, currentAmmo: ammo);
|
||||
|
||||
if (shotFired && currentWeapon.type != WeaponType.knife) {
|
||||
ammo--;
|
||||
|
||||
Reference in New Issue
Block a user