seeComponentType<T extends GameComponent> method

PolygonShape? seeComponentType<T extends GameComponent>({
  1. required dynamic observed(
    1. List<T>
    ),
  2. VoidCallback? notObserved,
  3. double radiusVision = 32,
  4. double? visionAngle,
  5. double angle = 3.14159,
})

This method we notify when detect components by type when enter in radiusVision configuration Method that bo used in update method. visionAngle in radians angle in radians.

Implementation

PolygonShape? seeComponentType<T extends GameComponent>({
  required Function(List<T>) observed,
  VoidCallback? notObserved,
  double radiusVision = 32,
  double? visionAngle,
  double angle = 3.14159,
}) {
  var compVisible = gameRef.visibles<T>();

  if (compVisible.isEmpty) {
    notObserved?.call();
    return _currentShape = null;
  }

  PolygonShape shape = _getShapeVision(radiusVision, visionAngle, angle);

  List<T> compObserved = compVisible.where((comp) {
    return _canSee(shape, comp, radiusVision);
  }).toList();

  if (compObserved.isNotEmpty) {
    observed(compObserved);
  } else {
    notObserved?.call();
  }
  return _currentShape = shape;
}