seeAndMoveToEnemy method
void
seeAndMoveToEnemy({
- required dynamic closeEnemy(),
- VoidCallback? notObserved,
- VoidCallback? observed,
- VoidCallback? notCanMove,
- double radiusVision = 32,
- double? visionAngle,
- double? angle,
- double margin = 10,
- bool runOnlyVisibleInScreen = true,
Checks whether the player is within range. If so, move to it.
visionAngle
in radians
angle
in radians. is automatically picked up using the component's direction.
Implementation
void seeAndMoveToEnemy({
required Function(Enemy) closeEnemy,
VoidCallback? notObserved,
VoidCallback? observed,
VoidCallback? notCanMove,
double radiusVision = 32,
double? visionAngle,
double? angle,
double margin = 10,
bool runOnlyVisibleInScreen = true,
}) {
if (runOnlyVisibleInScreen && !isVisible) return;
seeComponentType<Enemy>(
radiusVision: radiusVision,
visionAngle: visionAngle,
angle: angle ?? lastDirection.toRadians(),
observed: (enemy) {
observed?.call();
bool move = followComponent(
enemy.first,
dtUpdate,
closeComponent: (comp) => closeEnemy(comp as Enemy),
margin: margin,
);
if (!move) {
notCanMove?.call();
}
},
notObserved: () {
if (!isIdle) {
idle();
}
notObserved?.call();
},
);
}