org.lwjgl.input.Controller Java Examples

The following examples show how to use org.lwjgl.input.Controller. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Input.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if controller button is pressed
 * 
 * @param controller The index of the controller to check
 * @param index The index of the button to check
 * @return True if the button is pressed
 */
public boolean isButtonPressed(int index, int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isButtonPressed(index, i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).isButtonPressed(index);
}
 
Example #2
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check if controller button is pressed
 * 
 * @param controller The index of the controller to check
 * @param index The index of the button to check
 * @return True if the button is pressed
 */
public boolean isButtonPressed(int index, int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isButtonPressed(index, i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).isButtonPressed(index);
}
 
Example #3
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check if the controller has the down direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the down
 */
public boolean isControllerDown(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerDown(i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).getYAxisValue() > 0.5f
		   || ((Controller) controllers.get(controller)).getPovY() > 0.5f;
       
}
 
Example #4
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check if the controller has the up direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the up
 */
public boolean isControllerUp(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerUp(i)) {
				return true;
			}
		}
		
		return false;
	}
	return ((Controller) controllers.get(controller)).getYAxisValue() < -0.5f
	   		|| ((Controller) controllers.get(controller)).getPovY() < -0.5f;
}
 
Example #5
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check if the controller has the right direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the right
 */
public boolean isControllerRight(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerRight(i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).getXAxisValue() > 0.5f
  				|| ((Controller) controllers.get(controller)).getPovX() > 0.5f;
}
 
Example #6
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check if the controller has the left direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the left
 */
public boolean isControllerLeft(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}
	
	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerLeft(i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).getXAxisValue() < -0.5f
			|| ((Controller) controllers.get(controller)).getPovX() < -0.5f;
}
 
Example #7
Source File: Input.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if the controller has the down direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the down
 */
public boolean isControllerDown(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerDown(i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).getYAxisValue() > 0.5f
		   || ((Controller) controllers.get(controller)).getPovY() > 0.5f;
       
}
 
Example #8
Source File: Input.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if the controller has the up direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the up
 */
public boolean isControllerUp(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerUp(i)) {
				return true;
			}
		}
		
		return false;
	}
	return ((Controller) controllers.get(controller)).getYAxisValue() < -0.5f
	   		|| ((Controller) controllers.get(controller)).getPovY() < -0.5f;
}
 
Example #9
Source File: Input.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if the controller has the right direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the right
 */
public boolean isControllerRight(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}

	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerRight(i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).getXAxisValue() > 0.5f
  				|| ((Controller) controllers.get(controller)).getPovX() > 0.5f;
}
 
Example #10
Source File: Input.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if the controller has the left direction pressed
 * 
 * @param controller The index of the controller to check
 * @return True if the controller is pressed to the left
 */
public boolean isControllerLeft(int controller) {
	if (controller >= getControllerCount()) {
		return false;
	}
	
	if (controller == ANY_CONTROLLER) {
		for (int i=0;i<controllers.size();i++) {
			if (isControllerLeft(i)) {
				return true;
			}
		}
		
		return false;
	}
	
	return ((Controller) controllers.get(controller)).getXAxisValue() < -0.5f
			|| ((Controller) controllers.get(controller)).getPovX() < -0.5f;
}
 
Example #11
Source File: StateConfigJoystickTest.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	if(!container.hasFocus()) {
		if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	ResourceHolderSlick.imgMenu.draw(0, 0);

	NormalFontSlick.printFontGrid(1, 1, "JOYSTICK INPUT TEST (" + (player + 1) + "P)", NormalFontSlick.COLOR_ORANGE);

	if(joyNumber < 0) {
		NormalFontSlick.printFontGrid(1, 3, "NO JOYSTICK", NormalFontSlick.COLOR_RED);
	} else if(frame >= KEYACCEPTFRAME) {
		NormalFontSlick.printFontGrid(1, 3, "JOYSTICK NUMBER:" + joyNumber, NormalFontSlick.COLOR_RED);

		NormalFontSlick.printFontGrid(1, 5, "LAST PRESSED BUTTON:" + ((lastPressButton == -1) ? "NONE" : String.valueOf(lastPressButton)));

		Controller controller = ControllerManager.controllers.get(joyNumber);

		NormalFontSlick.printFontGrid(1, 7, "AXIS X:" + controller.getXAxisValue());
		NormalFontSlick.printFontGrid(1, 8, "AXIS Y:" + controller.getYAxisValue());

		NormalFontSlick.printFontGrid(1, 10, "POV X:" + controller.getPovX());
		NormalFontSlick.printFontGrid(1, 11, "POV Y:" + controller.getPovY());
	}

	if(frame >= KEYACCEPTFRAME) {
		NormalFontSlick.printFontGrid(1, 23, "ENTER/BACKSPACE: EXIT", NormalFontSlick.COLOR_GREEN);
	}

	// FPS
	NullpoMinoSlick.drawFPS(container);
	// Observer
	NullpoMinoSlick.drawObserverClient();
	if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example #12
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the number of axis that are avaiable on a given controller
 * 
 * @param controller The index of the controller to check
 * @return The number of axis available on the controller
 */
public int getAxisCount(int controller) {
	return ((Controller) controllers.get(controller)).getAxisCount();
}
 
Example #13
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the value of the axis with the given index
 *  
 * @param controller The index of the controller to check
 * @param axis The index of the axis to read
 * @return The axis value at time of reading
 */ 
public float getAxisValue(int controller, int axis) {
	return ((Controller) controllers.get(controller)).getAxisValue(axis);
}
 
Example #14
Source File: Input.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the name of the axis with the given index
 *  
 * @param controller The index of the controller to check
 * @param axis The index of the axis to read
 * @return The name of the specified axis
 */ 
public String getAxisName(int controller, int axis) {
	return ((Controller) controllers.get(controller)).getAxisName(axis);
}
 
Example #15
Source File: Input.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the name of the axis with the given index
 *  
 * @param controller The index of the controller to check
 * @param axis The index of the axis to read
 * @return The name of the specified axis
 */ 
public String getAxisName(int controller, int axis) {
	return ((Controller) controllers.get(controller)).getAxisName(axis);
}
 
Example #16
Source File: Input.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the value of the axis with the given index
 *  
 * @param controller The index of the controller to check
 * @param axis The index of the axis to read
 * @return The axis value at time of reading
 */ 
public float getAxisValue(int controller, int axis) {
	return ((Controller) controllers.get(controller)).getAxisValue(axis);
}
 
Example #17
Source File: Input.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the number of axis that are avaiable on a given controller
 * 
 * @param controller The index of the controller to check
 * @return The number of axis available on the controller
 */
public int getAxisCount(int controller) {
	return ((Controller) controllers.get(controller)).getAxisCount();
}