use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class PhysicsCollisionSample method initInput.
@Override
protected void initInput() {
Input input = FXGL.getInput();
input.addAction(new UserAction("Scale Up") {
@Override
protected void onActionBegin() {
System.out.println("Scaling Up Player.");
}
@Override
protected void onAction() {
scalePlayer(Scale.UP, 0.20);
}
@Override
protected void onActionEnd() {
}
}, KeyCode.RIGHT);
input.addAction(new UserAction("Scale Down") {
@Override
protected void onActionBegin() {
System.out.println("Scaling Down Player.");
}
@Override
protected void onAction() {
scalePlayer(Scale.DOWN, 0.20);
}
@Override
protected void onActionEnd() {
}
}, KeyCode.LEFT);
input.addAction(new UserAction("Rotate Right") {
@Override
protected void onActionBegin() {
System.out.println("Rotating Player Right.");
}
@Override
protected void onAction() {
double currentPlayerRotation = player.getRotation();
player.setRotation(currentPlayerRotation - 1.5);
}
@Override
protected void onActionEnd() {
}
}, KeyCode.Q);
input.addAction(new UserAction("Rotate Left") {
@Override
protected void onActionBegin() {
System.out.println("Rotating Player Right.");
}
@Override
protected void onAction() {
double currentPlayerRotation = player.getRotation();
player.setRotation(currentPlayerRotation + 1.5);
}
@Override
protected void onActionEnd() {
}
}, KeyCode.E);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class PlatformerSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Left") {
@Override
protected void onActionBegin() {
player.getComponent(PhysicsComponent.class).setVelocityX(-200);
}
}, KeyCode.A, VirtualButton.LEFT);
input.addAction(new UserAction("Right") {
@Override
protected void onActionBegin() {
player.getComponent(PhysicsComponent.class).setVelocityX(200);
}
}, KeyCode.D, VirtualButton.RIGHT);
input.addAction(new UserAction("Jump") {
@Override
protected void onActionBegin() {
PhysicsComponent physics = player.getComponent(PhysicsComponent.class);
if (physics.isOnGround()) {
physics.setVelocityY(-500);
}
// getDevPane().addDebugPoint(player.getCenter());
}
}, KeyCode.W, VirtualButton.A);
onKeyDown(KeyCode.I, "Info", () -> System.out.println(player.getCenter()));
input.addAction(new UserAction("Grow") {
@Override
protected void onActionBegin() {
player.setScaleX(player.getScaleX() * 1.25);
player.setScaleY(player.getScaleY() * 1.25);
// double x = player.getX();
// double y = player.getY();
//
// player.removeFromWorld();
//
// player = createPlayer(x, y, 60, 80);
}
}, KeyCode.SPACE);
input.addAction(new UserAction("Grow Poly") {
@Override
protected void onActionBegin() {
poly.setScaleX(poly.getScaleX() * 1.25);
poly.setScaleY(poly.getScaleY() * 1.25);
}
}, KeyCode.G);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class SpriteSheetAnimationApp method initInput.
@Override
protected void initInput() {
FXGL.getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
player.getComponent(AnimationComponent.class).moveRight();
}
}, KeyCode.D);
FXGL.getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
player.getComponent(AnimationComponent.class).moveLeft();
}
}, KeyCode.A);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class MultiplayerSample method initInput.
@Override
protected void initInput() {
onKey(W, () -> player1.translateY(-5));
onKey(S, () -> player1.translateY(5));
onKey(A, () -> player1.translateX(-5));
onKey(D, () -> player1.translateX(5));
onBtnDown(MouseButton.PRIMARY, () -> shoot(player1));
onKeyDown(F, () -> {
if (isServer) {
clientBus.fireEvent(new CustomReplicationEvent("Hello", random(0.0, 1000.0)));
}
});
clientInput = new Input();
onKeyBuilder(clientInput, W).onAction(() -> player2.translateY(-5));
onKeyBuilder(clientInput, S).onAction(() -> player2.translateY(5));
onKeyBuilder(clientInput, A).onAction(() -> player2.translateX(-5));
onKeyBuilder(clientInput, D).onAction(() -> player2.translateX(5));
clientInput.addAction(new UserAction("Shoot") {
@Override
protected void onActionBegin() {
shoot(player2);
}
}, MouseButton.PRIMARY);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class ParticlesSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Spawn Explosion") {
@Override
protected void onActionBegin() {
// 1. create entity
Entity explosion = new Entity();
explosion.setPosition(input.getMousePositionWorld());
// 2. create and configure emitter + control
ParticleEmitter emitter = ParticleEmitters.newExplosionEmitter(400);
ParticleControl control = new ParticleControl(emitter);
// we also want the entity to destroy itself when particle control is done
control.setOnFinished(explosion::removeFromWorld);
// 3. add control to entity
explosion.addControl(control);
// 4. add entity to game world
getGameWorld().addEntity(explosion);
}
}, MouseButton.PRIMARY);
}
Aggregations