Moving attacks to Domain-Driven Design and Entity-Component architecture

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 00:22:47 +01:00
parent 0fe530e58e
commit 09c28028ad
4 changed files with 112 additions and 68 deletions

View File

@@ -2,6 +2,7 @@ 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/entities/entity.dart';
import 'package:wolf_dart/features/weapon/weapon.dart';
import 'package:wolf_dart/features/weapon/weapons/chain_gun.dart';
import 'package:wolf_dart/features/weapon/weapons/knife.dart';
@@ -194,15 +195,30 @@ class Player {
}
/// Returns true only on the specific frame where the hit should be calculated
bool updateWeapon(int currentTime) {
void updateWeapon({
required int currentTime,
required List<Entity> entities,
required bool Function(int x, int y) isWalkable,
}) {
int oldFrame = currentWeapon.frameIndex;
currentWeapon.update(currentTime);
// If we just crossed into the firing frame...
if (currentWeapon.state == WeaponState.firing &&
oldFrame == 0 &&
currentWeapon.frameIndex == 1) {
return true;
// The weapon handles everything itself!
currentWeapon.performHitscan(
playerX: x,
playerY: y,
playerAngle: angle,
entities: entities,
isWalkable: isWalkable,
currentTime: currentTime,
onEnemyKilled: (int pointsToAdd) {
score += pointsToAdd;
},
);
}
return false;
}
}