added gamepadInputClass
This commit is contained in:
parent
f2b2fa9e9b
commit
888e5825ba
@ -24,7 +24,7 @@ public class Engine {
|
||||
|
||||
private final List<ObjectGl> objectsGl;
|
||||
|
||||
|
||||
private final static int buttonA=0, buttonB=1, buttonX=3, buttonY=4;
|
||||
|
||||
private boolean running;
|
||||
|
||||
@ -210,16 +210,13 @@ public class Engine {
|
||||
boolean nextFrame = false;
|
||||
boolean present = glfwJoystickPresent(GLFW_JOYSTICK_1);
|
||||
|
||||
int buttonA=0;
|
||||
int buttonB=1;
|
||||
int buttonX=3;
|
||||
int buttonY=4;
|
||||
|
||||
|
||||
while (engine.isRunning()) {
|
||||
lastFrame = System.currentTimeMillis();
|
||||
// Game logic should fit here
|
||||
|
||||
if (present) {
|
||||
if (present) { //sprite //bindings
|
||||
gamepadInput.gamepadInput(zangief, speed, buttonA, buttonB, buttonX, buttonY);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
public class Input extends GLFWKeyCallback {
|
||||
|
||||
public static boolean[] keys = new boolean[65536];
|
||||
public static boolean keyPressed = false;
|
||||
|
||||
@Override
|
||||
public void invoke(long window, int key, int scancode, int action, int mods) {
|
||||
@ -37,9 +38,6 @@ public class Input extends GLFWKeyCallback {
|
||||
assert gamepadAxes != null;
|
||||
assert gamepadButton != null;
|
||||
|
||||
String name = GLFW.glfwGetJoystickName(GLFW_JOYSTICK_1);
|
||||
System.out.println("GamePad Name :" + name);
|
||||
|
||||
|
||||
|
||||
if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox)
|
||||
@ -48,9 +46,9 @@ public class Input extends GLFWKeyCallback {
|
||||
if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche
|
||||
token.translate(new Vector3f (5 * speed * gamepadAxes.get(2), 0.0f, 0.0f));
|
||||
if ( gamepadAxes.get(2) < -0.1 ){
|
||||
token.setTextureWrap(121,0,57,80, ObjectGl.DEFAULT);
|
||||
token.setTextureWrap(121,0,57,80, ObjectGl.STICK_TOP);
|
||||
}else if (gamepadAxes.get(2) > 0.1) {
|
||||
token.setTextureWrap(178,0,62,82, ObjectGl.DEFAULT);
|
||||
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +86,7 @@ public class Input extends GLFWKeyCallback {
|
||||
}
|
||||
|
||||
public static void keyboardInput(ObjectGl token, int speed) {
|
||||
boolean keyPressed = false;
|
||||
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S)) {
|
||||
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
||||
keyPressed = true;
|
||||
|
76
src/engine/input/gamepadInput.java
Normal file
76
src/engine/input/gamepadInput.java
Normal file
@ -0,0 +1,76 @@
|
||||
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
|
||||
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 class gamepadInput{
|
||||
//à définir //à définir
|
||||
public static void gamepadInput(ObjectGl token, int speed,int jump, int attack, int act3, int act4) { //to update for more controlBinding
|
||||
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
|
||||
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
|
||||
|
||||
assert gamepadAxes != null;
|
||||
assert gamepadButton != null;
|
||||
|
||||
if (gamepadButton.get(jump)==1 ) { // appuie sur croix(PlayStation) A (Xbox)
|
||||
jump( token,speed);
|
||||
}
|
||||
|
||||
if (gamepadButton.get(attack)==1 ) { // appuie sur rond(PlayStation) B (Xbox)
|
||||
attack( token,speed);
|
||||
}
|
||||
|
||||
if (gamepadAxes.get(3) > 0.1) {
|
||||
crouch(token,speed);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void jump(ObjectGl token,int speed) {
|
||||
token.translate(new Vector3f( 0.0f, speed * 20.0f, 0.0f));
|
||||
|
||||
}
|
||||
|
||||
public static void attack(ObjectGl token,int speed) {
|
||||
|
||||
}
|
||||
|
||||
public static void crouch(ObjectGl token,int speed) {
|
||||
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user