Merge branch 'master' of

https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat.git

Conflicts:
	.gitignore
This commit is contained in:
François Autin 2021-06-03 14:58:37 +02:00
commit f129ed523b
No known key found for this signature in database
GPG Key ID: 24025429AC559B7C
10 changed files with 315 additions and 28 deletions

5
.gitignore vendored
View File

@ -3,4 +3,9 @@
/bin/
/.idea/
/.project
<<<<<<< HEAD
/.classpath
=======
/jeu-de-combat.iml
/pom.xml
>>>>>>> branch 'master' of https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat.git

View File

@ -34,7 +34,7 @@
<properties>
<lwjgl.version>3.2.3</lwjgl.version>
<lwjgl.natives>natives-windows</lwjgl.natives>
<lwjgl.natives>natives-linux</lwjgl.natives>
<javafx.version>11</javafx.version>
</properties>

View File

@ -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);
// 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));
//select an element on the list
JSONArray arene = (JSONArray) jsonO.get("arena");
//print a case of this element
System.out.println(arene.get(1));
// nb players selection
JSONArray nb_players = (JSONArray) jsonO.get("nb_players");
System.out.println(nb_players.get(1));
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));
// resolution string " width x heigth"
JSONObject reso = (JSONObject) resolution.get(1);
JSONArray button = (JSONArray) jsonO.get("button");
System.out.println(button);
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();

View File

@ -15,4 +15,8 @@ public class Attack {
*/
private static Button[][] command;
/**
* The different sections of the attack
*/
private attackPart[] parts;
}

View File

@ -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;
}
}

View File

@ -27,5 +27,5 @@ public class Character extends Entity {
this.maxHP = HP;
}
public int getMaxHP() { return this.getMaxHP();}
public int getMaxHP() { return this.maxHP;}
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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) {
@ -62,5 +65,23 @@ public class Inputs {
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;
}
}

View File

@ -32,6 +32,10 @@ public class match {
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.
* Initiates a new match with with two given characters
@ -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;
}
}
}