simpleAttackRangeByAngle method

void simpleAttackRangeByAngle({
  1. required Future<SpriteAnimation> animation,
  2. required Vector2 size,
  3. required double angle,
  4. required double damage,
  5. required AttackFromEnum attackFrom,
  6. Vector2? destroySize,
  7. Future<SpriteAnimation>? animationDestroy,
  8. dynamic id,
  9. double speed = 150,
  10. bool withDecorationCollision = true,
  11. VoidCallback? onDestroy,
  12. CollisionConfig? 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 AttackFromEnum attackFrom,
  Vector2? destroySize,
  Future<SpriteAnimation>? animationDestroy,
  dynamic id,
  double speed = 150,
  bool withDecorationCollision = true,
  VoidCallback? onDestroy,
  CollisionConfig? collision,
  LightingConfig? lightingConfig,
  double marginFromOrigin = 16,
  Vector2? centerOffset,
}) {
  var initPosition = rectConsideringCollision;

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

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

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

  startPosition.add(Vector2(-size.x / 2, -size.y / 2));
  gameRef.add(
    FlyingAttackObject.byAngle(
      id: id,
      position: startPosition,
      size: size,
      angle: angle,
      damage: damage,
      speed: speed,
      attackFrom: attackFrom,
      collision: collision,
      withDecorationCollision: withDecorationCollision,
      onDestroy: onDestroy,
      destroySize: destroySize,
      flyAnimation: animation,
      animationDestroy: animationDestroy,
      lightingConfig: lightingConfig,
    ),
  );
}