Fire weapons

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-13 20:36:40 +01:00
parent fb2b297900
commit 029e90ea9d
6 changed files with 143 additions and 1 deletions

View File

@@ -2,6 +2,10 @@ import 'dart:math' as math;
import 'package:wolf_dart/classes/linear_coordinates.dart';
import 'package:wolf_dart/features/entities/collectible.dart';
import 'package:wolf_dart/features/player/weapon.dart';
import 'package:wolf_dart/features/player/weapons/knife.dart';
import 'package:wolf_dart/features/player/weapons/machine_gun.dart';
import 'package:wolf_dart/features/player/weapons/pistol.dart';
class Player {
// Spatial
@@ -20,11 +24,20 @@ class Player {
bool hasMachineGun = false;
bool hasChainGun = false;
// Weapon
late Weapon currentWeapon;
final List<Weapon> availableWeapons = [];
Player({
required this.x,
required this.y,
required this.angle,
});
}) {
// Start with Knife and Pistol
availableWeapons.add(Knife());
availableWeapons.add(Pistol());
currentWeapon = availableWeapons[1];
}
// Helper getter to interface with the RaycasterPainter
LinearCoordinates get position => (x: x, y: y);
@@ -105,4 +118,28 @@ class Player {
}
return pickedUp;
}
void fire(int currentTime) {
bool shotFired = currentWeapon.fire(currentTime, currentAmmo: ammo);
// If it was a gun (not a knife) and it fired, consume ammo
if (shotFired && currentWeapon is! Knife) {
ammo--;
}
// TODO: We'll add Raycast hit detection here next!
}
void updateWeapon(int currentTime) {
currentWeapon.update(currentTime);
}
// Logic to switch weapons (e.g., picking up the Machine Gun)
void equipBestWeapon() {
if (hasChainGun) {
/* set chain gun */
} else if (hasMachineGun) {
currentWeapon = MachineGun();
}
}
}