diff --git a/.gitignore b/.gitignore index e4ed897..1f01948 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,9 @@ /bin/ /.idea/ /.project -/.classpath \ No newline at end of file +<<<<<<< HEAD +/.classpath +======= +/jeu-de-combat.iml +/pom.xml +>>>>>>> branch 'master' of https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat.git 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/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(); 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/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/input/Button.java b/src/gameplay/input/Button.java index 6ef406f..709b5dc 100644 --- a/src/gameplay/input/Button.java +++ b/src/gameplay/input/Button.java @@ -16,4 +16,28 @@ public enum Button { default : return -1; } } + + public String toString() { + switch (this) { + case UP : return "UP"; + case DOWN : return "DOWN"; + case LEFT : return "LEFT"; + case RIGHT : return "RIGHT"; + case A : return "A"; + case B : return "B"; + case C : return "C"; + case D : return "D"; + default : return "???"; + } + } + + public static Button intToButton(int i) { + Button[] b = {UP, DOWN, LEFT, RIGHT, A, B, C, D}; + try { + return b[i]; + } catch (ArrayIndexOutOfBoundsException e) { + //TODO: put error message here + return null; + } + } } diff --git a/src/gameplay/input/InputBuffer.java b/src/gameplay/input/InputBuffer.java index 778e6bf..fd9e877 100644 --- a/src/gameplay/input/InputBuffer.java +++ b/src/gameplay/input/InputBuffer.java @@ -1,5 +1,7 @@ package gameplay.input; +import engine.input.GamepadInput; + public class InputBuffer { /** @@ -72,9 +74,19 @@ public class InputBuffer { * record a new input in the * @param inputs a size 8 tab of inputs */ - private void recordInputs(Inputs inputs) { + public void recordInputs(Inputs inputs) { this.nextPos(); this.setLatestInputs(inputs); } + + /** + * records the new Inputs from a gamepad in the gamepad buffer + * @param pad the gamepad to record + */ + public void recordInputsFromGamepad(GamepadInput pad) { + Inputs in = new Inputs(); + in.recordFromGamepad(pad); + this.recordInputs(in); + } } diff --git a/src/gameplay/input/Inputs.java b/src/gameplay/input/Inputs.java index 2248c21..3ca6724 100644 --- a/src/gameplay/input/Inputs.java +++ b/src/gameplay/input/Inputs.java @@ -1,5 +1,8 @@ package gameplay.input; +import engine.input.GamepadInput; +import engine.input.InputConst; + /** * The class handling the parsing of one input. * @author Victor @@ -18,7 +21,7 @@ public class Inputs { /** * record one input - * @param i the integer value corresponding to the tab location + * @param b the input to be recorded */ public void recordOneInput(Button b) { int i = b.toInt(); @@ -27,7 +30,7 @@ public class Inputs { /** * Check if a specific input (for example UP) has been recorded - * @param i the integer value corresponding to the input + * @param b the button to be checked * @return */ public boolean containsInput(Button b) { @@ -61,6 +64,24 @@ public class Inputs { public boolean[] getInputs() { return this.tab; } - + + public void recordFromGamepad(GamepadInput pad) { + this.tab[Button.UP.toInt()] = pad.checkPressed(InputConst.up); + this.tab[Button.DOWN.toInt()] = pad.checkPressed(InputConst.down); + this.tab[Button.LEFT.toInt()] = pad.checkPressed(InputConst.left); + this.tab[Button.RIGHT.toInt()] = pad.checkPressed(InputConst.right); + this.tab[Button.A.toInt()] = pad.checkPressed(InputConst.buttonX); + this.tab[Button.B.toInt()] = pad.checkPressed(InputConst.buttonA); + this.tab[Button.C.toInt()] = pad.checkPressed(InputConst.buttonY); + this.tab[Button.D.toInt()] = pad.checkPressed(InputConst.buttonB); + } + + public String toString() { + String s = ""; + for(int i = 0; i < numberOfInputs; i++) { + if(this.tab[i]) {s = s + Button.intToButton(i).toString() + " "; } + } + return s; + } } diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index f5c069a..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,8 +52,39 @@ public class match { this.roundsWonP2 = 0; } - public static void main(String[] args) throws Exception { + /** + * 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); engine.init(); @@ -109,6 +144,57 @@ public class match { nextFrame = false; if (engine.shouldClose()) engine.setRunning(false); + } */ + int frame = 0; + boolean goToNextFrame = true; + boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1); + GamepadInput gamepad1 = null; + match match = new match(new Character(),new Character()); //TOD0 : Change to not empty chars + + if (Joystick1Present) { + gamepad1 = new GamepadInput(GLFW_JOYSTICK_1); + gamepad1.inputRefresh(); + } + + } + + 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; } } }