Merge remote-tracking branch 'origin/master'

This commit is contained in:
no 2021-06-24 11:44:44 +02:00
commit 5e7e0e2f89
2 changed files with 149 additions and 95 deletions

View File

@ -381,6 +381,7 @@ public class match {
case 21:
try {
handleThrows(p1, p2);
handleThrows(p2,p1);
} catch (IndexOutOfBoundsException e) {}
try {
handleHits(p1, p2, inputsP2);
@ -391,13 +392,13 @@ public class match {
//Update of the current frame of each character
case 22:
if(p1.getCurrentframe().islastFrameOfHit()) {
p1.removeFirstAttackPart();
}
if(p2.getCurrentframe().islastFrameOfHit()) {
p2.removeFirstAttackPart();
}
nextFrame(p1,inputsP1);
nextFrame(p2,inputsP2);
@ -405,6 +406,9 @@ public class match {
updatePos(p1,p1LooksRight);
updatePos(p2,!p1LooksRight);
pushBox();
cameraPushBack();
if(p1LooksRight) {
f = p1.getCurrentframe();
@ -584,7 +588,9 @@ public class match {
|| (!p1LooksRight && (atH.getPosX()+p1.getPosX()+ atH.getSize_x() < ptH.getPosX()+p2.getPosX()+ptH.getSize_x())
&& (atH.getPosX() > ptH.getPosX()));
boolean touchV = (atH.getPosY() - atH.getSize_y() < ptH.getPosY()) && (atH.getPosY() > ptH.getPosY() - ptH.getSize_y());
boolean touchV = (atH.getPosY()+p1.getPosY() - atH.getSize_y() < ptH.getPosY()+p2.getPosY()) && (atH.getPosY()+p1.getPosY() > ptH.getPosY()+p2.getPosY() - ptH.getSize_y());
if(touchH && touchV) {
hit.setHasHit(true);
tP.set(0,hit);
@ -616,7 +622,9 @@ public class match {
|| (!p1LooksRight && (aH.getPosX()+p1.getPosX()+ aH.getSize_x() < pH.getPosX()+p2.getPosX()+pH.getSize_x())
&& (aH.getPosX() > pH.getPosX()));
boolean touchV = (aH.getPosY() - aH.getSize_y() < pH.getPosY()) && (aH.getPosY() > pH.getPosY() - pH.getSize_y());
boolean touchV = (aH.getPosY()+p1.getPosY() - aH.getSize_y() < pH.getPosY()+p2.getPosY()) && (aH.getPosY()+p1.getPosY() > pH.getPosY()+p2.getPosY() - pH.getSize_y());
if(touchH && touchV) {
getHit(p2,hit,inputsP2.getLatestInputs());
hit.setHasHit(true);
@ -628,6 +636,7 @@ public class match {
}
}
/**
* Handles a character getting hit by an attack part.
* @param c the character that's getting hit
@ -731,6 +740,51 @@ public class match {
else {c.setPos((int)(c.getPosX()-c.getCurrentframe().getMove_x()),(int)(c.getPosY()+c.getCurrentframe().getMove_y()));}
}
private static void pushBox(){
Push_HitBox phb1 = p1.getCurrentframe().getPushHitBox();
Push_HitBox phb2 = p2.getCurrentframe().getPushHitBox();
// Check if there is an intersection only on the x axis, if we push on the y axis character could get stuck in the air
boolean lookRight = p1.getPosX() < p2.getPosX();
float sizeIntersection = lookRight ? p1.getPosX() + phb1.getPosX() + phb1.getSize_x() - p2.getPosX() - phb2.getPosX()
: p2.getPosX() + phb2.getPosX() + phb2.getSize_x() - p1.getPosX() - phb1.getPosX();
boolean col = 0 < sizeIntersection;
boolean colV = (phb1.getPosY() + p1.getPosY() - phb1.getSize_y() < phb2.getPosY() + p2.getPosY()) && (phb1.getPosY() + p1.getPosY() > phb2.getPosY() + p2.getPosY() - phb2.getSize_y());
if (col && colV){
if(lookRight){
p1.setPos((int) (p1.getPosX() - sizeIntersection/2), p1.getPosY());
p2.setPos((int) (p2.getPosX() + sizeIntersection/2), p2.getPosY());
} else {
p1.setPos((int) (p1.getPosX() + sizeIntersection/2), p1.getPosY());
p2.setPos((int) (p2.getPosX() - sizeIntersection/2), p2.getPosY());
}
}
}
/**
*
*/
private static void cameraPushBack(){
boolean lookRight = p1.getPosX() < p2.getPosX();
Character left;
Character right;
ObjectGl rightObj;
if (lookRight) {
left = p1;
right = p2;
rightObj = objP2;
} else {
left = p2;
right = p1;
rightObj = objP1;
}
float leftOutOfView = left.getPosX() - (-engine.getViewXPos() - engine.getCamera().getDimension());
float rightOutOfView = (right.getPosX() + rightObj.getWidth() * rightObj.getScalingFactor()) - (-engine.getViewXPos() + engine.getCamera().getDimension());
if(leftOutOfView < 0 && rightOutOfView > 0){
left.setPos((int) (left.getPosX() - leftOutOfView), left.getPosY());
right.setPos((int) (right.getPosX() - rightOutOfView), right.getPosY());
}
}
/*
HITBOX DEBUG METHOD
*/

View File

@ -5,105 +5,105 @@ import org.json.simple.*;
import org.json.simple.parser.*;
public class Config {
public int width, height, rounds;
public boolean fullscreen, hitboxes;
public String stage;
public String p1, p2;
public Config() throws FileNotFoundException {
parse();
}
public void parse() throws FileNotFoundException {
// initialize the parser
JSONParser jsonP = new JSONParser();
try {
// read the json document
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("game.set"));
public int width, height, rounds;
public boolean fullscreen, hitboxes;
public String stage;
public String p1, p2;
// to print all values
// System.out.println(jsonO.values());
public Config() throws FileNotFoundException {
parse();
}
// isolate the "test" part and print it
// String test = (String) jsonO.get("test");
// System.out.println("ceci est un test :" + test);
public void parse() throws FileNotFoundException {
JSONArray game = (JSONArray) jsonO.get("game");
JSONObject settings = (JSONObject) game.get(0);
// print a case of this element
stage = (String) settings.get("stage");
// initialize the parser
JSONParser jsonP = new JSONParser();
try {
// read the json document
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("game.set"));
// rounds
rounds = Integer.parseInt((String) settings.get("rounds"));
// character selection
p1 = (String) settings.get("character1");
p2 = (String) settings.get("character2");
// to print all values
// System.out.println(jsonO.values());
height = Integer.parseInt((String) settings.get("height")); // String to int
width = Integer.parseInt((String) settings.get("width"));
// fullscreen
String fs = (String) settings.get("fullscreen");
if (fs.equals("true")) {
fullscreen = true;
} else fullscreen = false;
String hb = (String) settings.get("hitboxes");
if (hb == null) hb = "false";
if (hb.equals("true")) {
hitboxes = true;
} else hitboxes = false;
// rounds
String temprounds = (String) settings.get("rounds");
switch (temprounds) {
case "1": rounds = 1;
case "3": rounds = 3;
case "5": rounds = 5;
default: rounds = 1;
}
// isolate the "test" part and print it
// String test = (String) jsonO.get("test");
// System.out.println("ceci est un test :" + test);
} catch (FileNotFoundException e) {
File f = new File("game.set");
try {
f.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.exit(1);
}
parse();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
System.out.println("Empty config file");
}
}
@SuppressWarnings("unchecked")
public void write(int width, int height, int rounds, boolean fullscreen, boolean hitboxes, String character1, String character2, String stage) throws Exception {
JSONObject metafile = new JSONObject();
JSONArray array = new JSONArray();
JSONObject set = new JSONObject();
set.put("width", Integer.toString(width));
set.put("height", Integer.toString(height));
set.put("rounds", Integer.toString(rounds));
set.put("fullscreen", Boolean.toString(fullscreen));
set.put("hitboxes", Boolean.toString(hitboxes));
set.put("character1", character1);
set.put("character2", character2);
set.put("stage", stage);
array.add(set);
metafile.put("game", array);
JSONArray game = (JSONArray) jsonO.get("game");
JSONObject settings = (JSONObject) game.get(0);
// print a case of this element
stage = (String) settings.get("stage");
// rounds
rounds = Integer.parseInt((String) settings.get("rounds"));
// character selection
p1 = (String) settings.get("character1");
p2 = (String) settings.get("character2");
height = Integer.parseInt((String) settings.get("height")); // String to int
width = Integer.parseInt((String) settings.get("width"));
// fullscreen
String fs = (String) settings.get("fullscreen");
if (fs.equals("true")) {
fullscreen = true;
} else fullscreen = false;
String hb = (String) settings.get("hitboxes");
if (hb == null) hb = "false";
if (hb.equals("true")) {
hitboxes = true;
} else hitboxes = false;
// rounds
String temprounds = (String) settings.get("rounds");
switch (temprounds) {
case "1": rounds = 1;
case "3": rounds = 3;
case "5": rounds = 5;
default: rounds = 1;
}
} catch (FileNotFoundException e) {
File f = new File("game.set");
try {
f.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.exit(1);
}
parse();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
System.out.println("Empty config file");
}
}
@SuppressWarnings("unchecked")
public void write(int width, int height, int rounds, boolean fullscreen, boolean hitboxes, String character1, String character2, String stage) throws Exception {
JSONObject metafile = new JSONObject();
JSONArray array = new JSONArray();
JSONObject set = new JSONObject();
set.put("width", Integer.toString(width));
set.put("height", Integer.toString(height));
set.put("rounds", Integer.toString(rounds));
set.put("fullscreen", Boolean.toString(fullscreen));
set.put("hitboxes", Boolean.toString(hitboxes));
set.put("character1", character1);
set.put("character2", character2);
set.put("stage", stage);
array.add(set);
metafile.put("game", array);
try (FileWriter file = new FileWriter("game.set", false)) {
file.write(metafile.toJSONString());
@ -114,5 +114,5 @@ public class Config {
} catch (IOException e) {
e.printStackTrace();
}
}
}
}