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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations