Search in sources :

Example 1 with ComponentActor

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

the class TransformComponentsAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animation = new ArrayList<>();
    List<Action> transformAnimation = new ArrayList<>();
    for (int i = 0; i < originalComponents.size(); i++) {
        Component originalComponent = originalComponents.get(i);
        Component newComponent = newComponents.get(i);
        for (ComponentActor componentActor : screen.getBoard().getComponents()) {
            if (componentActor.getComponent().equals(originalComponent)) {
                Action transformAction = Actions.sequence(Actions.fadeOut(0.25f * animationSpeed), Actions.run(() -> {
                    componentActor.setRegion(newComponent);
                }), Actions.fadeIn(0.25f * animationSpeed));
                transformAction.setActor(componentActor);
                transformAnimation.add(transformAction);
            }
        }
    }
    animation.add(transformAnimation);
    return animation;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Component(com.janfic.games.computercombat.model.Component) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor)

Example 2 with ComponentActor

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

the class CascadeAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    Board board = screen.getBoard();
    List<List<Action>> actions = new ArrayList<>();
    List<Action> cascadeAnimation = new ArrayList<>();
    Map<Integer, List<CascadeData>> newComponentFallingOrder = new HashMap<>();
    for (CascadeData cas : cascade) {
        boolean found = false;
        for (Cell<ComponentActor>[] cells : board.getBoard()) {
            for (Cell<ComponentActor> cell : cells) {
                if (cell.getActor().getComponent().equals(cas.getOriginalComponent())) {
                    int x = cas.getFallenComponent().getX();
                    int y = cas.getFallenComponent().getY();
                    Action moveAction = Actions.moveTo(24 * x + 7, (8 - (cas.getFallenComponent().getY() + 1)) * 24 + 7, ((cas.getFallenComponent().getY() - cas.getOriginalComponent().getY()) / 4f) * animationSpeed, Interpolation.pow2In);
                    moveAction.setActor(cell.getActor());
                    cascadeAnimation.add(moveAction);
                    found = true;
                }
            }
        }
        if (!found) {
            List<CascadeData> columnFall = newComponentFallingOrder.getOrDefault(cas.getOriginalComponent().getX(), new ArrayList<>());
            columnFall.add(cas);
            newComponentFallingOrder.put(cas.getOriginalComponent().getX(), columnFall);
        }
    }
    Group newSpawn = board.getNewComponentSpawn().getActor();
    for (int x = 0; x < board.getBoard().length; x++) {
        List<CascadeData> columnFall = newComponentFallingOrder.get(x);
        if (columnFall == null) {
            continue;
        }
        columnFall.sort(new Comparator<CascadeData>() {

            @Override
            public int compare(CascadeData o1, CascadeData o2) {
                return o2.getFallenComponent().getY() - o1.getFallenComponent().getY();
            }
        });
        for (int i = 0; i < columnFall.size(); i++) {
            ComponentActor component = new ComponentActor(columnFall.get(i).getFallenComponent());
            newSpawn.addActor(component);
            component.setPosition(24 * x, 3000);
            Action move = Actions.sequence(Actions.moveTo(24 * x, i * 24), Actions.moveTo(24 * x, -(columnFall.get(i).getFallenComponent().getY() + 1) * 24, ((columnFall.get(i).getFallenComponent().getY() - (-1 - i)) / 4f) * animationSpeed, Interpolation.pow2In));
            move.setActor(component);
            cascadeAnimation.add(move);
        }
    }
    actions.add(cascadeAnimation);
    return actions;
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Action(com.badlogic.gdx.scenes.scene2d.Action) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Board(com.janfic.games.computercombat.actors.Board) ArrayList(java.util.ArrayList) List(java.util.List) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor)

Example 3 with ComponentActor

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

