diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 933c1e5..78679a3 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -220,9 +220,9 @@ 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, - leftJoyX_Axe, leftJoyY_Axe, rightJoyX_Axe, rightJoyY_Axe, LT, RT); + GamepadInput.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); System.out.println( " \n left :" + GamepadInput.leftJoyLeft + " \n right :" + GamepadInput.leftJoyRight + diff --git a/src/engine/input/Button.java b/src/engine/input/Button.java index ccef189..942b13f 100644 --- a/src/engine/input/Button.java +++ b/src/engine/input/Button.java @@ -6,20 +6,19 @@ public class Button { public String name; private final List buttons; + private final GamepadInput controller; public Button(String name, List buttons, GamepadInput controller){ this.name = name; this.buttons = buttons; - } - - public void addButton(int key){ - this.buttons.add(key); + this.controller = controller; } public boolean isButtonPressed(){ for (int i : buttons){ - GamepadInput.checkPressed(i); + if (controller.checkPressed(i)) return true; } + return false; } diff --git a/src/engine/input/GamepadInput.java b/src/engine/input/GamepadInput.java index 27c7662..a8b4c94 100644 --- a/src/engine/input/GamepadInput.java +++ b/src/engine/input/GamepadInput.java @@ -1,15 +1,9 @@ package engine.input; -import engine.math.Vector3f; -import engine.object.ObjectGl; -import org.lwjgl.glfw.GLFW; -import org.lwjgl.glfw.GLFWKeyCallback; - import java.nio.ByteBuffer; import java.nio.FloatBuffer; import static org.lwjgl.glfw.GLFW.*; -import static org.lwjgl.opengl.GL11.*; /* Buttons 0 : Croix / A 1: rond /B @@ -72,9 +66,9 @@ public class GamepadInput { - 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 + public static 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 ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); @@ -127,7 +121,16 @@ public class GamepadInput { //LT RT LT_pressed = gamepadButton.get(LT) == 1; RT_pressed = gamepadButton.get(RT) == 1; - } + + public boolean checkPressed(int keyCode){ + ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); + FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); + + assert gamepadAxes != null; + assert gamepadButton != null; + + return gamepadButton.get(keyCode) == 1; + } }