From 2fd3dc61d9961864f83743a2792e3e9712f4c957 Mon Sep 17 00:00:00 2001 From: no Date: Tue, 1 Jun 2021 21:02:11 +0200 Subject: [PATCH 1/3] change dsome things inmatch, added the start of amain function. --- .gitignore | 1 + src/gameplay/actions/Attack.java | 6 +- src/gameplay/actions/attackPart.java | 114 +++++++++++++++++++++++++++ src/gameplay/match/match.java | 14 ++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/gameplay/actions/attackPart.java diff --git a/.gitignore b/.gitignore index a5cac0f..049b9a7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /bin/ /.idea/ /.project +/jeu-de-combat.iml diff --git a/src/gameplay/actions/Attack.java b/src/gameplay/actions/Attack.java index 48e9fe5..ba72498 100644 --- a/src/gameplay/actions/Attack.java +++ b/src/gameplay/actions/Attack.java @@ -14,5 +14,9 @@ public class Attack { * {{DOWN},{DOWN,RIGHT},{RIGHT},{A}} */ private static Button[][] command; - + + /** + * The different sections of the attack + */ + private attackPart[] parts; } diff --git a/src/gameplay/actions/attackPart.java b/src/gameplay/actions/attackPart.java new file mode 100644 index 0000000..9310f6f --- /dev/null +++ b/src/gameplay/actions/attackPart.java @@ -0,0 +1,114 @@ +package gameplay.actions; + +import gameplay.frames.Frame; + +/** + * This class represent one section (generally one isolated hit) of an attack. + */ +public class attackPart { + private int damage, chipDamage, hitstun, blockstun; + private double knockbackOnHit, knockbackOnBlock; + private Frame[] frames; + private boolean hasHit; + + /** + * Constructor with most parameters for an attack part, generally a hit + * @param damage the damage dealt to the enemy if the attack part connects + * @param chipDamage the damage dealt to the enemy if the attack part is blocked + * @param hitstun the amount of frames where the enemy is in hitstun if the attack part connects + * @param blockstun the amount of frames where the enemy is in blockstun if the attack part is blocked + * @param knockbackOnHit the distance the enemy gets moved back if hit + * @param knockbackOnBlock the distance the enemy gets moved back if blocked + * @param frames the array of frames for the part + */ + public attackPart(int damage, int chipDamage, int hitstun, int blockstun, double knockbackOnHit, double knockbackOnBlock, Frame[] frames) { + this.damage = damage; + this.chipDamage = chipDamage; + this.hitstun = hitstun; + this.blockstun = blockstun; + this.knockbackOnHit = knockbackOnHit; + this.knockbackOnHit = knockbackOnBlock; + this.frames = frames; + this.hasHit = false; + } + + /** + * Constructor for an attack part with only a frames array as parameter. + * Generally for a move startup or recovery. + * @param frames the array of frames for the part + */ + public attackPart(Frame[] frames) { + this.frames = frames; + this.damage = 0; + this.chipDamage = 0; + this.hitstun = 0; + this.blockstun = 0; + this.knockbackOnHit = 0.0; + this.knockbackOnBlock = 0.0; + this.hasHit = false; + } + + public boolean hasHit() { + return hasHit; + } + + public void setHasHit(boolean hasHit) { + this.hasHit = hasHit; + } + + public int getDamage() { + return this.damage; + } + + public void setDamage(int damage) { + this.damage = damage; + } + + public int getChipDamage() { + return this.chipDamage; + } + + public void setChipDamage(int chipDamage) { + this.chipDamage = chipDamage; + } + + public int getHitstun() { + return hitstun; + } + + public void setHitstun(int hitstun) { + this.hitstun = hitstun; + } + + public int getBlockstun() { + return blockstun; + } + + public void setBlockstun(int blockstun) { + this.blockstun = blockstun; + } + + public double getKnockbackOnHit() { + return knockbackOnHit; + } + + public void setKnockbackOnHit(double knockback) { + this.knockbackOnHit = knockback; + } + + public Frame[] getFrames() { + return frames; + } + + public void setFrames(Frame[] frames) { + this.frames = frames; + } + + public double getKnockbackOnBlock() { + return knockbackOnBlock; + } + + public void setKnockbackOnBlock(double knockbackOnBlock) { + this.knockbackOnBlock = knockbackOnBlock; + } +} diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 6f54f84..513bf2a 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -3,6 +3,7 @@ package gameplay.match; import gameplay.input.InputBuffer; import gameplay.entities.*; import gameplay.entities.Character; +import engine.Engine; /** * Main class that describes the base structure of the match, with characters, timer and such @@ -37,6 +38,19 @@ public class match { this.roundsWonP1 = 0; this.roundsWonP2 = 0; } + + + /** + * Main function of a match. Contains the main gameplay loop. + * @param args arguments + */ + public static void main(String args[]) { + Character p1 = new Character(); //TODO : change to not a blank + Character p2 = new Character(); //TODO : same as above + match match = new match(p1,p2); + + + } } From 37caf34e79926140e4b1d2ac2d31608e3036d262 Mon Sep 17 00:00:00 2001 From: Azra Victor Date: Thu, 3 Jun 2021 03:03:25 +0200 Subject: [PATCH 2/3] 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; } } } From 9200ae0415e594eee186c637492c70a88468571b Mon Sep 17 00:00:00 2001 From: Boyeau Indy Date: Thu, 3 Jun 2021 08:22:32 +0000 Subject: [PATCH 3/3] Update JsonToJava.java --- src/configuration/JsonToJava.java | 59 +++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/src/configuration/JsonToJava.java b/src/configuration/JsonToJava.java index f0d0d8f..94478bc 100644 --- a/src/configuration/JsonToJava.java +++ b/src/configuration/JsonToJava.java @@ -8,39 +8,60 @@ public class JsonToJava { public static void main(String args[]) { + JsonRecover(); + + } + + private static void JsonRecover() { // initialize the parser JSONParser jsonP = new JSONParser(); try { // read the json document JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("src/configuration/config.json")); - - //to print all values - //System.out.println(jsonO.values()); + + // to print all values + // System.out.println(jsonO.values()); // isolate the "test" part and print it // String test = (String) jsonO.get("test"); // System.out.println("ceci est un test :" + test); - - //select an element on the list - JSONArray arene = (JSONArray) jsonO.get("arena"); - //print a case of this element - System.out.println(arene.get(1)); - - JSONArray nb_players = (JSONArray) jsonO.get("nb_players"); - System.out.println(nb_players.get(1)); + // arena selection + // select an element on the list + JSONArray arena = (JSONArray) jsonO.get("arena"); + // print a case of this element + System.out.println("arena : " + arena.get(1)); + // nb players selection + JSONArray nb_players = (JSONArray) jsonO.get("nb_players"); + System.out.println("nb_player : " + nb_players.get(1)); + + // character selection JSONArray character1 = (JSONArray) jsonO.get("character1"); - System.out.println(character1.get(1)); - + System.out.println("players 1 : " + character1.get(1)); + JSONArray character2 = (JSONArray) jsonO.get("character2"); - System.out.println(character2.get(1)); - + System.out.println("players 2 : " + character2.get(1)); + + // resolution JSONArray resolution = (JSONArray) jsonO.get("resolution"); - System.out.println(resolution.get(1)); - - JSONArray button = (JSONArray) jsonO.get("button"); - System.out.println(button); + // resolution string " width x heigth" + JSONObject reso = (JSONObject) resolution.get(1); + + String heightStr = (String) reso.get("height"); + int height = Integer.parseInt(heightStr); // String to int + + String widthStr = (String) reso.get("width"); + int width = Integer.parseInt(widthStr); + + System.out.println("heigth : " + height + " width : " + width); + + // button selection + JSONArray allButton = (JSONArray) jsonO.get("button"); + System.out.println(allButton); + + String up = (String) allButton.get(0); + System.out.println("button for up is : " + up); } catch (FileNotFoundException e) { e.printStackTrace();