meleeByAngle method
void
meleeByAngle({
- required double damage,
- required double angle,
- required AttackOriginEnum attackFrom,
- required Vector2 size,
- dynamic id,
- Future<
SpriteAnimation> ? animation, - bool withPush = true,
- double marginFromCenter = 0,
- Vector2? centerOffset,
- void onDamage(
- WithLife attackable
Executes a melee attack by angle (radians).
Implementation
void meleeByAngle({
required double damage,
required double angle,
required AttackOriginEnum attackFrom,
required Vector2 size,
dynamic id,
Future<SpriteAnimation>? animation,
bool withPush = true,
double marginFromCenter = 0,
Vector2? centerOffset,
void Function(WithLife attackable)? onDamage,
}) {
final initPosition = comp.rectCollision;
final startPosition =
initPosition.center.toVector2() + (centerOffset ?? Vector2.zero());
final displacement =
max(initPosition.width, initPosition.height) / 2 + marginFromCenter;
final diffBase = BonfireUtil.diffMovePointByAngle(
startPosition,
displacement,
angle,
);
startPosition.add(diffBase);
if (animation != null) {
comp.gameRef.add(
AnimatedGameObject(
animation: animation,
position: startPosition,
size: size,
angle: angle,
anchor: Anchor.center,
loop: false,
renderAboveComponents: true,
),
);
}
comp.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,
);
}
},
),
);
}