use of com.almasb.fxgl.entity.control.ExpireCleanControl in project FXGL by AlmasB.
the class MarioApp method initInput.
@Override
protected void initInput() {
DSLKt.onKeyDown(KeyCode.K, "G+", () -> {
getPhysicsWorld().setGravity(0, -getPhysicsWorld().getJBox2DWorld().getGravity().y * 50 + 10);
System.out.println(-getPhysicsWorld().getJBox2DWorld().getGravity().y * 50);
});
DSLKt.onKeyDown(KeyCode.I, "G-", () -> {
getPhysicsWorld().setGravity(0, -getPhysicsWorld().getJBox2DWorld().getGravity().y * 50 - 10);
System.out.println(-getPhysicsWorld().getJBox2DWorld().getGravity().y * 50);
});
getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
playerControl.left();
}
@Override
protected void onActionEnd() {
playerControl.stop();
}
}, KeyCode.A);
getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
playerControl.right();
}
@Override
protected void onActionEnd() {
playerControl.stop();
}
}, KeyCode.D);
getInput().addAction(new UserAction("Jump") {
@Override
protected void onActionBegin() {
playerControl.jump();
}
}, KeyCode.W);
getInput().addAction(new UserAction("Enter") {
@Override
protected void onActionBegin() {
stepLoop();
}
}, KeyCode.L);
getInput().addAction(new UserAction("Drop rectangle") {
@Override
protected void onActionBegin() {
Entities.builder().type(MarioType.OBSTACLE).at(getInput().getMousePositionWorld()).viewFromNodeWithBBox(new Rectangle(40, 40)).with(new CollidableComponent(true)).with(new ExpireCleanControl(Duration.seconds(2)).animateOpacity()).buildAndAttach();
}
}, MouseButton.PRIMARY);
}
use of com.almasb.fxgl.entity.control.ExpireCleanControl 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.control.ExpireCleanControl 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);
}
}
}
}
Aggregations