diff --git a/.gitignore b/.gitignore index 3972786..763ac98 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.gitignore /jeu-de-combat.iml /target/ +/bin/ diff --git a/src/engine/Engine.java b/src/engine/Engine.java index f571ff0..52f85cf 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -8,6 +8,8 @@ import org.lwjgl.glfw.GLFWFramebufferSizeCallback; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.opengl.GL; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.List; @@ -179,6 +181,7 @@ public class Engine { // Game logic should fit here zangief.setTextureWrap(52,2,70,83); + gamepadInput(zangief, speed); input(zangief, speed); // input(smiley2, speed); @@ -213,6 +216,49 @@ public class Engine { // if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f)); // if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f)); // } + private static void gamepadInput(ObjectGl token, int speed) { + ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); + FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); + String name = GLFW.glfwGetJoystickName(GLFW_JOYSTICK_1); + + //System.out.println("GamePad Name :" + name); + for (int i =0 ; i < gamepadAxes.capacity(); i++) { + System.out.println(i + " :" + gamepadAxes.get(i)); + } + System.out.println(); + System.out.println(); + + if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox) + token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f)); + } + + /* Buttons + 0 : Croix / A + 1: rond /B + 2: carré / X + 3: triangle / Y + 4: L1 / LB + 5: R1 / RB + 6:select + 7:start + 8:L3 + 9:R3 + 10: haut + 11: droite + 12: bas + 13: gauche + */ + + /* Axes + 0 : left X axe ( right : 1 left -1) + 1: left Y axe ( down : 1 , Up -1) + 2: right X axe ( right : 1 left -1) + 3: right Y axe ( down : 1 , Up -1) + 4:L2 / LT : 1 active, -1 unactive + 5: R2 /RT : 1 active, -1 unactive + */ + + } public static void input(ObjectGlTex token, int speed) { if (Input.isKeyDown(GLFW.GLFW_KEY_W)) {