use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class ScifiSample method initInput.
// @Override
// protected void initAchievements() {
// getGameplay().getAchievementManager().registerAchievement(new Achievement("Collector", "Collect 10 coins"));
// }
@Override
protected void initInput() {
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("Animate Level Text") {
@Override
protected void onActionBegin() {
levelText.animateIn();
}
@Override
protected void onActionEnd() {
levelText.animateOut();
}
}, KeyCode.G);
getInput().addAction(new UserAction("Open/Close Panel") {
@Override
protected void onActionBegin() {
if (panel.isOpen())
panel.close();
else
panel.open();
}
}, KeyCode.TAB);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class TimerActionSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Pause") {
@Override
protected void onActionBegin() {
if (timerAction.isPaused())
timerAction.resume();
else
timerAction.pause();
}
}, KeyCode.F);
getInput().addAction(new UserAction("Expire") {
@Override
protected void onActionBegin() {
timerAction.expire();
}
}, KeyCode.E);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class LagApp method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
getGameScene().getViewport().setX(getGameScene().getViewport().getX() - 5);
}
}, KeyCode.A);
getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
getGameScene().getViewport().setX(getGameScene().getViewport().getX() + 5);
}
}, KeyCode.D);
getInput().addAction(new UserAction("Up") {
@Override
protected void onAction() {
getGameScene().getViewport().setY(getGameScene().getViewport().getY() - 5);
}
}, KeyCode.W);
getInput().addAction(new UserAction("Down") {
@Override
protected void onAction() {
getGameScene().getViewport().setY(getGameScene().getViewport().getY() + 5);
}
}, KeyCode.S);
}
use of com.almasb.fxgl.input.UserAction 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.input.UserAction in project FXGL by AlmasB.
the class BasicGameApp2 method initInput.
@Override
protected void initInput() {
// get input service
Input input = getInput();
input.addAction(new UserAction("Move Right") {
@Override
protected void onAction() {
// move right 5 pixels
player.translateX(5);
getGameState().increment("pixelsMoved", +5);
}
}, KeyCode.D);
input.addAction(new UserAction("Move Left") {
@Override
protected void onAction() {
// move left 5 pixels
player.translateX(-5);
getGameState().increment("pixelsMoved", +5);
}
}, KeyCode.A);
input.addAction(new UserAction("Move Up") {
@Override
protected void onAction() {
// move up 5 pixels
player.translateY(-5);
getGameState().increment("pixelsMoved", +5);
}
}, KeyCode.W);
input.addAction(new UserAction("Move Down") {
@Override
protected void onAction() {
// move down 5 pixels
player.translateY(5);
getGameState().increment("pixelsMoved", +5);
}
}, KeyCode.S);
}
Aggregations