Search in sources :

Example 31 with Card

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

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

the class SoftwareActor method buildActor.

public void buildActor(boolean flipped, Card software, ComputerCombatGame game) {
    System.out.println("BUILDING ACTOR");
    this.software = software;
    this.areas = new ArrayList<>();
    this.isSelecting = false;
    this.selected = false;
    this.clear();
    this.defaults().height(48).space(1);
    ProgressBarStyle red = new ProgressBarStyle(getSkin().get("default-vertical", ProgressBarStyle.class));
    red.knobBefore = getSkin().newDrawable("progress_bar_before_vertical", Color.valueOf("df3e23"));
    ProgressBarStyle green = new ProgressBarStyle(getSkin().get("default-vertical", ProgressBarStyle.class));
    green.knobBefore = getSkin().newDrawable("progress_bar_before_vertical", Color.valueOf("9cdb43"));
    ProgressBarStyle grey = new ProgressBarStyle(getSkin().get("default-vertical", ProgressBarStyle.class));
    grey.knobBefore = getSkin().newDrawable("progress_bar_before_vertical", Color.valueOf("dae0ea"));
    ProgressBarStyle blue = new ProgressBarStyle(getSkin().get("default-vertical", ProgressBarStyle.class));
    blue.knobBefore = getSkin().newDrawable("progress_bar_before_vertical", Color.valueOf("249fde"));
    progressBar = new ProgressBar(0, software.getRunRequirements(), 1, true, blue);
    healthBar = new ProgressBar(0, software.getMaxHealth(), 1, true, green);
    defenseBar = new ProgressBar(0, software.getMaxArmor(), 1, true, grey);
    attackBar = new ProgressBar(0, software.getMaxAttack(), 1, true, red);
    imageArea = new BorderedArea(getSkin());
    cardRegion = game.getAssetManager().get("texture_packs/" + software.getCollection().getTextureName() + ".atlas", TextureAtlas.class).findRegion(software.getTextureName());
    abilityRegion = game.getAssetManager().get("texture_packs/" + software.getCollection().getTextureName() + ".atlas", TextureAtlas.class).findRegion(software.getAbility().getTextureName());
    displayImage = new Image(cardRegion);
    imageArea.add(displayImage);
    this.setTouchable(Touchable.enabled);
    this.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (isSelecting == true) {
                selected = true;
                return;
            }
            ;
            CardInfoWindow w = new CardInfoWindow(game, software, getSkin(), SoftwareActor.this.getSoftware().getRunProgress() >= SoftwareActor.this.getSoftware().getRunRequirements());
            SoftwareActor.this.getStage().addActor(w);
            w.getUseAbilityButton().addListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    SoftwareActor.this.activatedAbility = true;
                }
            });
        }
    });
    progressBar.setValue(software.getRunProgress());
    healthBar.setValue(software.getHealth());
    defenseBar.setValue(software.getArmor());
    attackBar.setValue(software.getAttack());
    Stack progressStack = new Stack();
    progressStack.add(progressBar);
    Table progressOverlay = new Table();
    OverlayTextLabelArea<Card> progressLabelArea = new OverlayTextLabelArea<Card>(getSkin(), software) {

        @Override
        public String updateLabel(Card dataObject) {
            progressBar.setValue(dataObject.getRunProgress());
            return "" + dataObject.getRunProgress();
        }
    };
    this.areas.add(progressLabelArea);
    progressOverlay.add(progressLabelArea).expand().fillX().height(9);
    progressStack.add(progressOverlay);
    Stack healthStack = new Stack();
    healthStack.add(healthBar);
    Table healthOverlay = new Table();
    OverlayTextLabelArea<Card> healthLabelArea = new OverlayTextLabelArea<Card>(getSkin(), software) {

        @Override
        public String updateLabel(Card dataObject) {
            healthBar.setValue(dataObject.getHealth());
            return "" + dataObject.getHealth();
        }
    };
    this.areas.add(healthLabelArea);
    healthOverlay.add(healthLabelArea).expand().fillX().height(9);
    healthStack.add(healthOverlay);
    Stack defenseStack = new Stack();
    defenseStack.add(defenseBar);
    Table defenseOverlay = new Table();
    OverlayTextLabelArea<Card> defenseLabelArea = new OverlayTextLabelArea<Card>(getSkin(), software) {

        @Override
        public String updateLabel(Card dataObject) {
            defenseBar.setValue(dataObject.getArmor());
            return "" + dataObject.getArmor();
        }
    };
    this.areas.add(defenseLabelArea);
    defenseOverlay.add(defenseLabelArea).expand().fillX().height(9);
    defenseStack.add(defenseOverlay);
    Stack attackStack = new Stack();
    attackStack.add(attackBar);
    Table attackOverlay = new Table();
    OverlayTextLabelArea<Card> attackLabelArea = new OverlayTextLabelArea<Card>(getSkin(), software) {

        @Override
        public String updateLabel(Card dataObject) {
            attackBar.setValue(dataObject.getAttack());
            return "" + dataObject.getAttack();
        }
    };
    this.areas.add(attackLabelArea);
    attackOverlay.add(attackLabelArea).expand().fillX().height(9);
    attackStack.add(attackOverlay);
    leds = new VerticalGroup();
    for (Integer runComponent : software.getRunComponents()) {
        leds.addActor(new LEDActor(getSkin(), components.get(runComponent)));
    }
    leds.space(3).center();
    if (flipped) {
        this.add(leds).padRight(2);
        this.add(progressStack).width(9).prefSize(8, 8);
        this.add(attackStack).width(9);
        this.add(imageArea).width(48);
        this.add(defenseStack).width(9);
        this.add(healthStack).width(9);
    } else {
        this.add(healthStack).width(9);
        this.add(defenseStack).width(9);
        this.add(imageArea).width(48);
        this.add(attackStack).width(9);
        this.add(progressStack).width(9).prefSize(8, 8);
        this.add(leds).padLeft(2);
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) VerticalGroup(com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup) Stack(com.badlogic.gdx.scenes.scene2d.ui.Stack) Card(com.janfic.games.computercombat.model.Card) ProgressBarStyle(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 33 with Card

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

the class DrawAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> r = new ArrayList<>();
    UseAbilityMove abilityMove = (UseAbilityMove) move;
    List<Card> cards = state.activeEntities.get(move.getPlayerUID());
    Deck deck = state.decks.get(move.getPlayerUID());
    List<Card> drawnCards = new ArrayList<>();
    if (cards.size() < 4) {
        if (this.cards == null) {
            if (deck.size() > 0) {
                Card s = deck.draw();
                s.setOwnerUID(move.getPlayerUID());
                cards.add(s);
                drawnCards.add(s);
            }
        } else {
            for (StateAnalyzer<Integer> card : this.cards) {
                Card s = SQLAPI.getSingleton().getCardById(card.analyze(state, move), move.getPlayerUID());
                s.setOwnerUID(move.getPlayerUID());
                s.generateMatchID();
                cards.add(s);
                drawnCards.add(s);
            }
        }
    }
    List<MoveAnimation> animations = new ArrayList<>();
    if (abilityMove.getCard().getID() == 0) {
        state.computers.get(move.getPlayerUID()).setProgress(0);
    } else {
        for (Card card : state.activeEntities.get(move.getPlayerUID())) {
            if (card.equals(abilityMove.getCard())) {
                card.setProgress(0);
            }
        }
    }
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    ConsumeProgressAnimation drainAnimation = new ConsumeProgressAnimation(move.getPlayerUID(), drained);
    DrawAnimation drawAnimation = new DrawAnimation(move.getPlayerUID(), drawnCards);
    for (Player player : state.players) {
        if (player.getUID().equals(move.getPlayerUID())) {
            state.currentPlayerMove = state.getOtherProfile(player.getUID());
        }
    }
    animations.add(drainAnimation);
    animations.add(drawAnimation);
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    r.add(result);
    return r;
}
Also used : Player(com.janfic.games.computercombat.model.Player) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) Deck(com.janfic.games.computercombat.model.Deck) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card) DrawAnimation(com.janfic.games.computercombat.model.animations.DrawAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 34 with Card

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

the class SwitchComponentsAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove useAbility = (UseAbilityMove) move;
    Component[][] newBoard = state.componentBoard;
    Component a = useAbility.getSelectedComponents().get(0);
    Component b = useAbility.getSelectedComponents().get(1);
    Component bb = newBoard[b.getX()][b.getY()];
    Component ba = newBoard[a.getX()][a.getY()];
    bb.invalidate();
    ba.invalidate();
    ba.invalidateNeighbors();
    bb.invalidateNeighbors();
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    List<MoveAnimation> anims = new ArrayList<>();
    anims.add(new ConsumeProgressAnimation(move.getPlayerUID(), drained));
    anims.add(new SwitchAnimation(bb, ba));
    MoveResult r = new MoveResult(move, MatchState.record(state), anims);
    List<MoveResult> collectCheckResults = state.results(move);
    results.add(r);
    results.addAll(collectCheckResults);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) SwitchAnimation(com.janfic.games.computercombat.model.animations.SwitchAnimation) Card(com.janfic.games.computercombat.model.Card)

Example 35 with Card

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

Card (com.janfic.games.computercombat.model.Card)42 ArrayList (java.util.ArrayList)28 List (java.util.List)12 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)11 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)10 Action (com.badlogic.gdx.scenes.scene2d.Action)9 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)8 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)7 Component (com.janfic.games.computercombat.model.Component)6 ResultSet (java.sql.ResultSet)6 Statement (java.sql.Statement)6 HashMap (java.util.HashMap)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)5 Deck (com.janfic.games.computercombat.model.Deck)5 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)5 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 CollectionCard (com.janfic.games.computercombat.actors.CollectionCard)4 Collection (com.janfic.games.computercombat.model.Collection)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)3