use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class UnoSample method onUpdate.
@Override
protected void onUpdate(double tpf) {
if (playerHandChanged) {
double sizePerCard = 1.0 * getWidth() / player.cardsProperty().size();
int i = 0;
for (Entity card : player.cardsProperty()) {
card.setX(i++ * sizePerCard);
card.setY(450);
}
playerHandChanged = false;
}
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class UnoSample method spawn.
private Entity spawn(Card card, int x, int y) {
Entity cardEntity = (Entity) getGameWorld().spawn("Card", new SpawnData(x, y).put("card", card));
cardEntity.getView().setOnMouseClicked(e -> {
if (card.canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
Animation<?> animation = Entities.animationBuilder().duration(Duration.seconds(0.35)).translate(cardEntity).from(cardEntity.getPosition()).to(new Point2D(350, 225)).build();
animation.setOnFinished(() -> {
player.removeCard(cardEntity);
playerHandChanged = true;
currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
currentCard = cardEntity;
currentCard.setRenderLayer(RenderLayer.BACKGROUND);
// apply special effect
switch(card.getRank()) {
case SP_PLUS2:
break;
case SP_PLUS4:
break;
case SP_SKIP:
break;
default:
}
aiMove();
});
animation.startInPlayState();
}
});
return cardEntity;
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class UnoSample method aiMove.
private void aiMove() {
Entity chosenCard = null;
for (Entity card : enemy.cardsProperty()) {
// can we avoid calls like this?
if (card.getComponent(CardComponent.class).getValue().canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
enemy.removeCard(card);
card.setPosition(new Point2D(350, 225));
currentCard = card;
currentCard.setRenderLayer(RenderLayer.BACKGROUND);
// apply special effect
chosenCard = card;
break;
}
}
if (chosenCard == null) {
while (deck.hasCards()) {
Entity draw = spawn(deck.drawCard(), 0, -150);
if (draw.getComponent(CardComponent.class).getValue().canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
draw.setPosition(new Point2D(350, 225));
currentCard = draw;
currentCard.setRenderLayer(RenderLayer.BACKGROUND);
break;
} else {
enemy.addCard(draw);
}
}
}
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class InterpolatorSample2 method initGame.
@Override
protected void initGame() {
int i = 0;
for (var interpolator : Interpolators.values()) {
Text t = getUIFactoryService().newText(interpolator.toString() + ":");
t.setFill(Color.BLACK);
Pane p = new Pane(t);
p.setTranslateY(i * 50 + 25);
Line line = new Line(0, i * 50, getAppWidth(), i * 50);
line.setStroke(Color.RED);
getGameScene().addUINodes(p, line);
Entity bird = entityBuilder().at(70, i * 50).view(texture("bird.png").toAnimatedTexture(2, Duration.seconds(0.5)).loop()).buildAndAttach();
animationBuilder().interpolator(interpolator.EASE_OUT()).duration(Duration.seconds(2)).repeatInfinitely().translate(bird).from(new Point2D(120, i * 50)).to(new Point2D(getAppWidth() - 70, i * 50)).buildAndPlay();
i++;
}
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class GraphVisSample method makeNode.
private Entity makeNode(int id) {
var e = entityBuilder().at(FXGLMath.randomPoint(new Rectangle2D(0, 0, getAppWidth(), getAppHeight()))).view(new Circle(NODE_RADIUS, NODE_RADIUS, NODE_RADIUS)).with("id", id).with(new DraggableComponent()).onClick(entity -> {
// here you can find out more info about the node in question
}).buildAndAttach();
nodes.put(id, e);
return e;
}
Aggregations