the class CollectAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    Map<String, ComputerActor> computerActors = screen.getComputerActors();
    Map<String, List<SoftwareActor>> softwareActors = screen.getSoftwareActors();
    Board board = screen.getBoard();
    List<List<Action>> actions = new ArrayList<>();
    List<Action> popAction = new ArrayList<>();
    List<ComponentActor> componentActors = board.getComponents();
    for (Component component : getAllComponents()) {
        for (ComponentActor componentActor : componentActors) {
            if (componentActor.getComponent().equals(component)) {
                boolean isPlayerMove = currentPlayerUID.equals(playerUID);
                Action a = Actions.sequence(Actions.fadeOut(0.35f * animationSpeed), Actions.delay(0.35f * animationSpeed), Actions.moveTo(isPlayerMove ? 0 : board.getWidth() - 7 - 24, (8 - (componentActor.getComponent().getY() + 1)) * 24 + 7, (isPlayerMove ? componentActor.getComponent().getX() : 7 - componentActor.getComponent().getX()) / 6f * animationSpeed));
                a.setActor(componentActor);
                componentActor.setZIndex(0);
                Action b = Actions.sequence(Actions.fadeOut(0), Actions.visible(true), Actions.fadeIn(0.7f * animationSpeed), Actions.fadeOut((isPlayerMove ? componentActor.getComponent().getX() : 7 - componentActor.getComponent().getX()) / 6f * animationSpeed, Interpolation.fade));
                b.setActor(componentActor.getCollectedRegion());
                Image collectedComponent = new Image(board.getSkin(), "collected_component");
                board.getStage().addActor(collectedComponent);
                collectedComponent.setColor(board.getSkin().getColor(component.getTextureName().toUpperCase()).cpy().mul(1, 1, 1, 0));
                collectedComponent.setZIndex(10);
                int i = 4;
                final ComputerActor computerActor = computerActors.get(currentPlayerUID);
                SoftwareActor tempActor = null;
                if (progress.containsKey(component.toString())) {
                    Card c = progress.get(component.toString());
                    for (int j = 0; j < softwareActors.get(currentPlayerUID).size(); j++) {
                        SoftwareActor softwareActor = softwareActors.get(currentPlayerUID).get(j);
                        if (c.equals(softwareActor.getSoftware())) {
                            tempActor = softwareActor;
                            i = j;
                            break;
                        }
                    }
                }
                final SoftwareActor progressActor = tempActor;
                Vector2 start = new Vector2(isPlayerMove ? -5 : board.getWidth() + 3, (8 - (componentActor.getComponent().getY() + 1)) * 24 + 7 + 12 - 4);
                start = board.localToStageCoordinates(start);
                Vector2 end = board.localToStageCoordinates(new Vector2(isPlayerMove ? -5 : board.getWidth() + 3, gutterYs[i]));
                collectedComponent.setPosition(start.x, start.y);
                Action c = Actions.sequence(Actions.delay(animationSpeed * (isPlayerMove ? componentActor.getComponent().getX() : 7 - componentActor.getComponent().getX()) / 4f + 0.7f - 0.2f), Actions.scaleTo(1, 4 * animationSpeed), Actions.fadeIn(0.2f * animationSpeed), Actions.parallel(Actions.moveTo(end.x, end.y, Math.abs(end.y - start.y) / 100f * animationSpeed, Interpolation.exp5), Actions.sequence(Actions.scaleTo(1, 10, Math.abs(end.y - start.y) / 200f * animationSpeed, Interpolation.circleIn), Actions.scaleTo(1, 1, Math.abs(end.y - start.y) / 200f * animationSpeed, Interpolation.circleOut))), Actions.parallel(Actions.moveBy(isPlayerMove ? -13 : 13, 0, 0.1f * animationSpeed, Interpolation.exp5), Actions.scaleTo(2, 1, 0.1f * animationSpeed)), Actions.fadeOut(0.1f * animationSpeed), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        if (progressActor == null) {
                            computerActor.getComputer().recieveProgress(1);
                            computerActor.addProgress(1);
                        } else {
                            progressActor.getSoftware().recieveProgress(1);
                            for (Actor actor : progressActor.getLEDs().getChildren()) {
                                LEDActor led = (LEDActor) actor;
                                if (led.getComponentColor().equals(SoftwareActor.components.get(component.getColor()))) {
                                    led.setLightOn(true);
                                }
                            }
                        }
                    }
                }), Actions.delay(0.5f * animationSpeed), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        if (progressActor != null) {
                            for (Actor actor : progressActor.getLEDs().getChildren()) {
                                LEDActor led = (LEDActor) actor;
                                if (led.getComponentColor().equals(SoftwareActor.components.get(component.getColor()))) {
                                    led.setLightOn(false);
                                }
                            }
                        }
                    }
                }), Actions.removeActor());
                c.setActor(collectedComponent);
                popAction.add(a);
                popAction.add(b);
                popAction.add(c);
            }
        }
    }
    actions.add(popAction);
    return actions;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Card(com.janfic.games.computercombat.model.Card) Board(com.janfic.games.computercombat.actors.Board) Vector2(com.badlogic.gdx.math.Vector2) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) LEDActor(com.janfic.games.computercombat.actors.LEDActor) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) LEDActor(com.janfic.games.computercombat.actors.LEDActor) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.janfic.games.computercombat.model.Component) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor)

