simpleAttackMeleeByAngle method
void
simpleAttackMeleeByAngle({
- dynamic id,
- Future<
SpriteAnimation> ? animation, - required double damage,
- required double angle,
- required AttackOriginEnum attackFrom,
- required Vector2 size,
- bool withPush = true,
- double marginFromCenter = 0,
- Vector2? centerOffset,
- void onDamage(
- Attackable attackable
Execute simple attack melee using animation
Implementation
void simpleAttackMeleeByAngle({
dynamic id,
/// use animation facing right.
Future<SpriteAnimation>? animation,
required double damage,
/// Use radians angle
required double angle,
required AttackOriginEnum attackFrom,
required Vector2 size,
bool withPush = true,
double marginFromCenter = 0,
Vector2? centerOffset,
void Function(Attackable attackable)? onDamage,
}) {
var initPosition = rectCollision;
Vector2 startPosition =
initPosition.center.toVector2() + (centerOffset ?? Vector2.zero());
double displacement = max(
initPosition.width,
initPosition.height,
) /
2 +
marginFromCenter;
Vector2 diffBase = BonfireUtil.diffMovePointByAngle(
startPosition,
displacement,
angle,
);
startPosition.add(diffBase);
if (animation != null) {
gameRef.add(
AnimatedGameObject(
animation: animation,
position: startPosition,
size: size,
angle: angle,
anchor: Anchor.center,
loop: false,
renderAboveComponents: true,
),
);
}
gameRef.add(
DamageHitbox(
position: startPosition,
damage: damage,
origin: attackFrom,
size: size,
angle: angle,
id: id,
onDamage: (attackable) {
onDamage?.call(attackable);
if (withPush && attackable is Movement) {
_doPush(
attackable as Movement,
BonfireUtil.getDirectionFromAngle(angle),
diffBase,
);
}
},
),
);
}