Classe Button.java

This commit is contained in:
Antoine 2021-06-01 18:04:33 +02:00
parent 6dcd7feda5
commit b63ee09571
3 changed files with 20 additions and 18 deletions

View File

@ -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 +

View File

@ -6,20 +6,19 @@ public class Button {
public String name;
private final List<Integer> buttons;
private final GamepadInput controller;
public Button(String name, List<Integer> 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;
}

View File

@ -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;
}
}