Can now open secret walls and pick up machine gun

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 15:34:27 +01:00
parent 9f5f29100b
commit 001c7c3131
13 changed files with 545 additions and 120 deletions

View File

@@ -14,10 +14,12 @@ abstract class Weapon {
final List<int> fireFrames;
final int damage;
final int msPerFrame;
final bool isAutomatic;
WeaponState state = WeaponState.idle;
int frameIndex = 0;
int lastFrameTime = 0;
bool _triggerReleased = true;
Weapon({
required this.type,
@@ -25,16 +27,24 @@ abstract class Weapon {
required this.fireFrames,
required this.damage,
this.msPerFrame = 100,
this.isAutomatic = true,
});
int get currentSprite =>
state == WeaponState.idle ? idleSprite : fireFrames[frameIndex];
void releaseTrigger() {
_triggerReleased = true;
}
bool fire(int currentTime, {required int currentAmmo}) {
if (state == WeaponState.idle && currentAmmo > 0) {
if (!isAutomatic && !_triggerReleased) return false;
state = WeaponState.firing;
frameIndex = 0;
lastFrameTime = currentTime;
_triggerReleased = false;
return true;
}
return false;
@@ -61,7 +71,7 @@ abstract class Weapon {
required List<Entity> entities,
required bool Function(int x, int y) isWalkable,
required int currentTime,
required void Function(int scoreToAdd) onEnemyKilled,
required void Function(Enemy killedEnemy) onEnemyKilled,
}) {
Enemy? closestEnemy;
double minDistance = 15.0;
@@ -85,7 +95,6 @@ abstract class Weapon {
if (angleDiff.abs() < threshold) {
Coordinate2D source = Coordinate2D(playerX, playerY);
// Delegate to the enemy to check if it's visible
if (entity.hasLineOfSightFrom(
source,
playerAngle,
@@ -103,8 +112,10 @@ abstract class Weapon {
if (closestEnemy != null) {
closestEnemy.takeDamage(damage, currentTime);
// If the shot was fatal, pass the enemy back so the Player class
// can calculate the correct score based on enemy type!
if (closestEnemy.state == EntityState.dead) {
onEnemyKilled(100);
onEnemyKilled(closestEnemy);
}
}
}

View File

@@ -8,6 +8,7 @@ class Knife extends Weapon {
fireFrames: [417, 418, 419, 420],
damage: 15,
msPerFrame: 120,
isAutomatic: false,
);
@override

View File

@@ -7,5 +7,6 @@ class Pistol extends Weapon {
idleSprite: 421,
fireFrames: [422, 423, 424, 425],
damage: 20,
isAutomatic: false,
);
}