Search in sources :

Example 1 with PlayerInputController

use of com.ilargia.games.states.game.component.input.PlayerInputController in project Entitas-Java by Rubentxu.

the class GuiFactory method createPadButtons.

public Table createPadButtons(float width, float height, InputEntity player) {
    Table tableControlPad = new Table();
    PlayerInputController stateController = player.getPlayerInputController();
    tableControlPad.row().height(height);
    ImageButton btnLeft = new ImageButton(skin, "buttonLeft");
    tableControlPad.add(btnLeft).width(width).expandY().fill();
    btnLeft.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchDown(event, x, y, pointer, button);
            //                controller.leftPressed();
            //                controller.rightReleased();
            player.replacePlayerInputController(true, false, stateController.jumpPressed);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchUp(event, x, y, pointer, button);
            //                controller.leftReleased();
            player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            System.out.println("Event- " + event.getType());
            super.touchDragged(event, x, y, pointer);
            if (isOver(event.getListenerActor(), x, y)) {
                //                    controller.rightReleased();
                //                    controller.leftPressed();
                player.replacePlayerInputController(true, false, stateController.jumpPressed);
            } else {
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
            }
        }
    });
    ImageButton btnRight = new ImageButton(skin, "buttonRight");
    tableControlPad.add(btnRight).width(width).expandY().fill().padRight((width) * 2);
    btnRight.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchDown(event, x, y, pointer, button);
            //                controller.leftReleased();
            //                controller.rightPressed();
            player.replacePlayerInputController(false, true, stateController.jumpPressed);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchUp(event, x, y, pointer, button);
            //                controller.rightReleased();
            player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            System.out.println("Event- " + event.getType());
            super.touchDragged(event, x, y, pointer);
            if (isOver(event.getListenerActor(), x, y)) {
                //                    controller.rightPressed();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, true, stateController.jumpPressed);
            } else {
                //                    controller.rightReleased();
                player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
            }
        }
    });
    ImageButton btnUP = new ImageButton(skin, "buttonUp");
    tableControlPad.add(btnUP).width(width).expandY().fill();
    btnUP.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchDown(event, x, y, pointer, button);
            //                controller.jumpPressed();
            player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchUp(event, x, y, pointer, button);
            //                controller.jumpReleased();
            player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            System.out.println("Event- " + event.getType());
            super.touchDragged(event, x, y, pointer);
            if (isOver(event.getListenerActor(), x, y)) {
                //                    controller.jumpPressed();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            } else {
                //                    controller.jumpReleased();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
            }
        }
    });
    tableControlPad.setBounds(0, 0, Gdx.graphics.getWidth(), height + 10);
    return tableControlPad;
}
Also used : PlayerInputController(com.ilargia.games.states.game.component.input.PlayerInputController) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 2 with PlayerInputController

use of com.ilargia.games.states.game.component.input.PlayerInputController in project Entitas-Java by Rubentxu.

the class GuiFactory method createTouchPad.

public Touchpad createTouchPad(float width, float height, InputEntity player) {
    Touchpad touchpad = new Touchpad(10 * ScaleUtil.getSizeRatio(), skin);
    touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
    touchpad.setWidth(width);
    touchpad.setHeight(height);
    PlayerInputController stateController = player.getPlayerInputController();
    touchpad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("PercentX " + ((Touchpad) actor).getKnobPercentX() + "PercentY " + ((Touchpad) actor).getKnobPercentY());
            if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5 && ((Touchpad) actor).getKnobPercentX() > -0.5) {
                //                    controller.rightReleased();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() > 0.5) {
                //                    controller.rightPressed();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, true, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() < -0.5) {
                //                    controller.leftPressed();
                //                    controller.rightReleased();
                player.replacePlayerInputController(true, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentY() > 0.5) {
                //                    controller.jumpPressed();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            } else {
                //                    controller.jumpReleased();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
            }
        }
    });
    return touchpad;
}
Also used : PlayerInputController(com.ilargia.games.states.game.component.input.PlayerInputController) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

PlayerInputController (com.ilargia.games.states.game.component.input.PlayerInputController)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1