Example 4 with ComponentActor

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

the class SpawnAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animation = new ArrayList<>();
    List<Action> spawn = new ArrayList<>();
    for (Component oldComponent : oldComponents) {
        Action fade = Actions.fadeOut(0.5f);
        fade.setActor(screen.getBoard().getBoard()[oldComponent.getX()][oldComponent.getY()].getActor());
        spawn.add(fade);
    }
    for (Component component : spawned) {
        ComponentActor componentActor = new ComponentActor(component);
        componentActor.setVisible(false);
        screen.getBoard().getBoard()[component.getX()][component.getY()].setActor(componentActor);
        Action spawnAction = Actions.sequence(Actions.scaleTo(1.5f, 1.5f), Actions.alpha(0), Actions.visible(true), Actions.parallel(Actions.scaleTo(1, 1, 0.5f * animationSpeed), Actions.fadeIn(0.5f * animationSpeed)));
        spawnAction.setActor(componentActor);
        spawn.add(spawnAction);
    }
    animation.add(spawn);
    return animation;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Component(com.janfic.games.computercombat.model.Component) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor)

Example 5 with ComponentActor

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

the class SwitchAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> actions = new ArrayList<>();
    if (currentPlayerUID.equals(playerUID)) {
        return actions;
    }
    ComponentActor aActor = screen.getBoard().getBoard()[a.getX()][a.getY()].getActor(), bActor = screen.getBoard().getBoard()[b.getX()][b.getY()].getActor();
    if (aActor == null || bActor == null || aActor == bActor) {
        return actions;
    }
    List<Action> switchActions = new ArrayList<>();
    Vector2 sA = new Vector2(aActor.getX(), aActor.getY());
    Vector2 sB = new Vector2(bActor.getX(), bActor.getY());
    Action actionA = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(sA.x, sA.y, 0.35f * animationSpeed), Actions.scaleTo(1, 1, 0.25f * animationSpeed), Actions.rotateTo(0, 0.25f * animationSpeed));
    Action actionB = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(sB.x, sB.y, 0.35f * animationSpeed), Actions.scaleTo(1, 1, 0.25f * animationSpeed), Actions.rotateTo(0, 0.25f * animationSpeed));
    actionA.setActor(bActor);
    actionB.setActor(aActor);
    switchActions.add(actionA);
    switchActions.add(actionB);
    System.out.println("ANIMATION");
    actions.add(switchActions);
    return actions;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) Vector2(com.badlogic.gdx.math.Vector2) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor)

Aggregations

Action (com.badlogic.gdx.scenes.scene2d.Action)5 ComponentActor (com.janfic.games.computercombat.actors.ComponentActor)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Component (com.janfic.games.computercombat.model.Component)3 Vector2 (com.badlogic.gdx.math.Vector2)2 Board (com.janfic.games.computercombat.actors.Board)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Group (com.badlogic.gdx.scenes.scene2d.Group)1 Cell (com.badlogic.gdx.scenes.scene2d.ui.Cell)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)1 LEDActor (com.janfic.games.computercombat.actors.LEDActor)1 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)1 Card (com.janfic.games.computercombat.model.Card)1 HashMap (java.util.HashMap)1