Merge branch 'master' of https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat
This commit is contained in:
commit
ab03782425
@ -1,40 +1,55 @@
|
|||||||
{
|
{
|
||||||
"test": "test valide",
|
|
||||||
"arena": [
|
"arena": [
|
||||||
|
"random",
|
||||||
"arena1.png",
|
"arena1.png",
|
||||||
"arena2.png",
|
"arena2.png"
|
||||||
"random"
|
|
||||||
],
|
],
|
||||||
"nb_players": [
|
"nb_players": [
|
||||||
"1",
|
"1",
|
||||||
"2"
|
"2"
|
||||||
],
|
],
|
||||||
"character1": [
|
"character1": [
|
||||||
|
"random",
|
||||||
"character1.png",
|
"character1.png",
|
||||||
"character2.png",
|
"character2.png"
|
||||||
"random"
|
|
||||||
],
|
],
|
||||||
"character2": [
|
"character2": [
|
||||||
|
"random",
|
||||||
"character1.png",
|
"character1.png",
|
||||||
"character1_swapcolor.png",
|
"character1_swapcolor.png",
|
||||||
"character2.png",
|
"character2.png",
|
||||||
"character2_swapcolor.png",
|
"character2_swapcolor.png"
|
||||||
"random"
|
|
||||||
],
|
],
|
||||||
"resolution": [
|
"resolution": [
|
||||||
"1280 x 1024",
|
{
|
||||||
"1680 x 1050",
|
"width": "800",
|
||||||
"1920 x 1080",
|
"height": "600"
|
||||||
"800 x 600"
|
},
|
||||||
|
{
|
||||||
|
"width": "1280",
|
||||||
|
"height": "1024"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"width": "1680",
|
||||||
|
"height": "1050"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"width": "1920",
|
||||||
|
"height": "1080"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"persoWidth": "800",
|
||||||
|
"persoHeight": "600"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"button": [
|
"button": [
|
||||||
"up",
|
"UP",
|
||||||
"down",
|
"DOWN",
|
||||||
"rigth",
|
"RIGTH",
|
||||||
"left",
|
"LEFT",
|
||||||
"a",
|
"A",
|
||||||
"b",
|
"B",
|
||||||
"c",
|
"X",
|
||||||
"d"
|
"Y"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package engine;
|
package engine;
|
||||||
|
|
||||||
import engine.input.Input;
|
import engine.input.*;
|
||||||
//import engine.input.gamepadInput;
|
|
||||||
import engine.input.GamepadInput;
|
|
||||||
import engine.math.*;
|
import engine.math.*;
|
||||||
import engine.object.*;
|
import engine.object.*;
|
||||||
import engine.sound.*;
|
import engine.sound.*;
|
||||||
@ -73,7 +71,7 @@ public class Engine {
|
|||||||
// On met la fenêtre au centre de l'écran principale
|
// On met la fenêtre au centre de l'écran principale
|
||||||
glfwSetWindowPos(getWindow(), (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
|
glfwSetWindowPos(getWindow(), (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
|
||||||
|
|
||||||
glfwSetKeyCallback(getWindow(), new Input());
|
glfwSetKeyCallback(getWindow(), new KeyboardInput());
|
||||||
glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
|
glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
|
||||||
|
|
||||||
// Contexte = zone cible des rendus
|
// Contexte = zone cible des rendus
|
||||||
@ -207,7 +205,25 @@ public class Engine {
|
|||||||
long lastFrame;
|
long lastFrame;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
boolean nextFrame = false;
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -215,14 +231,16 @@ public class Engine {
|
|||||||
lastFrame = System.currentTimeMillis();
|
lastFrame = System.currentTimeMillis();
|
||||||
// Game logic should fit here
|
// Game logic should fit here
|
||||||
|
|
||||||
if (present) { //sprite //bindings
|
if (Joystick1Present) {
|
||||||
GamepadInput gamepad1 = new GamepadInput(GLFW_JOYSTICK_1, false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
|
|
||||||
gamepad1.inputRefresh();
|
gamepad1.inputRefresh();
|
||||||
|
|
||||||
System.out.println( " \n left :" + gamepad1.leftJoyLeft +
|
System.out.println(gamepad1.getAxisDiscreet(GLFW_GAMEPAD_AXIS_LEFT_X));
|
||||||
" \n right :" + gamepad1.leftJoyRight +
|
|
||||||
" \n down :" + gamepad1.leftJoyDown +
|
// Check si le personnage a sauté
|
||||||
" \n up :" + gamepad1.leftJoyUp);
|
if (jump.isButtonPressed()){
|
||||||
|
// Le personnage saute
|
||||||
|
System.out.println(" JE SAUTE ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input.keyboardInput(zangief, speed);
|
// Input.keyboardInput(zangief, speed);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package engine.input;
|
package engine.input;
|
||||||
|
|
||||||
|
import engine.math.Vector3f;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import static engine.input.inputVariables.*;
|
import static engine.input.InputConst.*;
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
/* Buttons
|
/* Buttons
|
||||||
0 : Croix / A
|
0 : Croix / A
|
||||||
@ -34,6 +36,8 @@ import static org.lwjgl.glfw.GLFW.*;
|
|||||||
public class GamepadInput {
|
public class GamepadInput {
|
||||||
|
|
||||||
private final int gamepadNum;
|
private final int gamepadNum;
|
||||||
|
private ByteBuffer gamepadButton;
|
||||||
|
private FloatBuffer gamepadAxes;
|
||||||
|
|
||||||
public boolean buttonA_pressed ;
|
public boolean buttonA_pressed ;
|
||||||
public boolean buttonB_pressed ;
|
public boolean buttonB_pressed ;
|
||||||
@ -67,40 +71,40 @@ public class GamepadInput {
|
|||||||
public boolean LT_pressed ;
|
public boolean LT_pressed ;
|
||||||
public boolean RT_pressed;
|
public boolean RT_pressed;
|
||||||
|
|
||||||
public GamepadInput (int gamepadNum, boolean buttonA_pressed,boolean buttonB_pressed,boolean buttonY_pressed, boolean buttonX_pressed, boolean LB_pressed,
|
public GamepadInput (int gamepadNum){
|
||||||
boolean RB_pressed, boolean select_pressed, boolean start_pressed,boolean R_JoyClick_pressed, boolean L_JoyClick_pressed , boolean up_pressed,
|
|
||||||
boolean down_pressed,boolean left_pressed,boolean right_pressed,boolean leftJoyRight,boolean leftJoyLeft,boolean leftJoyDown, boolean leftJoyUp,
|
|
||||||
boolean rightJoyLeft, boolean rightJoyRight, boolean rightJoyDown,boolean rightJoyUp,boolean LT_pressed, boolean RT_pressed){
|
|
||||||
this.gamepadNum = gamepadNum;
|
this.gamepadNum = gamepadNum;
|
||||||
this.buttonA_pressed = buttonA_pressed;
|
this.gamepadAxes = null;
|
||||||
this.buttonB_pressed = buttonB_pressed;
|
this.gamepadButton = null;
|
||||||
this.buttonY_pressed = buttonY_pressed;
|
this.buttonA_pressed = false;
|
||||||
this.buttonX_pressed =buttonX_pressed;
|
this.buttonB_pressed = false;
|
||||||
this.LB_pressed =LB_pressed;
|
this.buttonY_pressed = false;
|
||||||
this.RB_pressed =RB_pressed;
|
this.buttonX_pressed = false;
|
||||||
this.select_pressed =select_pressed;
|
this.LB_pressed = false;
|
||||||
this.start_pressed =start_pressed;
|
this.RB_pressed = false;
|
||||||
this.R_JoyClick_pressed =R_JoyClick_pressed;
|
this.select_pressed = false;
|
||||||
this.L_JoyClick_pressed =L_JoyClick_pressed;
|
this.start_pressed = false;
|
||||||
this.up_pressed =up_pressed;
|
this.R_JoyClick_pressed = false;
|
||||||
this.down_pressed =down_pressed;
|
this.L_JoyClick_pressed = false;
|
||||||
this.left_pressed =left_pressed;
|
this.up_pressed = false;
|
||||||
this.right_pressed =right_pressed;
|
this.down_pressed = false;
|
||||||
this.leftJoyRight =leftJoyRight;
|
this.left_pressed = false;
|
||||||
this.leftJoyLeft =leftJoyLeft;
|
this.right_pressed = false;
|
||||||
this.leftJoyDown =leftJoyDown;
|
this.leftJoyRight = false;
|
||||||
this.leftJoyUp =leftJoyUp;
|
this.leftJoyLeft = false;
|
||||||
this.rightJoyLeft =rightJoyLeft;
|
this.leftJoyDown = false;
|
||||||
this.rightJoyRight =rightJoyRight;
|
this.leftJoyUp = false;
|
||||||
this.rightJoyDown =rightJoyDown;
|
this.rightJoyLeft = false;
|
||||||
this.rightJoyUp =rightJoyUp;
|
this.rightJoyRight = false;
|
||||||
this.LT_pressed =LT_pressed;
|
this.rightJoyDown = false;
|
||||||
this.RT_pressed =RT_pressed;
|
this.rightJoyUp = false;
|
||||||
|
this.LT_pressed = false;
|
||||||
|
this.RT_pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputRefresh() {
|
public void inputRefresh() {
|
||||||
ByteBuffer gamepadButton = glfwGetJoystickButtons(this.gamepadNum);
|
|
||||||
FloatBuffer gamepadAxes = glfwGetJoystickAxes(this.gamepadNum);
|
this.gamepadButton = glfwGetJoystickButtons(this.gamepadNum);
|
||||||
|
this.gamepadAxes = glfwGetJoystickAxes(this.gamepadNum);
|
||||||
|
|
||||||
assert gamepadAxes != null;
|
assert gamepadAxes != null;
|
||||||
assert gamepadButton != null;
|
assert gamepadButton != null;
|
||||||
@ -154,13 +158,55 @@ public class GamepadInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkPressed(int keyCode){
|
public boolean checkPressed(int keyCode){
|
||||||
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
|
this.gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
|
||||||
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
|
|
||||||
|
|
||||||
assert gamepadAxes != null;
|
|
||||||
assert gamepadButton != null;
|
assert gamepadButton != null;
|
||||||
|
|
||||||
return gamepadButton.get(keyCode) == 1;
|
return gamepadButton.get(keyCode) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Envoie la position du stick pointé par axisId sous forme de direction général (9 directions)
|
||||||
|
* @param axisId l'identifiant du joystick (AXE X)
|
||||||
|
* @return la direction du stick valeur possible : RIGHT, UPPER_RIGHT, UP, UPPER_LEFT, LEFT, LOWER_LEFT, DOWN, LOWER_RIGHT, CENTER;
|
||||||
|
*/
|
||||||
|
public int getAxisDiscreet(int axisId){
|
||||||
|
|
||||||
|
float x = gamepadAxes.get(axisId);
|
||||||
|
float y = gamepadAxes.get(axisId + 1);
|
||||||
|
|
||||||
|
float magnitude = (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
||||||
|
float angle = (float) Math.toDegrees(2 * Math.atan(y /(x + magnitude)));
|
||||||
|
|
||||||
|
if (magnitude < 0.1) return CENTER;
|
||||||
|
if (angle < 22.5 && angle > -22.5) return RIGHT;
|
||||||
|
else if (angle > -67.5 && angle < -22.5) return UPPER_RIGHT;
|
||||||
|
else if (angle > -112.5 && angle < -67.5) return UP;
|
||||||
|
else if (angle > -157.5 && angle < -112.5) return UPPER_LEFT;
|
||||||
|
else if (angle < -157.5 || angle > 157.5) return LEFT;
|
||||||
|
else if (angle < 157.5 && angle > 112.5) return LOWER_LEFT;
|
||||||
|
else if (angle < 112.5 && angle > 67.5) return DOWN;
|
||||||
|
else if (angle < 67.5 && angle > 22.5) return LOWER_RIGHT;
|
||||||
|
|
||||||
|
return -1; // TEST
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Envoie la position du stick pointé par axisID (AXE X) sous forme de Vecteur
|
||||||
|
* @param axisId l'identifiant du joystick (AXE X)
|
||||||
|
* @return un Vecteur représentant la position actuel du joystick
|
||||||
|
*/
|
||||||
|
public Vector3f getAxisContinuous(int axisId){
|
||||||
|
|
||||||
|
float x = gamepadAxes.get(axisId);
|
||||||
|
float y = gamepadAxes.get(axisId + 1);
|
||||||
|
|
||||||
|
if (x < 0.1 && x > -0.1) x = 0;
|
||||||
|
if (y < 0.1 && y > -0.1) y = 0;
|
||||||
|
|
||||||
|
System.out.println("x: " + x + " y: " + y);
|
||||||
|
|
||||||
|
return new Vector3f(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
17
src/engine/input/InputConst.java
Normal file
17
src/engine/input/InputConst.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package engine.input;
|
||||||
|
|
||||||
|
public class InputConst {
|
||||||
|
/*
|
||||||
|
Button ID
|
||||||
|
*/
|
||||||
|
public final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7,
|
||||||
|
L_JoystickClick = 8, R_JoystickClick =9, up = 10, right = 11, down = 12, left = 13;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Axis ID
|
||||||
|
*/
|
||||||
|
public final static int leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5;
|
||||||
|
|
||||||
|
public final static int RIGHT = 0, UPPER_RIGHT = 1, UP = 2, UPPER_LEFT = 3, LEFT = 4, LOWER_LEFT = 5,
|
||||||
|
DOWN = 6, LOWER_RIGHT = 7, CENTER = 8;
|
||||||
|
}
|
@ -12,7 +12,7 @@ import java.nio.FloatBuffer;
|
|||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
public class Input extends GLFWKeyCallback {
|
public class KeyboardInput extends GLFWKeyCallback {
|
||||||
|
|
||||||
public static boolean[] keys = new boolean[65536];
|
public static boolean[] keys = new boolean[65536];
|
||||||
|
|
||||||
@ -89,18 +89,18 @@ public class Input extends GLFWKeyCallback {
|
|||||||
|
|
||||||
public static void keyboardInput(ObjectGl token, int speed) {
|
public static void keyboardInput(ObjectGl token, int speed) {
|
||||||
boolean keyPressed = false;
|
boolean keyPressed = false;
|
||||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S)) {
|
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_S)) {
|
||||||
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
||||||
keyPressed = true;
|
keyPressed = true;
|
||||||
} else if (Input.isKeyDown(GLFW.GLFW_KEY_W)) {
|
} else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) {
|
||||||
keyPressed = true;
|
keyPressed = true;
|
||||||
}
|
}
|
||||||
if (Input.isKeyDown(GLFW.GLFW_KEY_A)) {
|
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) {
|
||||||
token.translate(new Vector3f (speed * -5.0f, 0.0f, 0.0f));
|
token.translate(new Vector3f (speed * -5.0f, 0.0f, 0.0f));
|
||||||
token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP);
|
token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP);
|
||||||
keyPressed = true;
|
keyPressed = true;
|
||||||
}
|
}
|
||||||
else if (Input.isKeyDown(GLFW.GLFW_KEY_D)) {
|
else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_D)) {
|
||||||
token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||||
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
|
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
|
||||||
keyPressed = true;
|
keyPressed = true;
|
@ -1,7 +0,0 @@
|
|||||||
package engine.input;
|
|
||||||
|
|
||||||
public class inputVariables {
|
|
||||||
public final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7,
|
|
||||||
L_JoystickClick = 8, R_JoystickClick =9, up = 10, right = 11, down = 12, left = 13,
|
|
||||||
leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5;
|
|
||||||
}
|
|
@ -10,6 +10,11 @@ public class Vector3f {
|
|||||||
z = 0.0f;
|
z = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3f(float x, float y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3f(float x, float y, float z){
|
public Vector3f(float x, float y, float z){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user