range method

void range({
  1. required Future<SpriteAnimation> animation,
  2. required Vector2 size,
  3. Future<SpriteAnimation>? animationDestroy,
  4. Vector2? destroySize,
  5. dynamic id,
  6. double speed = 150,
  7. double damage = 1,
  8. Direction? direction,
  9. double? angle,
  10. bool useAngle = false,
  11. bool withCollision = true,
  12. bool withDecorationCollision = true,
  13. ShapeHitbox? collision,
  14. VoidCallback? onDestroy,
  15. LightingConfig? lightingConfig,
  16. Vector2? centerOffset,
  17. double marginFromOrigin = 16,
  18. AttackOriginEnum? attackFrom,
})

Executes a ranged attack. If angle (radians) or useAngle is provided the projectile is fired in that direction, otherwise direction is used (defaults to the player or the component direction).

Implementation

void range({
  required Future<SpriteAnimation> animation,
  required Vector2 size,
  Future<SpriteAnimation>? animationDestroy,
  Vector2? destroySize,
  dynamic id,
  double speed = 150,
  double damage = 1,
  Direction? direction,
  double? angle,
  bool useAngle = false,
  bool withCollision = true,
  bool withDecorationCollision = true,
  ShapeHitbox? collision,
  VoidCallback? onDestroy,
  LightingConfig? lightingConfig,
  Vector2? centerOffset,
  double marginFromOrigin = 16,
  AttackOriginEnum? attackFrom,
}) {
  final origin = attackFrom ?? _defaultAttackFrom();
  if (angle != null || useAngle) {
    rangeByAngle(
      animation: animation,
      animationDestroy: animationDestroy,
      size: size,
      angle: angle ?? comp.util.getAngleToPlayer(),
      damage: damage,
      attackFrom: origin,
      destroySize: destroySize,
      id: id,
      speed: speed,
      withDecorationCollision: withDecorationCollision,
      onDestroy: onDestroy,
      collision: collision,
      lightingConfig: lightingConfig,
      centerOffset: centerOffset,
      marginFromOrigin: marginFromOrigin,
    );
  } else {
    rangeByDirection(
      animationRight: animation,
      animationDestroy: animationDestroy,
      size: size,
      direction: direction ?? _defaultMeleeDirection(true),
      damage: damage,
      attackFrom: origin,
      destroySize: destroySize,
      id: id,
      speed: speed,
      withCollision: withCollision,
      onDestroy: onDestroy,
      collision: collision,
      lightingConfig: lightingConfig,
      centerOffset: centerOffset,
      marginFromOrigin: marginFromOrigin,
    );
  }
}