onCollision method

  1. @override
void onCollision(
  1. Set<Vector2> intersectionPoints,
  2. PositionComponent other
)
override

onCollision is called in every tick when this object is colliding with other.

Implementation

@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
  super.onCollision(intersectionPoints, other);
  if (_enablePushable && other is! Sensor) {
    if (other is GameComponent) {
      switch (_pushbleFrom) {
        case PushableFromEnum.ENEMY:
          if (other is! Enemy) {
            return;
          }
        case PushableFromEnum.PLAYER_OR_ALLY:
          if (other is! Player || other is! Ally) {
            return;
          }
        case PushableFromEnum.ALL:
      }
      GameComponent component = other;
      if (component is Movement && onPush(component)) {
        Vector2 displacement = (rectCollision.centerVector2 -
            component.rectCollision.centerVector2);
        if (_pushPerCellEnabled) {
          _movePercell(component, displacement);
        } else {
          _move(component, displacement);
        }
      }
    }
  }
}