Search in sources :

Example 36 with UserAction

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

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

Example 37 with UserAction

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

the class VoronoiSample method initInput.

@Override
protected void initInput() {
    onKey(KeyCode.Q, "dec", () -> inc("hp", -0.01));
    onKey(KeyCode.E, "inc", () -> inc("hp", +0.01));
    getInput().addAction(new UserAction("Voronoi") {

        @Override
        protected void onActionBegin() {
            VoronoiSubdivision.divide(getAppBounds(), 100, 2).forEach(p -> {
                p.setStrokeWidth(1.5);
                p.strokeProperty().bind(getop("stroke"));
                p.setFill(Color.RED);
                p.opacityProperty().bind(new SimpleDoubleProperty(1).subtract(getdp("hp")).multiply(distance(p) / 500 * 3));
                getGameScene().addUINode(p);
            });
            Text text = getUIFactory().newText("", Color.BLACK, 18.0);
            text.setTranslateX(50);
            text.setTranslateY(50);
            text.textProperty().bind(getdp("hp").asString("%.2f"));
            getGameScene().addUINode(text);
        }
    }, KeyCode.F);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Text(javafx.scene.text.Text) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) DSLKt(com.almasb.fxgl.app.DSLKt) VoronoiSubdivision(com.almasb.fxgl.algorithm.VoronoiSubdivision) Map(java.util.Map) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Point2D(javafx.geometry.Point2D) Polygon(javafx.scene.shape.Polygon) GameSettings(com.almasb.fxgl.settings.GameSettings) GameApplication(com.almasb.fxgl.app.GameApplication) UserAction(com.almasb.fxgl.input.UserAction) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Text(javafx.scene.text.Text)

Example 38 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.getRotationComponent().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 39 with UserAction

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

the class WheelMenuSample method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("Open/Close WheelMenu") {

        @Override
        protected void onActionBegin() {
            if (menu.isOpen())
                menu.close();
            else
                menu.open();
            menu.setTranslateX(getInput().getMouseXWorld() - 25);
            menu.setTranslateY(getInput().getMouseYWorld() - 75);
        }
    }, MouseButton.SECONDARY);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 40 with UserAction

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

the class SelectedEntitySample method initInput.

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

        @Override
        protected void onActionBegin() {
            player.getComponent(SelectableComponent.class).setValue(false);
        }
    }, KeyCode.F);
    getInput().addAction(new UserAction("Make selectable") {

        @Override
        protected void onActionBegin() {
            player.getComponent(SelectableComponent.class).setValue(true);
        }
    }, KeyCode.G);
}
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