From 8682d99578c07d39cc2363bb5a8f588f9eab8d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o?= Date: Tue, 1 Jun 2021 15:53:04 +0200 Subject: [PATCH] detection of all of the inputs ( joysticks included) --- src/engine/Engine.java | 16 +++++--- src/engine/input/gamepadInput.java | 64 +++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 497b607..ee1372b 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -25,7 +25,9 @@ public class Engine { private final List 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; @@ -218,12 +220,14 @@ public class Engine { // Game logic should fit here 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 + - " \n B :" + gamepadInput.buttonB_pressed + - " \n Y :" + gamepadInput.buttonY_pressed + - " \n X :" + gamepadInput.buttonX_pressed); + System.out.println( " \n left :" + gamepadInput.leftJoyLeft + + " \n right :" + gamepadInput.leftJoyRight + + " \n down :" + gamepadInput.leftJoyDown + + " \n up :" + gamepadInput.leftJoyUp); } // Input.keyboardInput(zangief, speed); diff --git a/src/engine/input/gamepadInput.java b/src/engine/input/gamepadInput.java index 6f99326..64d546b 100644 --- a/src/engine/input/gamepadInput.java +++ b/src/engine/input/gamepadInput.java @@ -56,8 +56,25 @@ public class gamepadInput{ public static boolean down_pressed = false; public static boolean left_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); FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); @@ -69,15 +86,12 @@ public class gamepadInput{ if (gamepadButton.get(ButtonA)==1 ) { buttonA_pressed = true; }else buttonA_pressed = false; - if (gamepadButton.get(ButtonB)==1 ) { buttonB_pressed = true; }else buttonB_pressed = false; - if (gamepadButton.get(ButtonY)==1 ) { buttonY_pressed = true; }else buttonY_pressed = false; - if (gamepadButton.get(ButtonX)==1 ) { buttonX_pressed = true; }else buttonX_pressed = false; @@ -96,7 +110,6 @@ public class gamepadInput{ if (gamepadButton.get(start)==1 ) { start_pressed = true; }else start_pressed = false; - if (gamepadButton.get(select)==1 ) { select_pressed = true; }else select_pressed = false; @@ -112,25 +125,56 @@ public class gamepadInput{ //up, down, left, right - if (gamepadButton.get(select)==1 ) { + if (gamepadButton.get(up)==1 ) { up_pressed = true; }else up_pressed = false; - - if (gamepadButton.get(select)==1 ) { + if (gamepadButton.get(down)==1 ) { down_pressed = true; }else down_pressed = false; - if (gamepadButton.get( left)==1 ) { left_pressed = true; }else left_pressed = false; - if (gamepadButton.get(right)==1 ) { right_pressed = true; }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;