Classe Button.java
This commit is contained in:
parent
6dcd7feda5
commit
b63ee09571
@ -220,7 +220,7 @@ public class Engine {
|
|||||||
// Game logic should fit here
|
// Game logic should fit here
|
||||||
|
|
||||||
if (present) { //sprite //bindings
|
if (present) { //sprite //bindings
|
||||||
GamepadInput.gamepad(zangief, speed, buttonA, buttonB, buttonX, buttonY, LB, RB , select , start ,
|
GamepadInput.inputRefresh(buttonA, buttonB, buttonX, buttonY, LB, RB , select , start ,
|
||||||
L_JoystickClick , R_JoystickClick , Up , right , down , left,
|
L_JoystickClick , R_JoystickClick , Up , right , down , left,
|
||||||
leftJoyX_Axe, leftJoyY_Axe, rightJoyX_Axe, rightJoyY_Axe, LT, RT);
|
leftJoyX_Axe, leftJoyY_Axe, rightJoyX_Axe, rightJoyY_Axe, LT, RT);
|
||||||
|
|
||||||
|
@ -6,20 +6,19 @@ public class Button {
|
|||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
private final List<Integer> buttons;
|
private final List<Integer> buttons;
|
||||||
|
private final GamepadInput controller;
|
||||||
|
|
||||||
public Button(String name, List<Integer> buttons, GamepadInput controller){
|
public Button(String name, List<Integer> buttons, GamepadInput controller){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.buttons = buttons;
|
this.buttons = buttons;
|
||||||
}
|
this.controller = controller;
|
||||||
|
|
||||||
public void addButton(int key){
|
|
||||||
this.buttons.add(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isButtonPressed(){
|
public boolean isButtonPressed(){
|
||||||
for (int i : buttons){
|
for (int i : buttons){
|
||||||
GamepadInput.checkPressed(i);
|
if (controller.checkPressed(i)) return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
package engine.input;
|
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.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
|
||||||
/* Buttons
|
/* Buttons
|
||||||
0 : Croix / A
|
0 : Croix / A
|
||||||
1: rond /B
|
1: rond /B
|
||||||
@ -72,7 +66,7 @@ public class GamepadInput {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void gamepad(ObjectGl token, int speed,int ButtonA, int ButtonB, int ButtonX, int ButtonY, int LB, int RB ,
|
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 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
|
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);
|
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
|
||||||
@ -127,7 +121,16 @@ public class GamepadInput {
|
|||||||
//LT RT
|
//LT RT
|
||||||
LT_pressed = gamepadButton.get(LT) == 1;
|
LT_pressed = gamepadButton.get(LT) == 1;
|
||||||
RT_pressed = gamepadButton.get(RT) == 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user