Example usage for com.badlogic.gdx.controllers.mappings Ouya STICK_DEADZONE

List of usage examples for com.badlogic.gdx.controllers.mappings Ouya STICK_DEADZONE

Introduction

In this page you can find the example usage for com.badlogic.gdx.controllers.mappings Ouya STICK_DEADZONE.

Prototype

float STICK_DEADZONE

To view the source code for com.badlogic.gdx.controllers.mappings Ouya STICK_DEADZONE.

Click Source Link

Usage

From source file:ve.ucv.ciens.ccg.nxtar.states.InGameState.java

License:Apache License

@Override
public boolean axisMoved(Controller controller, int axisCode, float value) {
    GamepadUserInput userInput = null;/*from ww  w.j a va  2 s .  c om*/

    if (Math.abs(value) > Ouya.STICK_DEADZONE) {
        userInput = new GamepadUserInput();
        if (axisCode == Ouya.AXIS_LEFT_X) {
            userInput.axisLeftX = value;
        } else if (axisCode == Ouya.AXIS_LEFT_Y) {
            userInput.axisLeftY = value;
        } else if (axisCode == Ouya.AXIS_RIGHT_X) {
            userInput.axisRightX = value;
        } else if (axisCode == Ouya.AXIS_RIGHT_Y) {
            userInput.axisRightY = value;
        }

    } else if (Math.abs(value) <= Ouya.STICK_DEADZONE && Math.abs(value) > 0.15f) {
        userInput = new GamepadUserInput();
        if (axisCode == Ouya.AXIS_LEFT_X) {
            userInput.axisLeftX = 0.0f;
        } else if (axisCode == Ouya.AXIS_LEFT_Y) {
            userInput.axisLeftY = 0.0f;
        } else if (axisCode == Ouya.AXIS_RIGHT_X) {
            userInput.axisRightX = 0.0f;
        } else if (axisCode == Ouya.AXIS_RIGHT_Y) {
            userInput.axisRightY = 0.0f;
        }
    }

    if (userInput != null) {
        robotArmPositioningSystem.setUserInput(userInput);
        robotArmPositioningSystem.process();
        return true;
    }

    return false;
}

From source file:ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem.java

License:Apache License

@Override
protected void process(Entity e) throws ClassCastException {
    Vector3 endPoint;//from   w ww.ja  v a 2 s .  com
    GamepadUserInput tempGP;
    KeyboardUserInput tempKey;
    GeometryComponent geometry = geometryMapper.get(e);
    AutomaticMovementComponent auto = autoMapper.get(e);
    CollisionDetectionComponent collision = collisionMapper.get(e);

    if (input == null) {
        if (auto.moving)
            autoMove(geometry, auto, collision);
        else
            return;

    } else {
        if (input instanceof TouchUserInput) {
            if (!auto.moving) {
                endPoint = ((TouchUserInput) input).userTouchEndPoint;
                endPoint.set(geometry.position.x, geometry.position.y, MAX_Z);
                auto.startPoint.set(geometry.position);
                auto.endPoint.set(endPoint);
                auto.moving = true;
                auto.forward = true;

                Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from "
                        + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
            } else
                autoMove(geometry, auto, collision);
            input = null;
        } else if (input instanceof GamepadUserInput) {
            tempGP = (GamepadUserInput) input;

            if (!auto.moving) {
                if (!tempGP.oButton) {
                    geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
                    geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
                    if (Math.abs(tempGP.axisLeftX) < Ouya.STICK_DEADZONE
                            && Math.abs(tempGP.axisLeftY) < Ouya.STICK_DEADZONE)
                        input = null;
                    else
                        input = (UserInput) tempGP;
                } else {
                    endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
                    auto.startPoint.set(geometry.position);
                    auto.endPoint.set(endPoint);
                    auto.moving = true;
                    auto.forward = true;
                    input = null;
                }
            } else {
                autoMove(geometry, auto, collision);
                input = null;
            }

        } else if (input instanceof KeyboardUserInput) {
            tempKey = (KeyboardUserInput) input;

            if (!auto.moving) {
                if (!tempKey.keySpace) {
                    geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f;
                    geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
                    geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
                    geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
                    if (!tempKey.keyUp && !tempKey.keyUp && !tempKey.keyUp && !tempKey.keyUp)
                        input = null;
                    else
                        input = (UserInput) tempKey;
                } else {
                    endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
                    auto.startPoint.set(geometry.position);
                    auto.endPoint.set(endPoint);
                    auto.moving = true;
                    auto.forward = true;
                    input = null;
                }
            } else {
                autoMove(geometry, auto, collision);
                input = null;
            }
        } else
            throw new ClassCastException("Input is not a valid UserInput instance.");
    }

}