use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class BasicGameApp3 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);
input.addAction(new UserAction("Play Sound") {
@Override
protected void onActionBegin() {
getAudioPlayer().playSound("drop.wav");
}
}, KeyCode.F);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class BasicGameApp4 method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
player.getControl(DudeControl.class).moveRight();
}
}, KeyCode.D);
getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
player.getControl(DudeControl.class).moveLeft();
}
}, KeyCode.A);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class PhysicsSample 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);
}
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).setLinearVelocity(new Point2D(-200, 0));
}
}, KeyCode.A);
input.addAction(new UserAction("Right") {
@Override
protected void onActionBegin() {
player.getComponent(PhysicsComponent.class).setLinearVelocity(new Point2D(200, 0));
}
}, KeyCode.D);
input.addAction(new UserAction("Jump") {
@Override
protected void onActionBegin() {
PhysicsComponent physics = player.getComponent(PhysicsComponent.class);
if (physics.isOnGround()) {
double dx = physics.getLinearVelocity().getX();
physics.setLinearVelocity(new Point2D(dx, -100));
}
}
}, KeyCode.W);
input.addAction(new UserAction("Grow") {
@Override
protected void onActionBegin() {
double x = player.getX();
double y = player.getY();
player.removeFromWorld();
player = createPlayer(x, y, 60, 80);
}
}, KeyCode.SPACE);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class RealPhysicsSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Spawn Box") {
@Override
protected void onActionBegin() {
Entity box = createPhysicsEntity();
// 3. set hit box (-es) to specify bounding shape
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().setView(new Rectangle(80, 40, Color.BLUE));
getGameWorld().addEntity(box);
}
}, MouseButton.PRIMARY);
input.addAction(new UserAction("Spawn Ball") {
@Override
protected void onActionBegin() {
Entity ball = createPhysicsEntity();
// 3. set hit box to specify bounding shape
ball.getBoundingBoxComponent().addHitBox(new HitBox("Test", BoundingShape.circle(20)));
ball.getViewComponent().setView(new Circle(20, Color.RED));
getGameWorld().addEntity(ball);
}
}, MouseButton.SECONDARY);
}
Aggregations