simpleAttackRange method

void simpleAttackRange({
  1. required Future<SpriteAnimation> animation,
  2. required Future<SpriteAnimation> animationDestroy,
  3. required Vector2 size,
  4. Vector2? destroySize,
  5. int? id,
  6. double speed = 150,
  7. double damage = 1,
  8. int interval = 1000,
  9. bool withCollision = true,
  10. bool useAngle = false,
  11. ShapeHitbox? collision,
  12. VoidCallback? onDestroy,
  13. VoidCallback? execute,
  14. LightingConfig? lightingConfig,
})

Execute the ranged attack using a component with animation

Implementation

void simpleAttackRange({
  required Future<SpriteAnimation> animation,
  required Future<SpriteAnimation> animationDestroy,
  required Vector2 size,
  Vector2? destroySize,
  int? id,
  double speed = 150,
  double damage = 1,
  int interval = 1000,
  bool withCollision = true,
  bool useAngle = false,
  ShapeHitbox? collision,
  VoidCallback? onDestroy,
  VoidCallback? execute,
  LightingConfig? lightingConfig,
}) {
  if (!checkInterval('attackRange', interval, dtUpdate) || isDead) {
    return;
  }

  if (useAngle) {
    simpleAttackRangeByAngle(
      animation: animation,
      animationDestroy: animationDestroy,
      size: size,
      angle: getAngleToPlayer(),
      id: id,
      speed: speed,
      damage: damage,
      withDecorationCollision: withCollision,
      collision: collision,
      onDestroy: onDestroy,
      destroySize: destroySize,
      lightingConfig: lightingConfig,
      attackFrom: AttackOriginEnum.ENEMY,
    );
  } else {
    final direct = gameRef.player != null
        ? getDirectionToTarget(gameRef.player!)
        : lastDirection;
    simpleAttackRangeByDirection(
      animationRight: animation,
      animationDestroy: animationDestroy,
      size: size,
      direction: direct,
      id: id,
      speed: speed,
      damage: damage,
      withCollision: withCollision,
      collision: collision,
      onDestroy: onDestroy,
      destroySize: destroySize,
      lightingConfig: lightingConfig,
      attackFrom: AttackOriginEnum.ENEMY,
    );
  }

  execute?.call();
}