seeAndMoveToAttackRange method

void seeAndMoveToAttackRange({
  1. required dynamic positioned(
    1. Player
    ),
  2. VoidCallback? notObserved,
  3. VoidCallback? observed,
  4. double radiusVision = 32,
  5. double? visionAngle,
  6. double? angle,
  7. double? minDistanceFromPlayer,
  8. 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();
    },
  );
}