Search in sources :

Example 1 with UserAction

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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 2 with UserAction

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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 3 with UserAction

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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 4 with UserAction

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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) ExpireCleanControl(com.almasb.fxgl.entity.control.ExpireCleanControl)

Example 5 with UserAction

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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Input(com.almasb.fxgl.input.Input)

Aggregations

UserAction (com.almasb.fxgl.input.UserAction)48 Input (com.almasb.fxgl.input.Input)23 Entity (com.almasb.fxgl.entity.Entity)6 Point2D (javafx.geometry.Point2D)6 HitBox (com.almasb.fxgl.physics.HitBox)5 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)3 Rectangle (javafx.scene.shape.Rectangle)3 GameApplication (com.almasb.fxgl.app.GameApplication)2 Action (com.almasb.fxgl.entity.action.Action)2 GameSettings (com.almasb.fxgl.settings.GameSettings)2 Circle (javafx.scene.shape.Circle)2 VoronoiSubdivision (com.almasb.fxgl.algorithm.VoronoiSubdivision)1 DSLKt (com.almasb.fxgl.app.DSLKt)1 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)1 SlowTimeEffect (com.almasb.fxgl.dsl.effects.SlowTimeEffect)1 ParticleControl (com.almasb.fxgl.effect.ParticleControl)1 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)1 Entities (com.almasb.fxgl.entity.Entities)1 ContinuousAction (com.almasb.fxgl.entity.action.ContinuousAction)1 InstantAction (com.almasb.fxgl.entity.action.InstantAction)1