@Override
  public void movePlayer() {

    SPEED = player.getSpeed();
    analogX = controller.getAxis(XBox360Pad.AXIS_LEFT_X);
    analogY = controller.getAxis(XBox360Pad.AXIS_LEFT_Y);

    if (analogY < -0.2f) { // up
      moveVertical(SPEED * -analogY, true);

    } else if (analogY > 0.2f) { // down
      moveVertical(SPEED * -analogY, false);
    } else {

      stopShip();
    }

    if (analogX < -0.2f || analogX > 0.2f) { // left|right
      moveHorizontal(SPEED * analogX);
    }

    PlayerGun gun = player.getGun();
    if (controller.getAxis(XBox360Pad.AXIS_RIGHT_TRIGGER) < -0.5f) {
      if (!gun.isCharging()) {
        gun.setChargingShot(true);
      }
    } else {
      if (gun.isCharging()) {
        gun.releaseShot(player.getTexture(), player.getPosition());
      }
    }
  }
Beispiel #2
0
  private void processGamepad() {
    for (Controller controller : Controllers.getControllers()) {
      final float MOV_THRESHOLD = 0.25f;
      float xaxis = controller.getAxis(1);
      float yaxis = -controller.getAxis(0);
      if (Math.abs(xaxis) < MOV_THRESHOLD) xaxis = 0f;
      if (Math.abs(yaxis) < MOV_THRESHOLD) yaxis = 0f;
      player.move(xaxis, 0);
      player.move(0, yaxis);

      if (controller.getButton(0)) player.useShield();
    }
  }