simpleAttackRangeByAngle method

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

Execute the ranged attack using a component with animation

Implementation

void simpleAttackRangeByAngle({
  /// use animation facing right.
  required Future<SpriteAnimation> animation,
  required Vector2 size,

  /// Use radians angle
  required double angle,
  required double damage,
  required AttackOriginEnum attackFrom,
  Vector2? destroySize,
  Future<SpriteAnimation>? animationDestroy,
  dynamic id,
  double speed = 150,
  bool withDecorationCollision = true,
  VoidCallback? onDestroy,
  ShapeHitbox? collision,
  LightingConfig? lightingConfig,
  double marginFromOrigin = 16,
  Vector2? centerOffset,
}) {
  var initPosition = rectCollision;

  Vector2 startPosition =
      initPosition.center.toVector2() + (centerOffset ?? Vector2.zero());

  double displacement =
      max(initPosition.width, initPosition.height) / 2 + marginFromOrigin;

  startPosition = BonfireUtil.movePointByAngle(
    startPosition,
    displacement,
    angle,
  );

  gameRef.add(
    FlyingAttackGameObject.byAngle(
      id: id,
      position: startPosition,
      size: size,
      angle: angle,
      damage: damage,
      speed: speed,
      attackFrom: attackFrom,
      collision: collision,
      withDecorationCollision: withDecorationCollision,
      onDestroy: onDestroy,
      destroySize: destroySize,
      animation: animation,
      animationDestroy: animationDestroy,
      lightingConfig: lightingConfig,
    ),
  );
}