@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()); } } }
public static void printControllers() { int i = 0; for (Controller c : Controllers.getControllers()) { System.out.println("Controller #" + i + ": " + c.getName()); i += 1; } if (Controllers.getControllers().size == 0) { System.out.println("Controllers: No controllers attached"); } }
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(); } }
@Override public void disconnected(Controller controller) { System.out.println("Disconnected " + controller.getName()); ControllerHelper.printControllers(); }