Search in sources :

Example 1 with ChangeStatAction

use of com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction in project computercombat by janfic.

the class ReceiveDamageAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animations = new ArrayList<>();
    List<Action> changeColorActions = new ArrayList<>();
    SoftwareActor softwareActor = screen.getSoftwareActorByMatchID(reciever.getOwnerUID(), reciever.getMatchID());
    Card a = softwareActor.getSoftware();
    int armorDecrease = a.getArmor() > 0 ? Math.min(a.getArmor(), damage) : 0;
    int healthDecrease = a.getHealth() <= damage - armorDecrease ? a.getHealth() : damage - armorDecrease;
    Action attackedAction = Actions.sequence(Actions.delay(0.5f * animationSpeed), Actions.color(Color.RED), Actions.color(Color.WHITE, 0.4f * animationSpeed), new ChangeStatAction(0.5f * animationSpeed, "armor", -armorDecrease), new ChangeStatAction(0.5f * animationSpeed, "health", -healthDecrease));
    attackedAction.setActor(softwareActor);
    changeColorActions.add(attackedAction);
    animations.add(changeColorActions);
    return animations;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) ChangeStatAction(com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Card(com.janfic.games.computercombat.model.Card) ChangeStatAction(com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction)

Example 2 with ChangeStatAction

use of com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction in project computercombat by janfic.

the class AttackAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animations = new ArrayList<>();
    for (String key : attacks.keySet()) {
        List<Action> attackActions = new ArrayList<>();
        System.out.println(" HERE " + key);
        SoftwareActor attackerActor = screen.getSoftwareActorByMatchID(attackerUID, Integer.parseInt(key));
        attackerActor.setZIndex(1000);
        attackerActor.getParent().setZIndex(Integer.MAX_VALUE);
        for (Integer matchID : attacks.get(key)) {
            Card attacker = attackerActor.getSoftware();
            Card attacked = screen.getSoftwareActorByMatchID(attackedUID, matchID).getSoftware();
            if (attacked.getID() > 0) {
                SoftwareActor attackedActor = screen.getSoftwareActorByMatchID(attackedUID, matchID);
                Vector2 posBack = attackerActor.localToStageCoordinates(new Vector2(attackerActor.getX(), attackerActor.getY()));
                Vector2 pos = attackedActor.localToStageCoordinates(new Vector2(attackedActor.getX(), attackedActor.getY()));
                posBack = attackerActor.stageToLocalCoordinates(posBack);
                pos = attackerActor.stageToLocalCoordinates(pos);
                Action attack = Actions.sequence(Actions.moveTo(pos.x, pos.y, 0.5f * animationSpeed, Interpolation.exp5In), Actions.moveTo(posBack.x, posBack.y, 0.5f * animationSpeed, Interpolation.exp5Out));
                Action attackedAction;
                Card a = attackedActor.getSoftware();
                int armorDecrease = a.getArmor() > 0 ? Math.min(a.getArmor(), attacker.getAttack()) : 0;
                int healthDecrease = a.getHealth() <= attacker.getAttack() - armorDecrease ? a.getHealth() : attacker.getAttack() - armorDecrease;
                attackedAction = Actions.sequence(Actions.delay(0.5f * animationSpeed), Actions.color(Color.RED), Actions.color(Color.WHITE, 0.4f * animationSpeed), new ChangeStatAction(0.5f * animationSpeed, "armor", -armorDecrease), new ChangeStatAction(0.5f * animationSpeed, "health", -healthDecrease));
                attackedAction.setActor(attackedActor);
                attack.setActor(attackerActor);
                attackActions.add(attack);
                attackActions.add(attackedAction);
            } else if (attacked.getID() == 0) {
                ComputerActor attackedActor = screen.getComputerActors().get(attackedUID);
                Action attackedAction;
                Vector2 posBack = attackerActor.localToStageCoordinates(new Vector2(attackerActor.getX(), attackerActor.getY()));
                Vector2 pos = attackedActor.localToStageCoordinates(new Vector2(attackedActor.getX(), attackedActor.getY()));
                posBack = attackerActor.stageToLocalCoordinates(posBack);
                pos = attackerActor.stageToLocalCoordinates(pos);
                Action attack = Actions.sequence(Actions.moveTo(pos.x, pos.y, 0.5f * animationSpeed, Interpolation.exp5In), Actions.moveTo(posBack.x, posBack.y, 0.5f * animationSpeed, Interpolation.exp5Out));
                int healthDecrease = attacker.getAttack();
                attackedAction = Actions.sequence(Actions.delay(0.5f * animationSpeed), Actions.color(Color.RED), Actions.color(Color.WHITE, 0.4f * animationSpeed), new ChangeStatAction(0.5f * animationSpeed, "health", -healthDecrease));
                attackedAction.setActor(attackedActor);
                attack.setActor(attackerActor);
                attackActions.add(attack);
                attackActions.add(attackedAction);
            }
        }
        animations.add(attackActions);
    }
    return animations;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) ChangeStatAction(com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) Card(com.janfic.games.computercombat.model.Card) Vector2(com.badlogic.gdx.math.Vector2) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) ArrayList(java.util.ArrayList) List(java.util.List) ChangeStatAction(com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction)

Aggregations

Action (com.badlogic.gdx.scenes.scene2d.Action)2 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)2 Card (com.janfic.games.computercombat.model.Card)2 ChangeStatAction (com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Vector2 (com.badlogic.gdx.math.Vector2)1 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)1