Search in sources :

Example 21 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class RobotPlatformerSample method initInput.

@Override
protected void initInput() {
    onKey(KeyCode.W, () -> getControl().jump());
    onKey(KeyCode.F, () -> getControl().roll());
    onKey(KeyCode.X, () -> getControl().die());
    getInput().addAction(new UserAction("Left") {

        @Override
        protected void onAction() {
            getControl().walkLeft();
        }

        @Override
        protected void onActionEnd() {
            getControl().stop();
        }
    }, KeyCode.A);
    getInput().addAction(new UserAction("Right") {

        @Override
        protected void onAction() {
            getControl().walkRight();
        }

        @Override
        protected void onActionEnd() {
            getControl().stop();
        }
    }, KeyCode.D);
    getInput().addAction(new UserAction("Run Left") {

        @Override
        protected void onAction() {
            getControl().runLeft();
        }

        @Override
        protected void onActionEnd() {
            getControl().stop();
        }
    }, KeyCode.Q);
    getInput().addAction(new UserAction("Run Right") {

        @Override
        protected void onAction() {
            getControl().runRight();
        }

        @Override
        protected void onActionEnd() {
            getControl().stop();
        }
    }, KeyCode.E);
    getInput().addAction(new UserAction("Crouch Left") {

        @Override
        protected void onAction() {
            getControl().crouchLeft();
        }

        @Override
        protected void onActionEnd() {
            getControl().stop();
        }
    }, KeyCode.Z);
    getInput().addAction(new UserAction("Crouch Right") {

        @Override
        protected void onAction() {
            getControl().crouchRight();
        }

        @Override
        protected void onActionEnd() {
            getControl().stop();
        }
    }, KeyCode.C);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 22 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class InputSequenceSample method initInput.

@Override
protected void initInput() {
    Input input = FXGL.getInput();
    var sequence = new InputSequence(KeyCode.Q, KeyCode.W, KeyCode.E, KeyCode.R);
    // the action fires only when the sequence above (Q, W, E, R) is complete
    // useful for input combos
    input.addAction(new UserAction("Print Line") {

        @Override
        protected void onActionBegin() {
            System.out.println("Action Begin");
        }

        @Override
        protected void onAction() {
            System.out.println("On Action");
        }

        @Override
        protected void onActionEnd() {
            System.out.println("Action End");
        }
    }, sequence);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Input(com.almasb.fxgl.input.Input) InputSequence(com.almasb.fxgl.input.InputSequence)

Example 23 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class VirtualControllerSample method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("test") {

        @Override
        protected void onActionBegin() {
            System.out.println("start f");
        }

        @Override
        protected void onAction() {
            System.out.println("f");
        }

        @Override
        protected void onActionEnd() {
            System.out.println("end f");
        }
    }, KeyCode.F, VirtualButton.X);
    getInput().addAction(new UserAction("test2") {

        @Override
        protected void onActionBegin() {
            System.out.println("start g");
        }

        @Override
        protected void onAction() {
            System.out.println("g");
        }

        @Override
        protected void onActionEnd() {
            System.out.println("end g");
        }
    }, KeyCode.G, VirtualButton.Y);
    getInput().addAction(new UserAction("test3") {

        @Override
        protected void onActionBegin() {
            System.out.println("start h");
        }

        @Override
        protected void onAction() {
            System.out.println("h");
        }

        @Override
        protected void onActionEnd() {
            System.out.println("end h");
        }
    }, KeyCode.H, VirtualButton.A);
    getInput().addAction(new UserAction("test4") {

        @Override
        protected void onActionBegin() {
            System.out.println("start j");
        }

        @Override
        protected void onAction() {
            System.out.println("j");
        }

        @Override
        protected void onActionEnd() {
            System.out.println("end j");
        }
    }, KeyCode.J, VirtualButton.B);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 24 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class SaveSample 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") {

        @Override
        protected void onAction() {
            player.rotateBy(1);
        }
    }, KeyCode.F);
    input.addAction(new UserAction("Switch Types") {

        @Override
        protected void onAction() {
            if (player.getTypeComponent().isType(Type.PLAYER)) {
                player.getTypeComponent().setValue(Type.ENEMY);
                enemy.getTypeComponent().setValue(Type.PLAYER);
            } else {
                player.getTypeComponent().setValue(Type.PLAYER);
                enemy.getTypeComponent().setValue(Type.ENEMY);
            }
        }
    }, KeyCode.G);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Input(com.almasb.fxgl.input.Input)

Example 25 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class InventorySample method initInput.

@Override
protected void initInput() {
    inventorySubScene = new InventorySubScene();
    inventorySubScene.getInput().addAction(new UserAction("Close Inventory") {

        @Override
        protected void onActionBegin() {
            getSceneService().popSubScene();
        }
    }, KeyCode.F);
    onKeyDown(KeyCode.F, "Open Inventory", () -> getSceneService().pushSubScene(inventorySubScene));
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

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