Search in sources :

Example 31 with UserAction

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

the class JointSample 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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Entity(com.almasb.fxgl.entity.Entity) Circle(javafx.scene.shape.Circle) Input(com.almasb.fxgl.input.Input) HitBox(com.almasb.fxgl.physics.HitBox) Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle)

Example 32 with UserAction

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

the class ScrollingBackgroundSample method initInput.

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

        @Override
        protected void onAction() {
            player.translateX(10);
        }
    }, KeyCode.D);
    getInput().addAction(new UserAction("Move Left") {

        @Override
        protected void onAction() {
            if (player.getX() >= 10)
                player.translateX(-10);
        }
    }, KeyCode.A);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 33 with UserAction

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

the class ViewportSample method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("Move Viewport Up") {

        @Override
        protected void onAction() {
            getGameScene().getViewport().setY(getGameScene().getViewport().getY() - 5);
        }
    }, KeyCode.W);
    getInput().addAction(new UserAction("Move Viewport Down") {

        @Override
        protected void onAction() {
            getGameScene().getViewport().setY(getGameScene().getViewport().getY() + 5);
        }
    }, KeyCode.S);
    getInput().addAction(new UserAction("Print Coords") {

        @Override
        protected void onActionBegin() {
            // System.out.println(getInput().getMousePositionWorld());
            // cinematicViewport();
            cinematicViewportBezier();
        }
    }, MouseButton.PRIMARY);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 34 with UserAction

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

the class ViewportZoomSample method initInput.

@Override
protected void initInput() {
    Input input = getInput();
    input.addAction(new UserAction("Move Left") {

        @Override
        protected void onAction() {
            e1.translateX(-5);
        }
    }, KeyCode.A);
    input.addAction(new UserAction("Move Right") {

        @Override
        protected void onAction() {
            e1.translateX(5);
        }
    }, KeyCode.D);
    input.addAction(new UserAction("Move Up") {

        @Override
        protected void onAction() {
            e1.translateY(-5);
        }
    }, KeyCode.W);
    input.addAction(new UserAction("Move Down") {

        @Override
        protected void onAction() {
            e1.translateY(5);
        }
    }, KeyCode.S);
    input.addAction(new UserAction("Move Left2") {

        @Override
        protected void onAction() {
            e2.translateX(-5);
        }
    }, KeyCode.LEFT);
    input.addAction(new UserAction("Move Right2") {

        @Override
        protected void onAction() {
            e2.translateX(5);
        }
    }, KeyCode.RIGHT);
    input.addAction(new UserAction("Move Up2") {

        @Override
        protected void onAction() {
            e2.translateY(-5);
        }
    }, KeyCode.UP);
    input.addAction(new UserAction("Move Down2") {

        @Override
        protected void onAction() {
            e2.translateY(5);
        }
    }, KeyCode.DOWN);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Input(com.almasb.fxgl.input.Input)

Example 35 with UserAction

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

the class AchievementsSample method initInput.

@Override
protected void initInput() {
    Input input = getInput();
    input.addAction(new UserAction("Move Left") {

        @Override
        protected void onAction() {
            playerControl.left();
            getGameState().increment("moved", (int) (300 * tpf()));
        }
    }, KeyCode.A);
    input.addAction(new UserAction("Move Right") {

        @Override
        protected void onAction() {
            playerControl.right();
            getGameState().increment("moved", (int) (300 * tpf()));
        }
    }, KeyCode.D);
    input.addAction(new UserAction("Move Up") {

        @Override
        protected void onAction() {
            playerControl.up();
            getGameState().increment("moved", (int) (300 * tpf()));
        }
    }, KeyCode.W);
    input.addAction(new UserAction("Move Down") {

        @Override
        protected void onAction() {
            playerControl.down();
            getGameState().increment("moved", (int) (300 * tpf()));
        }
    }, 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