simpleAttackRangeByDirection method

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

Execute the ranged attack using a component with animation

Implementation

void simpleAttackRangeByDirection({
  required Future<SpriteAnimation> animationRight,
  required Vector2 size,
  required Direction direction,
  required AttackOriginEnum attackFrom,
  Vector2? destroySize,
  dynamic id,
  double speed = 150,
  double damage = 1,
  bool withCollision = true,
  VoidCallback? onDestroy,
  ShapeHitbox? collision,
  LightingConfig? lightingConfig,
  Future<SpriteAnimation>? animationDestroy,
  double marginFromOrigin = 16,
  Vector2? centerOffset,
}) {
  final initPosition = rectCollision;

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

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

  startPosition = BonfireUtil.movePointByAngle(
    startPosition,
    displacement,
    direction.toRadians(),
  );
  gameRef.add(
    FlyingAttackGameObject.byDirection(
      direction: direction,
      animation: animationRight,
      attackFrom: attackFrom,
      damage: damage,
      size: size,
      animationDestroy: animationDestroy,
      destroySize: destroySize,
      id: id,
      lightingConfig: lightingConfig,
      onDestroy: onDestroy,
      speed: speed,
      withDecorationCollision: withCollision,
      position: startPosition,
    ),
  );
}