simpleAttackRangeByDirection method
void
simpleAttackRangeByDirection({
- required Future<
SpriteAnimation> animationRight, - required Future<
SpriteAnimation> animationLeft, - required Future<
SpriteAnimation> animationUp, - required Future<
SpriteAnimation> animationDown, - required double width,
- required double height,
- required Direction direction,
- dynamic id,
- double speed = 150,
- double damage = 1,
- bool withCollision = true,
- bool enableDiagonal = true,
- VoidCallback? destroy,
- CollisionConfig? collision,
- LightingConfig? lightingConfig,
- Future<
SpriteAnimation> ? animationDestroy,
Execute the ranged attack using a component with animation
Implementation
void simpleAttackRangeByDirection({
required Future<SpriteAnimation> animationRight,
required Future<SpriteAnimation> animationLeft,
required Future<SpriteAnimation> animationUp,
required Future<SpriteAnimation> animationDown,
required double width,
required double height,
required Direction direction,
dynamic id,
double speed = 150,
double damage = 1,
bool withCollision = true,
bool enableDiagonal = true,
VoidCallback? destroy,
CollisionConfig? collision,
LightingConfig? lightingConfig,
Future<SpriteAnimation>? animationDestroy,
}) {
Vector2 startPosition;
Future<SpriteAnimation> attackRangeAnimation;
Direction attackDirection = direction;
Vector2Rect rectBase = (this.isObjectCollision())
? (this as ObjectCollision).rectCollision
: position;
switch (attackDirection) {
case Direction.left:
attackRangeAnimation = animationLeft;
startPosition = Vector2(
rectBase.rect.left - width,
(rectBase.rect.top + (rectBase.rect.height - height) / 2),
);
break;
case Direction.right:
attackRangeAnimation = animationRight;
startPosition = Vector2(
rectBase.rect.right,
(rectBase.rect.top + (rectBase.rect.height - height) / 2),
);
break;
case Direction.up:
attackRangeAnimation = animationUp;
startPosition = Vector2(
(rectBase.rect.left + (rectBase.rect.width - width) / 2),
rectBase.rect.top - height,
);
break;
case Direction.down:
attackRangeAnimation = animationDown;
startPosition = Vector2(
(rectBase.rect.left + (rectBase.rect.width - width) / 2),
rectBase.rect.bottom,
);
break;
case Direction.upLeft:
attackRangeAnimation = animationLeft;
startPosition = Vector2(
rectBase.rect.left - width,
(rectBase.rect.top + (rectBase.rect.height - height) / 2),
);
break;
case Direction.upRight:
attackRangeAnimation = animationRight;
startPosition = Vector2(
rectBase.rect.right,
(rectBase.rect.top + (rectBase.rect.height - height) / 2),
);
break;
case Direction.downLeft:
attackRangeAnimation = animationLeft;
startPosition = Vector2(
rectBase.rect.left - width,
(rectBase.rect.top + (rectBase.rect.height - height) / 2),
);
break;
case Direction.downRight:
attackRangeAnimation = animationRight;
startPosition = Vector2(
rectBase.rect.right,
(rectBase.rect.top + (rectBase.rect.height - height) / 2),
);
break;
}
gameRef.add(
FlyingAttackObject(
id: id,
direction: attackDirection,
flyAnimation: attackRangeAnimation,
destroyAnimation: animationDestroy,
position: startPosition,
height: height,
width: width,
damage: damage,
speed: speed,
enableDiagonal: enableDiagonal,
attackFrom:
this is Player ? AttackFromEnum.PLAYER : AttackFromEnum.ENEMY,
onDestroyedObject: destroy,
withDecorationCollision: withCollision,
collision: collision,
lightingConfig: lightingConfig,
),
);
}