Search in sources :

Example 1 with Component

use of com.janfic.games.computercombat.model.Component 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 Component

use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.

the class MatchState method buildNeighbors.

public static void buildNeighbors(Component[][] componentBoard) {
    for (int x = 0; x < componentBoard.length; x++) {
        for (int y = 0; y < componentBoard[x].length; y++) {
            componentBoard[x][y].invalidate();
            for (int i = 0; i < Component.coordsToNeighbors.length; i += 3) {
                int neighborX = x + Component.coordsToNeighbors[i];
                int neighborY = y + Component.coordsToNeighbors[i + 1];
                if (neighborX < componentBoard.length && neighborY < componentBoard[x].length && neighborX >= 0 && neighborY >= 0) {
                    Component c = componentBoard[neighborX][neighborY];
                    componentBoard[x][y].setNeighbor(Component.coordsToNeighbors[i + 2], c);
                }
            }
        }
    }
}
Also used : Component(com.janfic.games.computercombat.model.Component)

Example 3 with Component

use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.

the class MatchState method read.

@Override
public void read(Json json, JsonValue jsonData) {
    json.setTypeName("class");
    this.players = json.readValue("players", List.class, Player.class, jsonData);
    json.setTypeName(null);
    this.isGameOver = json.readValue("isGameOver", boolean.class, jsonData);
    this.winner = json.readValue("winner", String.class, jsonData);
    this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
    this.decks = json.readValue("decks", HashMap.class, Deck.class, jsonData);
    HashMap<String, List<JsonValue>> v = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
    this.activeEntities = new HashMap<>();
    for (String string : v.keySet()) {
        List<Card> cards = new ArrayList<>();
        for (JsonValue jsonValue : v.get(string)) {
            Card c = json.readValue(Card.class, jsonValue);
            cards.add(c);
        }
        activeEntities.put(string, cards);
    }
    this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
    String boardString = json.readValue("componentBoard", String.class, jsonData);
    componentBoard = new Component[8][8];
    assert (boardString.length() == 64);
    for (int i = 0; i < boardString.length(); i++) {
        int x = i / 8;
        int y = i % 8;
        try {
            componentBoard[x][y] = new Component(Integer.parseInt("" + boardString.substring(i, i + 1)), x, y);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    json.setTypeName("class");
}
Also used : Player(com.janfic.games.computercombat.model.Player) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonValue(com.badlogic.gdx.utils.JsonValue) Deck(com.janfic.games.computercombat.model.Deck) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.janfic.games.computercombat.model.Component)

Example 4 with Component

use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.

the class MatchState method cascade.

public List<CascadeData> cascade() {
    List<CascadeAnimation.CascadeData> cascade = new ArrayList<>();
    for (int x = 0; x < componentBoard.length; x++) {
        for (int y = componentBoard[x].length - 1; y >= 0; y--) {
            if (componentBoard[x][y].getColor() == 0) {
                componentBoard[x][y].invalidate();
                componentBoard[x][y].invalidateNeighbors();
                boolean cascaded = false;
                for (int i = y - 1; i >= 0; i--) {
                    if (componentBoard[x][i].getColor() != 0) {
                        Component fallenComponent = new Component(componentBoard[x][i].getColor(), x, y);
                        Component originalComponent = new Component(componentBoard[x][i]);
                        cascade.add(new CascadeAnimation.CascadeData(fallenComponent, originalComponent));
                        componentBoard[x][y].changeColor(componentBoard[x][i].getColor());
                        componentBoard[x][i].changeColor(0);
                        cascaded = true;
                        break;
                    }
                }
                if (cascaded == false) {
                    componentBoard[x][y].changeColor(GameRules.getNewColor());
                    cascade.add(new CascadeAnimation.CascadeData(new Component(componentBoard[x][y]), x, (-y) - 1));
                }
            }
        }
    }
    return cascade;
}
Also used : ArrayList(java.util.ArrayList) CascadeAnimation(com.janfic.games.computercombat.model.animations.CascadeAnimation) Component(com.janfic.games.computercombat.model.Component) CascadeData(com.janfic.games.computercombat.model.animations.CascadeAnimation.CascadeData) CascadeData(com.janfic.games.computercombat.model.animations.CascadeAnimation.CascadeData)

Example 5 with Component

use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.

the class MatchState method progress.

public void progress(CollectAnimation collectAnimation) {
    Map<Component, Card> progress = collectAnimation.progress;
    for (Component c : collectAnimation.getAllComponents()) {
        boolean collectedByCard = false;
        for (Card card : activeEntities.get(currentPlayerMove)) {
            if (card.getRunProgress() < card.getRunRequirements()) {
                for (Integer requirement : card.getRunComponents()) {
                    if (c.getColor() == requirement) {
                        card.recieveComponents(requirement, 1);
                        collectedByCard = true;
                        progress.put(c, card);
                        break;
                    }
                }
            }
            if (collectedByCard == true) {
                break;
            }
        }
        if (collectedByCard == false) {
            computers.get(currentPlayerMove).recieveProgress(1);
        }
    }
}
Also used : Component(com.janfic.games.computercombat.model.Component) Card(com.janfic.games.computercombat.model.Card)

Aggregations

Component (com.janfic.games.computercombat.model.Component)20 ArrayList (java.util.ArrayList)14 List (java.util.List)8 Card (com.janfic.games.computercombat.model.Card)7 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)7 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)5 HashMap (java.util.HashMap)4 Action (com.badlogic.gdx.scenes.scene2d.Action)3 ComponentActor (com.janfic.games.computercombat.actors.ComponentActor)3 MatchState (com.janfic.games.computercombat.model.match.MatchState)3 Move (com.janfic.games.computercombat.model.moves.Move)3 Deck (com.janfic.games.computercombat.model.Deck)2 Player (com.janfic.games.computercombat.model.Player)2 CascadeAnimation (com.janfic.games.computercombat.model.animations.CascadeAnimation)2 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)2 SpawnAnimation (com.janfic.games.computercombat.model.animations.SpawnAnimation)2 SwitchAnimation (com.janfic.games.computercombat.model.animations.SwitchAnimation)2 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)2 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 Vector2 (com.badlogic.gdx.math.Vector2)1