diff --git a/src/engine/input/GamepadInput.java b/src/engine/input/GamepadInput.java index 142a95b..77b3b25 100644 --- a/src/engine/input/GamepadInput.java +++ b/src/engine/input/GamepadInput.java @@ -79,11 +79,11 @@ public class GamepadInput { if (magnitude < 0.3) return CENTER; if (angle < 22.5 && angle > -22.5) return RIGHT; else if (angle > -67.5 && angle < -22.5) return UPPER_RIGHT; - else if (angle > -112.5 && angle < -67.5) return UP; + else if (angle > -112.5 && angle < -67.5) return UP_STICK; else if (angle > -157.5 && angle < -112.5) return UPPER_LEFT; else if (angle < -157.5 || angle > 157.5) return LEFT; else if (angle < 157.5 && angle > 112.5) return LOWER_LEFT; - else if (angle < 112.5 && angle > 67.5) return DOWN; + else if (angle < 112.5 && angle > 67.5) return DOWN_STICK; else if (angle < 67.5 && angle > 22.5) return LOWER_RIGHT; return -1; // TEST diff --git a/src/engine/input/InputConst.java b/src/engine/input/InputConst.java index 85c927e..257ba8c 100644 --- a/src/engine/input/InputConst.java +++ b/src/engine/input/InputConst.java @@ -12,6 +12,6 @@ public class InputConst { */ public final static int leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5; - public final static int RIGHT = 0, UPPER_RIGHT = 1, UP = 2, UPPER_LEFT = 3, LEFT = 4, LOWER_LEFT = 5, - DOWN = 6, LOWER_RIGHT = 7, CENTER = 8; + public final static int RIGHT = 0, UPPER_RIGHT = 1, UP_STICK = 2, UPPER_LEFT = 3, LEFT = 4, LOWER_LEFT = 5, + DOWN_STICK = 6, LOWER_RIGHT = 7, CENTER = 8; } diff --git a/src/gameplay/input/Inputs.java b/src/gameplay/input/Inputs.java index 130e201..ee429cf 100644 --- a/src/gameplay/input/Inputs.java +++ b/src/gameplay/input/Inputs.java @@ -1,9 +1,9 @@ package gameplay.input; import engine.input.GamepadInput; -import engine.input.InputConst; import gameplay.input.ButtonIG; +import static engine.input.InputConst.*; import static gameplay.input.ButtonIG.*; /** @@ -95,14 +95,19 @@ public class Inputs { } public void recordFromGamepad(GamepadInput pad, boolean facesRight) { - this.tab[ButtonIG.UP.toInt()] = pad.checkPressed(InputConst.up); - this.tab[DOWN.toInt()] = pad.checkPressed(InputConst.down); - this.tab[ButtonIG.BACK.toInt()] = (pad.checkPressed(InputConst.left) && facesRight) || (pad.checkPressed(InputConst.right)&&!facesRight); - this.tab[FORWARD.toInt()] = (pad.checkPressed(InputConst.right) && facesRight) || (pad.checkPressed(InputConst.left) && !facesRight); - this.tab[ButtonIG.A.toInt()] = pad.checkPressed(InputConst.buttonX); - this.tab[ButtonIG.B.toInt()] = pad.checkPressed(InputConst.buttonA); - this.tab[ButtonIG.C.toInt()] = pad.checkPressed(InputConst.buttonY); - this.tab[ButtonIG.D.toInt()] = pad.checkPressed(InputConst.buttonB); + int leftStickPadDir = pad.getAxisDiscreet(leftJoyX_Axe); + // On check les directions du stick mtn pour eviter les répétitions comme les diagonales sont exclusive on les check aussi + boolean check_pressed_left = pad.checkPressed(left) || leftStickPadDir == UPPER_LEFT ||leftStickPadDir == LEFT || leftStickPadDir == LOWER_LEFT; + boolean check_pressed_right = pad.checkPressed(right) || leftStickPadDir == UPPER_RIGHT ||leftStickPadDir == RIGHT || leftStickPadDir == LOWER_RIGHT; + + this.tab[ButtonIG.UP.toInt()] = pad.checkPressed(up) || leftStickPadDir == UP_STICK || leftStickPadDir == UPPER_LEFT || leftStickPadDir == UPPER_RIGHT; + this.tab[DOWN.toInt()] = pad.checkPressed(down) || leftStickPadDir == DOWN_STICK || leftStickPadDir == LOWER_LEFT || leftStickPadDir == LOWER_RIGHT;; + this.tab[ButtonIG.BACK.toInt()] = (check_pressed_left && facesRight) || (check_pressed_right &&!facesRight); + this.tab[FORWARD.toInt()] = (check_pressed_right && facesRight) || (check_pressed_left && !facesRight); + this.tab[ButtonIG.A.toInt()] = pad.checkPressed(buttonX); + this.tab[ButtonIG.B.toInt()] = pad.checkPressed(buttonA); + this.tab[ButtonIG.C.toInt()] = pad.checkPressed(buttonY); + this.tab[ButtonIG.D.toInt()] = pad.checkPressed(buttonB); } public String toString() {