seeComponent method

void seeComponent(
  1. GameComponent component, {
  2. required dynamic observed(
    1. GameComponent
    ),
  3. VoidCallback? notObserved,
  4. double radiusVision = 32,
})

This method we notify when detect the component when enter in radiusVision configuration Method that bo used in update method.

Implementation

void seeComponent(
  GameComponent component, {
  required Function(GameComponent) observed,
  VoidCallback? notObserved,
  double radiusVision = 32,
}) {
  if (component.shouldRemove) {
    if (notObserved != null) notObserved();
    return;
  }

  double vision = radiusVision * 2;

  Rect fieldOfVision = Rect.fromLTWH(
    this.position.center.dx - radiusVision,
    this.position.center.dy - radiusVision,
    vision,
    vision,
  );

  if (fieldOfVision.overlaps(getRectAndCollision(component).rect)) {
    observed(component);
  } else {
    notObserved?.call();
  }
}