simpleAttackMelee method
void
simpleAttackMelee({
- required Future<
SpriteAnimation> attackEffectTopAnim, - required double damage,
- required Vector2 size,
- int? id,
- bool withPush = false,
- double? radAngleDirection,
- VoidCallback? execute,
- int interval = 1000,
Execute simple attack melee using animation
Implementation
void simpleAttackMelee({
required Future<SpriteAnimation> attackEffectTopAnim,
required double damage,
required Vector2 size,
int? id,
bool withPush = false,
double? radAngleDirection,
VoidCallback? execute,
int interval = 1000,
}) {
if (!this.checkInterval('attackMelee', interval, dtUpdate)) return;
if (isDead) return;
double angle = radAngleDirection ?? this.angle;
double nextX = this.height * cos(angle);
double nextY = this.height * sin(angle);
Offset nextPoint = Offset(nextX, nextY);
Vector2 diffBase =
Vector2(this.center.x + nextPoint.dx, this.position.y + nextPoint.dy) -
this.center;
Rect positionAttack = this.toRect().shift(diffBase.toOffset());
gameRef.add(
AnimatedObjectOnce(
animation: attackEffectTopAnim,
position: positionAttack.positionVector2,
size: size,
rotateRadAngle: angle,
),
);
gameRef
.visibleAttackables()
.where((a) => a.rectAttackable().overlaps(positionAttack))
.forEach((attackable) {
attackable.receiveDamage(AttackFromEnum.ENEMY, damage, id);
final rectAfterPush = attackable.position.translate(
diffBase.x,
diffBase.y,
);
if (withPush &&
(attackable is ObjectCollision &&
!(attackable as ObjectCollision)
.isCollision(displacement: rectAfterPush)
.isNotEmpty)) {
attackable.position = rectAfterPush;
}
});
if (execute != null) execute();
}