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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user