use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class PhysicsSample2 method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Move Left") {
@Override
protected void onAction() {
playerControl.left();
}
}, KeyCode.A);
input.addAction(new UserAction("Move Right") {
@Override
protected void onAction() {
playerControl.right();
}
}, KeyCode.D);
input.addAction(new UserAction("Move Up") {
@Override
protected void onAction() {
playerControl.up();
}
}, KeyCode.W);
input.addAction(new UserAction("Move Down") {
@Override
protected void onAction() {
playerControl.down();
}
}, KeyCode.S);
input.addAction(new UserAction("Rotate CCW") {
@Override
protected void onAction() {
player.rotateBy(-5);
}
}, KeyCode.Q);
input.addAction(new UserAction("Rotate CW") {
@Override
protected void onAction() {
player.rotateBy(5);
}
}, KeyCode.E);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class MarioApp method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
player.getControl(PlayerControl.class).left();
}
}, KeyCode.A);
getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
player.getControl(PlayerControl.class).right();
}
}, KeyCode.D);
getInput().addAction(new UserAction("Jump") {
@Override
protected void onAction() {
player.getControl(PlayerControl.class).jump();
}
}, KeyCode.W);
DSLKt.onKeyDown(KeyCode.F, "asd", () -> {
player.getControl(EffectControl.class).startEffect(new WobbleEffect(Duration.seconds(3), 3, 7, Orientation.VERTICAL));
});
DSLKt.onKeyDown(KeyCode.G, "asd2", () -> {
player.getControl(EffectControl.class).startEffect(new WobbleEffect(Duration.seconds(3), 2, 4, Orientation.HORIZONTAL));
});
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class BasicGameApp 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);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class BBoxSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Slow Time") {
@Override
protected void onActionBegin() {
player.getComponent(EffectComponent.class).startEffect(new SlowTimeEffect(0.2, Duration.seconds(3)));
}
}, KeyCode.F);
getInput().addAction(new UserAction("Change view 1") {
@Override
protected void onActionBegin() {
// byType(Type.NPC).get(0).getComponent(EffectComponent.class).startEffect(new FlashEffect(Color.RED, Duration.seconds(0.75)));
// player.setView(texture("bird.png").toAnimatedTexture(2, Duration.seconds(0.33)).play());
}
}, KeyCode.G);
onKey(KeyCode.Q, () -> {
scaleX += 0.1;
player.setScaleX(scaleX);
});
onKey(KeyCode.E, () -> {
scaleY += 0.1;
player.setScaleY(scaleY);
});
onKey(KeyCode.Z, () -> {
scaleX -= 0.1;
player.setScaleX(scaleX);
});
onKey(KeyCode.C, () -> {
scaleY -= 0.1;
player.setScaleY(scaleY);
});
onKey(KeyCode.R, () -> {
angle -= 5;
player.setRotation(angle);
});
onKey(KeyCode.T, () -> {
angle += 5;
player.setRotation(angle);
});
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class RopeJointSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("LMB") {
private double x;
private double y;
@Override
protected void onActionBegin() {
x = getInput().getMouseXWorld();
y = getInput().getMouseYWorld();
}
@Override
protected void onActionEnd() {
var endx = getInput().getMouseXWorld();
var endy = getInput().getMouseYWorld();
spawnBullet(x, y, endx - x, endy - y);
}
}, MouseButton.PRIMARY);
onKeyDown(KeyCode.F, () -> {
Entity box = createPhysicsEntity();
box.getBoundingBoxComponent().addHitBox(new HitBox("Left", BoundingShape.box(40, 40)));
box.getBoundingBoxComponent().addHitBox(new HitBox("Right", new Point2D(40, 0), BoundingShape.box(40, 40)));
box.getViewComponent().addChild(texture("brick.png", 40, 40).superTexture(texture("brick.png", 40, 40), HorizontalDirection.RIGHT));
box.setRotationOrigin(new Point2D(40, 20));
getGameWorld().addEntity(box);
});
onBtnDown(MouseButton.SECONDARY, () -> {
Entity ball = createPhysicsEntity();
ball.getBoundingBoxComponent().addHitBox(new HitBox("Test", BoundingShape.circle(20)));
ball.getViewComponent().addChild(texture("ball.png", 40, 40));
ball.setRotationOrigin(new Point2D(20, 20));
getGameWorld().addEntity(ball);
});
}
Aggregations