detection of all of the inputs ( joysticks included)

This commit is contained in:
Léo 2021-06-01 15:53:04 +02:00
parent b6b0d2bbc8
commit 8682d99578
2 changed files with 64 additions and 16 deletions

View File

@ -25,7 +25,9 @@ public class Engine {
private final List<ObjectGl> objectsGl; private final List<ObjectGl> objectsGl;
private final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7, L_JoystickClick = 8, R_JoystickClick =9, Up = 10, right = 11, down = 12, left = 13; private final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7,
L_JoystickClick = 8, R_JoystickClick =9, Up = 10, right = 11, down = 12, left = 13,
leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5;
private boolean running; private boolean running;
@ -218,12 +220,14 @@ public class Engine {
// Game logic should fit here // Game logic should fit here
if (present) { //sprite //bindings if (present) { //sprite //bindings
gamepadInput.gamepad(zangief, speed, buttonA, buttonB, buttonX, buttonY, LB, RB , select , start ,L_JoystickClick , R_JoystickClick , Up , right , down , left); gamepadInput.gamepad(zangief, speed, buttonA, buttonB, buttonX, buttonY, LB, RB , select , start ,
L_JoystickClick , R_JoystickClick , Up , right , down , left,
leftJoyX_Axe, leftJoyY_Axe, rightJoyX_Axe, rightJoyY_Axe, LT, RT);
System.out.println( " \n A :" + gamepadInput.buttonA_pressed + System.out.println( " \n left :" + gamepadInput.leftJoyLeft +
" \n B :" + gamepadInput.buttonB_pressed + " \n right :" + gamepadInput.leftJoyRight +
" \n Y :" + gamepadInput.buttonY_pressed + " \n down :" + gamepadInput.leftJoyDown +
" \n X :" + gamepadInput.buttonX_pressed); " \n up :" + gamepadInput.leftJoyUp);
} }
// Input.keyboardInput(zangief, speed); // Input.keyboardInput(zangief, speed);

View File

@ -56,8 +56,25 @@ public class gamepadInput{
public static boolean down_pressed = false; public static boolean down_pressed = false;
public static boolean left_pressed = false; public static boolean left_pressed = false;
public static boolean right_pressed = false; public static boolean right_pressed = false;
public static boolean leftJoyRight = false;
public static boolean leftJoyLeft = false;
public static boolean leftJoyDown = false;
public static boolean leftJoyUp = false;
public static boolean rightJoyLeft = false;
public static boolean rightJoyRight = false;
public static boolean rightJoyDown = false;
public static boolean rightJoyUp = false;
public static boolean LT_pressed = false;
public static boolean RT_pressed = false;
public static void gamepad(ObjectGl token, int speed,int ButtonA, int ButtonB, int ButtonX, int ButtonY, int LB, int RB , int select , int start ,int L_JoyClick ,int R_JoyClick ,int Up ,int right ,int down , int left) { //to update for more controlBinding public static void gamepad(ObjectGl token, int speed,int ButtonA, int ButtonB, int ButtonX, int ButtonY, int LB, int RB ,
int select , int start ,int L_JoyClick ,int R_JoyClick ,int up ,int right ,int down , int left,
int leftJoyX_Axe, int leftJoyY_Axe, int rightJoyX_Axe, int rightJoyY_Axe, int LT, int RT) { //to update for more controlBinding
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
@ -69,15 +86,12 @@ public class gamepadInput{
if (gamepadButton.get(ButtonA)==1 ) { if (gamepadButton.get(ButtonA)==1 ) {
buttonA_pressed = true; buttonA_pressed = true;
}else buttonA_pressed = false; }else buttonA_pressed = false;
if (gamepadButton.get(ButtonB)==1 ) { if (gamepadButton.get(ButtonB)==1 ) {
buttonB_pressed = true; buttonB_pressed = true;
}else buttonB_pressed = false; }else buttonB_pressed = false;
if (gamepadButton.get(ButtonY)==1 ) { if (gamepadButton.get(ButtonY)==1 ) {
buttonY_pressed = true; buttonY_pressed = true;
}else buttonY_pressed = false; }else buttonY_pressed = false;
if (gamepadButton.get(ButtonX)==1 ) { if (gamepadButton.get(ButtonX)==1 ) {
buttonX_pressed = true; buttonX_pressed = true;
}else buttonX_pressed = false; }else buttonX_pressed = false;
@ -96,7 +110,6 @@ public class gamepadInput{
if (gamepadButton.get(start)==1 ) { if (gamepadButton.get(start)==1 ) {
start_pressed = true; start_pressed = true;
}else start_pressed = false; }else start_pressed = false;
if (gamepadButton.get(select)==1 ) { if (gamepadButton.get(select)==1 ) {
select_pressed = true; select_pressed = true;
}else select_pressed = false; }else select_pressed = false;
@ -112,25 +125,56 @@ public class gamepadInput{
//up, down, left, right //up, down, left, right
if (gamepadButton.get(select)==1 ) { if (gamepadButton.get(up)==1 ) {
up_pressed = true; up_pressed = true;
}else up_pressed = false; }else up_pressed = false;
if (gamepadButton.get(down)==1 ) {
if (gamepadButton.get(select)==1 ) {
down_pressed = true; down_pressed = true;
}else down_pressed = false; }else down_pressed = false;
if (gamepadButton.get( left)==1 ) { if (gamepadButton.get( left)==1 ) {
left_pressed = true; left_pressed = true;
}else left_pressed = false; }else left_pressed = false;
if (gamepadButton.get(right)==1 ) { if (gamepadButton.get(right)==1 ) {
right_pressed = true; right_pressed = true;
}else right_pressed = false; }else right_pressed = false;
//Left Joystick
if (gamepadAxes.get(leftJoyX_Axe)> 0.1 ) {
leftJoyRight = true;
}else leftJoyRight = false;
if (gamepadAxes.get(leftJoyX_Axe)<-0.1 ) {
leftJoyLeft = true;
}else leftJoyLeft = false;
if (gamepadAxes.get(leftJoyY_Axe)> 0.1 ) {
leftJoyDown = true;
}else leftJoyDown = false;
if (gamepadAxes.get(leftJoyY_Axe)<-0.1 ) {
leftJoyUp = true;
}else leftJoyUp = false;
//Right Joystick
if (gamepadAxes.get(rightJoyX_Axe)> 0.1 ) {
rightJoyRight = true;
}else rightJoyRight = false;
if (gamepadAxes.get(rightJoyX_Axe)<-0.1 ) {
rightJoyLeft = true;
}else rightJoyLeft = false;
if (gamepadAxes.get(rightJoyY_Axe)> 0.1 ) {
rightJoyDown = true;
}else rightJoyDown = false;
if (gamepadAxes.get(rightJoyY_Axe)<-0.1 ) {
rightJoyUp = true;
}else rightJoyUp = false;
//LT RT
if (gamepadButton.get(LT)==1 ) {
LT_pressed = true;
}else LT_pressed = false;
if (gamepadButton.get(RT)==1 ) {
RT_pressed = true;
}else RT_pressed = false;