Exemple utilisation Input

This commit is contained in:
Antoine 2021-06-02 15:23:44 +02:00
parent c22f4266d1
commit bce2220453
2 changed files with 31 additions and 12 deletions

View File

@ -1,7 +1,6 @@
package engine;
import engine.input.KeyboardInput;
import engine.input.GamepadInput;
import engine.input.*;
import engine.math.*;
import engine.object.*;
import engine.sound.*;
@ -206,7 +205,25 @@ public class Engine {
long lastFrame;
int frame = 0;
boolean nextFrame = false;
boolean present = glfwJoystickPresent(GLFW_JOYSTICK_1);
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
/*
* Création des manettes / action
*/
GamepadInput gamepad1 = null;
Button jump = null;
if (Joystick1Present){
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
List<Integer> listJump = new ArrayList<>();
listJump.add(InputConst.buttonA);
jump = new Button("jump", listJump, gamepad1);
}
@ -214,16 +231,16 @@ public class Engine {
lastFrame = System.currentTimeMillis();
// Game logic should fit here
if (present) {
GamepadInput gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
if (Joystick1Present) {
gamepad1.inputRefresh();
// System.out.println( " \n left :" + gamepad1.leftJoyLeft +
// " \n right :" + gamepad1.leftJoyRight +
// " \n down :" + gamepad1.leftJoyDown +
// " \n up :" + gamepad1.leftJoyUp);
System.out.println(gamepad1.getAxisDiscreet(GLFW_GAMEPAD_AXIS_LEFT_X));
// Check si le personnage a sauté
if (jump.isButtonPressed()){
// Le personnage saute
System.out.println(" JE SAUTE ");
}
}
// Input.keyboardInput(zangief, speed);

View File

@ -73,6 +73,8 @@ public class GamepadInput {
public GamepadInput (int gamepadNum){
this.gamepadNum = gamepadNum;
this.gamepadAxes = null;
this.gamepadButton = null;
this.buttonA_pressed = false;
this.buttonB_pressed = false;
this.buttonY_pressed = false;