Search in sources :

Example 6 with SoftwareActor

use of com.janfic.games.computercombat.actors.SoftwareActor in project computercombat by janfic.

the class ConsumeProgressAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animation = new ArrayList<>();
    List<Action> actions = new ArrayList<>();
    int index = -1;
    List<SoftwareActor> softwareActors = screen.getSoftwareActors().get(this.playerUID);
    for (int i = 0; i < softwareActors.size(); i++) {
        SoftwareActor softwareActor = softwareActors.get(i);
        if (software.get(0).equals(softwareActor.getSoftware())) {
            index = i;
            break;
        }
    }
    if (software.get(0).equals(screen.getComputerActors().get(this.playerUID).getComputer())) {
        DrainProgressAction drain = new DrainProgressAction(1 * animationSpeed);
        drain.setActor(screen.getComputerActors().get(this.playerUID));
        actions.add(drain);
    } else if (index != -1) {
        DrainProgressAction drain = new DrainProgressAction(1 * animationSpeed);
        drain.setActor(softwareActors.get(index));
        actions.add(drain);
    }
    animation.add(actions);
    return animation;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) TemporalAction(com.badlogic.gdx.scenes.scene2d.actions.TemporalAction) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with SoftwareActor

use of com.janfic.games.computercombat.actors.SoftwareActor in project computercombat by janfic.

the class DrawAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    Table leftPanel = screen.getLeftPanel();
    Table rightPanel = screen.getRightPanel();
    Table panel;
    if (playerUID.equals(currentPlayerUID)) {
        panel = leftPanel;
    } else {
        panel = rightPanel;
    }
    List<List<Action>> animations = new ArrayList<>();
    ComputerCombatGame game = (ComputerCombatGame) Gdx.app.getApplicationListener();
    if (newSoftware.size() > 0) {
        List<Action> cardAnimation = new ArrayList<>();
        Table t = new Table();
        t.setFillParent(true);
        Card loadNewCard = SQLAPI.getSingleton().getCardById(newSoftware.get(0).getID(), newSoftware.get(0).getOwnerUID());
        loadNewCard.setMatchID(newSoftware.get(0).getMatchID());
        CollectionCard card = new CollectionCard(game, screen.getSkin(), loadNewCard, 1);
        card.setTouchable(Touchable.disabled);
        Stage stage = screen.getMainStage();
        stage.addActor(t);
        card.setVisible(false);
        card.setPosition(stage.getWidth() / 2, -300);
        t.add(card).expand().center();
        Action cardAction = Actions.sequence(Actions.moveBy(0, -400), Actions.visible(true), Actions.moveBy(0, 400, 1 * animationSpeed, Interpolation.fastSlow), Actions.delay(1 * animationSpeed), Actions.moveBy(0, -400, 1 * animationSpeed, Interpolation.slowFast));
        cardAction.setActor(card);
        cardAnimation.add(cardAction);
        animations.add(cardAnimation);
        List<SoftwareActor> softwareActors = screen.getSoftwareActors().get(currentPlayerUID);
        ComputerActor computerActor = screen.getComputerActors().get(currentPlayerUID);
        List<Action> softwareAnimation = new ArrayList<>();
        SoftwareActor softwareActor = new SoftwareActor(screen.getSkin(), !playerUID.equals(currentPlayerUID), loadNewCard, game);
        panel.clear();
        for (SoftwareActor s : softwareActors) {
            panel.add(s).row();
        }
        panel.add(softwareActor).row();
        panel.add(computerActor).expandY().growX().bottom();
        softwareActor.setVisible(false);
        softwareActors.add(softwareActor);
        Action softwareActorAction = Actions.sequence(Actions.moveBy(0, -400), Actions.visible(true), Actions.moveBy(0, 400, 1 * animationSpeed, Interpolation.fastSlow));
        softwareActorAction.setActor(softwareActor);
        softwareAnimation.add(softwareActorAction);
        animations.add(softwareAnimation);
    }
    return animations;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ArrayList(java.util.ArrayList) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) ComputerCombatGame(com.janfic.games.computercombat.ComputerCombatGame) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with SoftwareActor

use of com.janfic.games.computercombat.actors.SoftwareActor in project computercombat by janfic.

the class TransformCardAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> actions = new ArrayList<>();
    List<Action> transform = new ArrayList<>();
    for (Card oldCard : oldCards) {
        SoftwareActor actor = screen.getSoftwareActorByMatchID(oldCard.getOwnerUID(), oldCard.getMatchID());
        Action transformAction = Actions.sequence(Actions.moveBy(-2.5f, 0.2f * animationSpeed), Actions.repeat(10, Actions.sequence(Actions.moveBy(5, 0.2f * animationSpeed), Actions.moveBy(-5, 0.2f * animationSpeed))), Actions.moveBy(2.5f, 0.2f * animationSpeed), Actions.run(() -> {
            Card card = SQLAPI.getSingleton().getCardById(newCards.get(oldCards.indexOf(oldCard)).getID(), newCards.get(oldCards.indexOf(oldCard)).getOwnerUID());
            card.setMatchID(newCards.get(oldCards.indexOf(oldCard)).getMatchID());
            actor.buildActor(!currentPlayerUID.equals(playerUID), card, screen.getGame());
        }));
        transformAction.setActor(actor);
        transform.add(transformAction);
    }
    actions.add(transform);
    return actions;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) 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)

Example 9 with SoftwareActor

use of com.janfic.games.computercombat.actors.SoftwareActor 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)9 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Card (com.janfic.games.computercombat.model.Card)8 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)3 Vector2 (com.badlogic.gdx.math.Vector2)2 TemporalAction (com.badlogic.gdx.scenes.scene2d.actions.TemporalAction)2 ChangeStatAction (com.janfic.games.computercombat.model.animations.ChangeStatAnim.ChangeStatAction)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ComputerCombatGame (com.janfic.games.computercombat.ComputerCombatGame)1 Board (com.janfic.games.computercombat.actors.Board)1 CollectionCard (com.janfic.games.computercombat.actors.CollectionCard)1 ComponentActor (com.janfic.games.computercombat.actors.ComponentActor)1 LEDActor (com.janfic.games.computercombat.actors.LEDActor)1 Component (com.janfic.games.computercombat.model.Component)1