Fixed pistol and knife sprites for retail. Added firing mechanism.
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -120,14 +120,11 @@ class Player {
|
||||
}
|
||||
|
||||
void fire(int currentTime) {
|
||||
// Only spend ammo if the weapon isn't a knife
|
||||
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) {
|
||||
|
||||
@@ -16,16 +16,13 @@ abstract class Weapon {
|
||||
required this.idleSprite,
|
||||
required this.fireFrames,
|
||||
required this.damage,
|
||||
this.msPerFrame = 100, // Speed of animation
|
||||
this.msPerFrame = 100,
|
||||
});
|
||||
|
||||
int get currentSprite =>
|
||||
state == WeaponState.idle ? idleSprite : fireFrames[frameIndex];
|
||||
|
||||
bool get isFiring => state == WeaponState.firing;
|
||||
|
||||
/// The main entry point for the player to use the gun.
|
||||
/// Returns true if a bullet was actually spent.
|
||||
/// Core firing logic. Returns true if a bullet was spent.
|
||||
bool fire(int currentTime, {required int currentAmmo}) {
|
||||
if (state == WeaponState.idle && currentAmmo > 0) {
|
||||
state = WeaponState.firing;
|
||||
|
||||
@@ -5,14 +5,13 @@ class Knife extends Weapon {
|
||||
: super(
|
||||
name: "Knife",
|
||||
idleSprite: 416,
|
||||
fireFrames: [417, 418, 419],
|
||||
fireFrames: [417, 418, 419, 420],
|
||||
damage: 15,
|
||||
msPerFrame: 120,
|
||||
);
|
||||
|
||||
@override
|
||||
bool fire(int currentTime, {required int currentAmmo}) {
|
||||
// Knife doesn't need ammo!
|
||||
if (state == WeaponState.idle) {
|
||||
state = WeaponState.firing;
|
||||
frameIndex = 0;
|
||||
|
||||
@@ -4,8 +4,8 @@ class Pistol extends Weapon {
|
||||
Pistol()
|
||||
: super(
|
||||
name: "Pistol",
|
||||
idleSprite: 408,
|
||||
fireFrames: [409, 410, 411, 412],
|
||||
idleSprite: 421,
|
||||
fireFrames: [422, 423, 424, 425],
|
||||
damage: 20,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user