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

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

Introduction

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

Prototype

int AXIS_LEFT_X

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

Click Source Link

Usage

From source file:com.badlogic.invaders.screens.GameLoop.java

License:Apache License

@Override
public void update(float delta) {
    simulation.update(delta);// w w  w.j  a  v a2  s .c om

    float accelerometerY = Gdx.input.getAccelerometerY();
    if (accelerometerY < 0)
        simulation.moveShipLeft(delta, Math.abs(accelerometerY) / 10);
    else
        simulation.moveShipRight(delta, Math.abs(accelerometerY) / 10);

    if (invaders.getController() != null) {
        if (buttonsPressed > 0) {
            simulation.shot();
        }

        // if the left stick moved, move the ship
        float axisValue = invaders.getController().getAxis(Ouya.AXIS_LEFT_X) * 0.5f;
        if (Math.abs(axisValue) > 0.25f) {
            if (axisValue > 0) {
                simulation.moveShipRight(delta, axisValue);
            } else {
                simulation.moveShipLeft(delta, -axisValue);
            }
        }
    }

    if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT) || Gdx.input.isKeyPressed(Keys.A))
        simulation.moveShipLeft(delta, 0.5f);
    if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT) || Gdx.input.isKeyPressed(Keys.D))
        simulation.moveShipRight(delta, 0.5f);
    if (Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.SPACE))
        simulation.shot();
}

From source file:com.mygdx.game.screens.GameLoop.java

License:Apache License

@Override
public void update(float delta) {
    simulation.update(delta);/*from   ww w . j a  v a 2 s. c  o m*/

    float[] q0s = new float[simulation.MAX_SHIPS];
    float[] q1s = new float[simulation.MAX_SHIPS];
    float[] q2s = new float[simulation.MAX_SHIPS];
    float[] q3s = new float[simulation.MAX_SHIPS];

    for (int shipNumber = 0; shipNumber < simulation.MAX_SHIPS; shipNumber++) {

        q0s[shipNumber] = (float) Invaders.mInvaderInterfaceArray[shipNumber].getQ0();
        q1s[shipNumber] = (float) Invaders.mInvaderInterfaceArray[shipNumber].getQ1();
        q2s[shipNumber] = (float) Invaders.mInvaderInterfaceArray[shipNumber].getQ2();
        q3s[shipNumber] = (float) Invaders.mInvaderInterfaceArray[shipNumber].getQ3();

    }

    float accelerometerY = Gdx.input.getAccelerometerY();

    for (int shipNumber = 0; shipNumber < simulation.MAX_SHIPS; shipNumber++) {

        //This assumps that it is either left or right...
        if (0.2f * (q0s[shipNumber] * q1s[shipNumber] + q2s[shipNumber] * q3s[shipNumber]) > 0) {
            simulation.moveShipLeft(delta,
                    Math.abs(0.2f * (q0s[shipNumber] * q1s[shipNumber] + q2s[shipNumber] * q3s[shipNumber])),
                    shipNumber);
        } else {
            simulation.moveShipRight(delta,
                    Math.abs(0.2f * (q0s[shipNumber] * q1s[shipNumber] + q2s[shipNumber] * q3s[shipNumber])),
                    shipNumber);
        }
    }

    if (invaders.getController() != null) {
        if (buttonsPressed > 0) {
            simulation.shot();
        }

        // if the left stick moved, move the ship
        float axisValue = invaders.getController().getAxis(Ouya.AXIS_LEFT_X) * 0.5f;
        if (Math.abs(axisValue) > 0.25f) {
            if (axisValue > 0) {
                simulation.moveShipRight(delta, axisValue, 1);
            } else {
                simulation.moveShipLeft(delta, -axisValue, 1);
            }
        }
    }

    //      if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT) || Gdx.input.isKeyPressed(Keys.A)) simulation.moveShipLeft(delta, 0.5f);
    //      if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT) || Gdx.input.isKeyPressed(Keys.A)) simulation.moveShipLeft2(delta, 0.5f);
    //
    //      if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT) || Gdx.input.isKeyPressed(Keys.D)) simulation.moveShipRight(delta, 0.5f);
    //      if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT) || Gdx.input.isKeyPressed(Keys.D)) simulation.moveShipRight2(delta, 0.5f);
    //
    if (Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.SPACE))
        simulation.shot();
    //      if (Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.SPACE)) simulation.shot2();
}

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;/*w w  w .  j  av  a2  s .c  o  m*/

    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;
}