seeAndMoveToAttackRange method
void
seeAndMoveToAttackRange({
- required dynamic positioned(),
- VoidCallback? notObserved,
- VoidCallback? observed,
- double radiusVision = 32,
- double? visionAngle,
- double? angle,
- double? minDistanceFromPlayer,
- 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 seeAndMoveToAttackRange({
required Function(Player) positioned,
VoidCallback? notObserved,
VoidCallback? observed,
double radiusVision = 32,
double? visionAngle,
double? angle,
double? minDistanceFromPlayer,
bool runOnlyVisibleInScreen = true,
}) {
if (isDead) return;
seePlayer(
radiusVision: radiusVision,
visionAngle: visionAngle,
angle: angle,
observed: (player) {
observed?.call();
positionsItselfAndKeepDistance(
player,
minDistanceFromPlayer: minDistanceFromPlayer,
radiusVision: radiusVision,
runOnlyVisibleInScreen: runOnlyVisibleInScreen,
positioned: (player) {
final playerDirection = getComponentDirectionFromMe(player);
lastDirection = playerDirection;
if (lastDirection == Direction.left ||
lastDirection == Direction.right) {
lastDirectionHorizontal = lastDirection;
}
idle();
positioned(player as Player);
},
);
},
notObserved: () {
if (!isIdle) {
idle();
}
notObserved?.call();
},
);
}