From 37caf34e79926140e4b1d2ac2d31608e3036d262 Mon Sep 17 00:00:00 2001 From: Azra Victor Date: Thu, 3 Jun 2021 03:03:25 +0200 Subject: [PATCH] Implementation of gameplay loop, testing of afew things in match class. --- .gitignore | 1 + pom.xml | 2 +- src/gameplay/entities/Character.java | 2 +- src/gameplay/match/match.java | 89 +++++++++++++++++++++++----- 4 files changed, 78 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 049b9a7..c9fadc0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.idea/ /.project /jeu-de-combat.iml +/pom.xml diff --git a/pom.xml b/pom.xml index 5593d30..6a80a64 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 3.2.3 - natives-windows + natives-linux 11 diff --git a/src/gameplay/entities/Character.java b/src/gameplay/entities/Character.java index 8a6d52e..ed069f6 100644 --- a/src/gameplay/entities/Character.java +++ b/src/gameplay/entities/Character.java @@ -27,5 +27,5 @@ public class Character extends Entity { this.maxHP = HP; } - public int getMaxHP() { return this.getMaxHP();} + public int getMaxHP() { return this.maxHP;} } diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 10d2df8..28b7a34 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -31,6 +31,10 @@ public class match { private int hpP1, hpP2; private int roundsWonP1, roundsWonP2; private Character p1, p2; //characters of player 1 and 2 + + private static long timeStamp1; + private static long timeStamp2; + private static int frameCount; /** * base constructor of the match class. @@ -48,6 +52,37 @@ public class match { this.roundsWonP2 = 0; } + /** + * Starts a new round, by placing the timer back at base value, characters back at full hp and such. + */ + private void startNewRound() { + this.timer = 99; + this.inputsP1 = new InputBuffer(inputBufferSize); + this.inputsP2 = new InputBuffer(inputBufferSize); + this.hpP1 = p1.getMaxHP(); + this.hpP2 = p2.getMaxHP(); + this.p1.setPos(-500, 250); //TODO : change to better values if needed + this.p2.setPos(500, 250); //TODO : change to better values if needed + } + + /** + * Ends the round. + * Used for playing animations and such. + * TODO : Implement this once we know what to do. + */ + private void endRound() { + + } + + /** + * Ends the match. + * Used for playing animations and such. + * TODO : Implement this once we know what to do. + */ + private void endMatch() { + + } + public static void main(String[] args) throws Exception { /* Engine engine = new Engine(800, 600, 3.0f / 4.0f); @@ -110,30 +145,56 @@ public class match { 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()); - + match match = new match(new Character(),new Character()); //TOD0 : Change to not empty chars 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(); - } + } + + private void ac(int i) { + switch (i) { + + //initiate a round + case 0 : + startNewRound(); + timeStamp1 = System.currentTimeMillis(); + frameCount = 0; + ac(10); + break; + + //checks if one or both of the chars are out of health + case 10: + if(this.hpP1 <= 0 && hpP2 <= 0) { ac(11);} + else if(this.hpP1 <= 0) { ac(12);} + else if(this.hpP2 <= 0) { ac(13);} + else { ac(20);} + break; + + //end round + case 11: + endRound(); + if(roundsWonP1 >= 2||roundsWonP2 >= 2) { endMatch();} //TODO : will probably need to specify more + else{ac(0);} + break; + + //if p1 is at 0 health + case 12: + roundsWonP2++; + ac(11); + break; + + //if p2 is at 0 health + case 13: + roundsWonP2++; + ac(11); + break; } } }