Implémentation minimal match.java
This commit is contained in:
parent
bce2220453
commit
fbf65f3a6f
@ -178,7 +178,7 @@ public class GamepadInput {
|
|||||||
float magnitude = (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
float magnitude = (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
||||||
float angle = (float) Math.toDegrees(2 * Math.atan(y /(x + magnitude)));
|
float angle = (float) Math.toDegrees(2 * Math.atan(y /(x + magnitude)));
|
||||||
|
|
||||||
if (magnitude < 0.1) return CENTER;
|
if (magnitude < 0.3) return CENTER;
|
||||||
if (angle < 22.5 && angle > -22.5) return RIGHT;
|
if (angle < 22.5 && angle > -22.5) return RIGHT;
|
||||||
else if (angle > -67.5 && angle < -22.5) return UPPER_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 > -112.5 && angle < -67.5) return UP;
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
package gameplay.match;
|
package gameplay.match;
|
||||||
|
|
||||||
|
import engine.Engine;
|
||||||
|
import engine.input.Button;
|
||||||
|
import engine.input.GamepadInput;
|
||||||
|
import engine.input.InputConst;
|
||||||
|
import engine.object.ObjectGl;
|
||||||
import gameplay.input.InputBuffer;
|
import gameplay.input.InputBuffer;
|
||||||
import gameplay.entities.*;
|
import gameplay.entities.*;
|
||||||
import gameplay.entities.Character;
|
import gameplay.entities.Character;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class that describes the base structure of the match, with characters, timer and such
|
* Main class that describes the base structure of the match, with characters, timer and such
|
||||||
* @author Victor Azra
|
* @author Victor Azra
|
||||||
@ -37,6 +47,68 @@ public class match {
|
|||||||
this.roundsWonP1 = 0;
|
this.roundsWonP1 = 0;
|
||||||
this.roundsWonP2 = 0;
|
this.roundsWonP2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
|
Engine engine = new Engine(800, 600, 3.0f / 4.0f);
|
||||||
|
engine.init();
|
||||||
|
|
||||||
|
String path = "textures/zangief_sprite.png";
|
||||||
|
|
||||||
|
ObjectGl zangief = new ObjectGl(0f, 60f, 80f, 10f, path, null);
|
||||||
|
zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.STICK_TOP);
|
||||||
|
engine.add_objectGl(zangief);
|
||||||
|
|
||||||
|
long timer = System.currentTimeMillis();
|
||||||
|
long lastFrame;
|
||||||
|
int frame = 0;
|
||||||
|
boolean nextFrame = false;
|
||||||
|
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (engine.isRunning()) {
|
||||||
|
lastFrame = System.currentTimeMillis();
|
||||||
|
// Game logic should fit here
|
||||||
|
|
||||||
|
if (Joystick1Present) {
|
||||||
|
gamepad1.inputRefresh();
|
||||||
|
|
||||||
|
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 ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.update();
|
||||||
|
engine.render();
|
||||||
|
|
||||||
|
frame++;
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - timer > 1000) {
|
||||||
|
timer += 1000;
|
||||||
|
System.out.println("FPS: " + frame);
|
||||||
|
frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!nextFrame) {
|
||||||
|
nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextFrame = false;
|
||||||
|
if (engine.shouldClose()) engine.setRunning(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user