From 094fedc3a22cb9fdc49bae1e086925ec3b39d795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o?= Date: Tue, 1 Jun 2021 19:47:47 +0200 Subject: [PATCH] inputVariables --- src/engine/Engine.java | 8 +---- src/engine/input/GamepadInput.java | 54 ++++++++++++++-------------- src/engine/input/inputVariables.java | 7 ++++ 3 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 src/engine/input/inputVariables.java diff --git a/src/engine/Engine.java b/src/engine/Engine.java index cd3d754..4f6d8f3 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -25,10 +25,6 @@ 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, - leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5; - private boolean running; private final int width; @@ -221,9 +217,7 @@ public class Engine { if (present) { //sprite //bindings GamepadInput gamepad1 = new GamepadInput(false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false); - gamepad1.inputRefresh(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); + gamepad1.inputRefresh(); System.out.println( " \n left :" + gamepad1.leftJoyLeft + " \n right :" + gamepad1.leftJoyRight + diff --git a/src/engine/input/GamepadInput.java b/src/engine/input/GamepadInput.java index d3ee603..2e9d055 100644 --- a/src/engine/input/GamepadInput.java +++ b/src/engine/input/GamepadInput.java @@ -3,6 +3,8 @@ package engine.input; import java.nio.ByteBuffer; import java.nio.FloatBuffer; +import engine.Engine; + import static org.lwjgl.glfw.GLFW.*; /* Buttons 0 : Croix / A @@ -95,9 +97,7 @@ public class GamepadInput { this.RT_pressed =RT_pressed; } - public void inputRefresh(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 + public void inputRefresh() { ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); @@ -106,50 +106,50 @@ public class GamepadInput { // A B X Y - buttonA_pressed = gamepadButton.get(ButtonA) == 1; - buttonB_pressed = gamepadButton.get(ButtonB) == 1; - buttonY_pressed = gamepadButton.get(ButtonY) == 1; - buttonX_pressed = gamepadButton.get(ButtonX) == 1; + buttonA_pressed = gamepadButton.get(inputVariables.buttonA) == 1; + buttonB_pressed = gamepadButton.get(inputVariables.buttonB) == 1; + buttonY_pressed = gamepadButton.get(inputVariables.buttonY) == 1; + buttonX_pressed = gamepadButton.get(inputVariables.buttonX) == 1; // LB RB - LB_pressed = gamepadButton.get(LB) == 1; - RB_pressed = gamepadButton.get(RB) == 1; + LB_pressed = gamepadButton.get(inputVariables.LB) == 1; + RB_pressed = gamepadButton.get(inputVariables.RB) == 1; //start select - start_pressed = gamepadButton.get(start) == 1; - select_pressed = gamepadButton.get(select) == 1; + start_pressed = gamepadButton.get(inputVariables.start) == 1; + select_pressed = gamepadButton.get(inputVariables.select) == 1; //R & L JoystickClick - R_JoyClick_pressed = gamepadButton.get(R_JoyClick) == 1; - L_JoyClick_pressed = gamepadButton.get(L_JoyClick) == 1; + R_JoyClick_pressed = gamepadButton.get(inputVariables.R_JoystickClick) == 1; + L_JoyClick_pressed = gamepadButton.get(inputVariables.L_JoystickClick) == 1; //up, down, left, right - up_pressed = gamepadButton.get(up) == 1; - down_pressed = gamepadButton.get(down) == 1; - left_pressed = gamepadButton.get(left) == 1; - right_pressed = gamepadButton.get(right) == 1; + up_pressed = gamepadButton.get(inputVariables.up) == 1; + down_pressed = gamepadButton.get(inputVariables.down) == 1; + left_pressed = gamepadButton.get(inputVariables.left) == 1; + right_pressed = gamepadButton.get(inputVariables.right) == 1; //Left Joystick - leftJoyRight = gamepadAxes.get(leftJoyX_Axe) > 0.1; - leftJoyLeft = gamepadAxes.get(leftJoyX_Axe) < -0.1; - leftJoyDown = gamepadAxes.get(leftJoyY_Axe) > 0.1; - leftJoyUp = gamepadAxes.get(leftJoyY_Axe) < -0.1; + leftJoyRight = gamepadAxes.get(inputVariables.leftJoyX_Axe) > 0.1; + leftJoyLeft = gamepadAxes.get(inputVariables.leftJoyX_Axe) < -0.1; + leftJoyDown = gamepadAxes.get(inputVariables.leftJoyY_Axe) > 0.1; + leftJoyUp = gamepadAxes.get(inputVariables.leftJoyY_Axe) < -0.1; //Right Joystick - rightJoyRight = gamepadAxes.get(rightJoyX_Axe) > 0.1; - rightJoyLeft = gamepadAxes.get(rightJoyX_Axe) < -0.1; - rightJoyDown = gamepadAxes.get(rightJoyY_Axe) > 0.1; - rightJoyUp = gamepadAxes.get(rightJoyY_Axe) < -0.1; + rightJoyRight = gamepadAxes.get(inputVariables.rightJoyX_Axe) > 0.1; + rightJoyLeft = gamepadAxes.get(inputVariables.rightJoyX_Axe) < -0.1; + rightJoyDown = gamepadAxes.get(inputVariables.rightJoyY_Axe) > 0.1; + rightJoyUp = gamepadAxes.get(inputVariables.rightJoyY_Axe) < -0.1; //LT RT - LT_pressed = gamepadButton.get(LT) == 1; - RT_pressed = gamepadButton.get(RT) == 1; + LT_pressed = gamepadButton.get(inputVariables.LT) == 1; + RT_pressed = gamepadButton.get(inputVariables.RT) == 1; } public boolean checkPressed(int keyCode){ diff --git a/src/engine/input/inputVariables.java b/src/engine/input/inputVariables.java new file mode 100644 index 0000000..d8af4f4 --- /dev/null +++ b/src/engine/input/inputVariables.java @@ -0,0 +1,7 @@ +package engine.input; + +public class inputVariables { + public 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; +}