140 lines
3.6 KiB
Java
Raw Normal View History

package gameplay.match;
2021-06-02 15:37:41 +02:00
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.entities.*;
import gameplay.entities.Character;
2021-06-02 15:37:41 +02:00
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
* @author Victor Azra
*
*/
public class match {
/**
* the number of inputs read for each character, a.k.a. for how many frames the inputs are saved in memory.
*/
private static final int inputBufferSize = 120;
private int timer;
private InputBuffer inputsP1, inputsP2;
private int hpP1, hpP2;
private int roundsWonP1, roundsWonP2;
private Character p1, p2; //characters of player 1 and 2
2021-05-27 00:54:28 +02:00
/**
2021-05-27 01:17:41 +02:00
* base constructor of the match class.
* Initiates a new match with with two given characters
2021-05-27 00:54:28 +02:00
*/
public match(Character p1, Character p2) {
this.timer = 99;
this.inputsP1 = new InputBuffer(inputBufferSize);
this.inputsP2 = new InputBuffer(inputBufferSize);
2021-05-27 01:17:41 +02:00
this.p1 = p1;
this.p2 = p2;
this.hpP1 = p1.getMaxHP();
this.hpP2 = p2.getMaxHP();
this.roundsWonP1 = 0;
this.roundsWonP2 = 0;
}
2021-06-02 15:37:41 +02:00
public static void main(String[] args) throws Exception {
/*
2021-06-02 15:37:41 +02:00
Engine engine = new Engine(800, 600, 3.0f / 4.0f);
engine.init();
2021-06-02 15:37:41 +02:00
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
2021-06-02 15:37:41 +02:00
if (Joystick1Present) {
gamepad1.inputRefresh();
2021-06-02 15:37:41 +02:00
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);
} */
long framestart = System.currentTimeMillis();
long frameend = System.currentTimeMillis();
int frame = 0;
boolean goToNextFrame = true;
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
GamepadInput gamepad1 = null;
match match = new match(new Character(),new Character());
if (Joystick1Present) {
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
}
while(goToNextFrame) {
framestart = System.currentTimeMillis();
frame++;
gamepad1.inputRefresh();
match.inputsP1.recordInputsFromGamepad(gamepad1);
System.out.println("Frame " + frame + " " + match.inputsP1.getLatestInputs().toString());
frameend = System.currentTimeMillis();
while(frameend-framestart < (1000/60)) {
frameend = System.currentTimeMillis();
}
2021-06-02 15:37:41 +02:00
}
}
}