handleCollision method

void handleCollision(
  1. Set<Vector2> intersectionPoints,
  2. PositionComponent other
)

Handles collision from another component and applies push if needed.

Implementation

void handleCollision(
  Set<Vector2> intersectionPoints,
  PositionComponent other,
) {
  if (!_enabled || other is WithSensor) {
    return;
  }

  if (other is GameComponent) {
    switch (_pushableFrom) {
      case PushableFromEnum.ENEMY:
        if (other is! Enemy) {
          return;
        }
      case PushableFromEnum.PLAYER_OR_ALLY:
        if (other is! Player && other is! Ally) {
          return;
        }
      case PushableFromEnum.ALL:
    }

    final component = other;
    if (component is Movement && _canPush(component)) {
      final displacement = _comp.rectCollision.centerVector2 -
          component.rectCollision.centerVector2;
      if (_pushPerCellEnabled) {
        _movePerCell(component, displacement);
      } else {
        _move(displacement);
      }
    }
  }
}