#4 improve attack behavior (animation)
This commit is contained in:
@@ -20,7 +20,7 @@ public enum AnimationState implements State<Entity> {
|
||||
@Override
|
||||
public void update(Entity entity) {
|
||||
Move move = Move.MAPPER.get(entity);
|
||||
if (move != null && !move.getDirection().isZero()) {
|
||||
if (move != null && !move.isRooted() && !move.getDirection().isZero()) {
|
||||
Fsm.MAPPER.get(entity).getAnimationFsm().changeState(WALK);
|
||||
return;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public enum AnimationState implements State<Entity> {
|
||||
@Override
|
||||
public void update(Entity entity) {
|
||||
Move move = Move.MAPPER.get(entity);
|
||||
if (move.getDirection().isZero()) {
|
||||
if (move.getDirection().isZero() || move.isRooted()) {
|
||||
Fsm.MAPPER.get(entity).getAnimationFsm().changeState(IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public class Move implements Component {
|
||||
|
||||
private float maxSpeed;
|
||||
private final Vector2 direction;
|
||||
private boolean isRooted;
|
||||
|
||||
public Move(float maxSpeed) {
|
||||
this.maxSpeed = maxSpeed;
|
||||
@@ -22,4 +23,12 @@ public class Move implements Component {
|
||||
public Vector2 getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setRooted(boolean rooted) {
|
||||
this.isRooted = rooted;
|
||||
}
|
||||
|
||||
public boolean isRooted() {
|
||||
return isRooted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import io.github.com.quillraven.component.Damaged;
|
||||
import io.github.com.quillraven.component.Facing;
|
||||
import io.github.com.quillraven.component.Facing.FacingDirection;
|
||||
import io.github.com.quillraven.component.Life;
|
||||
import io.github.com.quillraven.component.Move;
|
||||
import io.github.com.quillraven.component.Physic;
|
||||
|
||||
public class AttackSystem extends IteratingSystem {
|
||||
@@ -46,6 +47,10 @@ public class AttackSystem extends IteratingSystem {
|
||||
|
||||
if (attack.hasAttackStarted() && attack.getSfx() != null) {
|
||||
audioService.playSound(attack.getSfx());
|
||||
Move move = Move.MAPPER.get(entity);
|
||||
if (move != null) {
|
||||
move.setRooted(true);
|
||||
}
|
||||
}
|
||||
|
||||
attack.decAttackTimer(deltaTime);
|
||||
@@ -57,6 +62,11 @@ public class AttackSystem extends IteratingSystem {
|
||||
|
||||
this.attackDamage = attack.getDamage();
|
||||
world.QueryAABB(this::attackCallback, attackAABB.x, attackAABB.y, attackAABB.width, attackAABB.height);
|
||||
|
||||
Move move = Move.MAPPER.get(entity);
|
||||
if (move != null) {
|
||||
move.setRooted(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ public class PhysicMoveSystem extends IteratingSystem {
|
||||
Move move = Move.MAPPER.get(entity);
|
||||
Physic physic = Physic.MAPPER.get(entity);
|
||||
Body body = physic.getBody();
|
||||
if (move.getDirection().isZero()) {
|
||||
// no direction given -> stop movement
|
||||
if (move.isRooted() || move.getDirection().isZero()) {
|
||||
// no direction given or rooted -> stop movement
|
||||
body.setLinearVelocity(0f, 0f);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user