use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class KeepComponentTypeHeuristicAnalyzer method analyze.
@Override
public float analyze(List<MoveResult> results) {
float r = 0;
MoveResult end = results.get(results.size() - 1);
ComponentFilter filter = new ComponentFilter() {
@Override
public boolean filter(Component component, MatchState state, Move move) {
return component.getColor() == color;
}
};
int amount = end.getState().countComponents(filter, end.getMove());
r = Math.min(amount / 25f, 1);
return r;
}
use of com.janfic.games.computercombat.model.Component 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;
}
use of com.janfic.games.computercombat.model.Component 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;
}
use of com.janfic.games.computercombat.model.Component 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.Component in project computercombat by janfic.
the class CollectAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
List<MoveAnimation> anim = new ArrayList<>();
anim.add(Ability.consumeCardProgress(state, move));
results.add(new MoveResult(move, MatchState.record(state), anim));
UseAbilityMove useAbility = (UseAbilityMove) move;
int index = state.activeEntities.get(useAbility.getPlayerUID()).indexOf(useAbility.getCard());
state.activeEntities.get(useAbility.getPlayerUID()).get(index).setProgress(0);
Stream<Component> components = state.getComponentsAsList().stream();
for (CollectFilter filter : filters) {
components = components.filter((c) -> {
return filter.filter(state, move, c);
});
}
List<Component> list = components.collect(Collectors.toList());
Collections.shuffle(list);
int count = amount.analyze(state, move);
list = list.subList(0, Math.min(count, list.size()));
Component[] c = list.toArray(new Component[0]);
for (Component component : c) {
component.getMatchNeighbors().add(-1);
}
List<MoveResult> result = state.results(move);
results.addAll(result);
return results;
}
Aggregations