Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5e7e0e2f89
@ -381,6 +381,7 @@ public class match {
|
|||||||
case 21:
|
case 21:
|
||||||
try {
|
try {
|
||||||
handleThrows(p1, p2);
|
handleThrows(p1, p2);
|
||||||
|
handleThrows(p2,p1);
|
||||||
} catch (IndexOutOfBoundsException e) {}
|
} catch (IndexOutOfBoundsException e) {}
|
||||||
try {
|
try {
|
||||||
handleHits(p1, p2, inputsP2);
|
handleHits(p1, p2, inputsP2);
|
||||||
@ -391,13 +392,13 @@ public class match {
|
|||||||
|
|
||||||
//Update of the current frame of each character
|
//Update of the current frame of each character
|
||||||
case 22:
|
case 22:
|
||||||
|
|
||||||
if(p1.getCurrentframe().islastFrameOfHit()) {
|
if(p1.getCurrentframe().islastFrameOfHit()) {
|
||||||
p1.removeFirstAttackPart();
|
p1.removeFirstAttackPart();
|
||||||
}
|
}
|
||||||
if(p2.getCurrentframe().islastFrameOfHit()) {
|
if(p2.getCurrentframe().islastFrameOfHit()) {
|
||||||
p2.removeFirstAttackPart();
|
p2.removeFirstAttackPart();
|
||||||
}
|
}
|
||||||
|
|
||||||
nextFrame(p1,inputsP1);
|
nextFrame(p1,inputsP1);
|
||||||
nextFrame(p2,inputsP2);
|
nextFrame(p2,inputsP2);
|
||||||
|
|
||||||
@ -405,6 +406,9 @@ public class match {
|
|||||||
updatePos(p1,p1LooksRight);
|
updatePos(p1,p1LooksRight);
|
||||||
updatePos(p2,!p1LooksRight);
|
updatePos(p2,!p1LooksRight);
|
||||||
|
|
||||||
|
pushBox();
|
||||||
|
cameraPushBack();
|
||||||
|
|
||||||
if(p1LooksRight) {
|
if(p1LooksRight) {
|
||||||
|
|
||||||
f = p1.getCurrentframe();
|
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())
|
|| (!p1LooksRight && (atH.getPosX()+p1.getPosX()+ atH.getSize_x() < ptH.getPosX()+p2.getPosX()+ptH.getSize_x())
|
||||||
&& (atH.getPosX() > ptH.getPosX()));
|
&& (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) {
|
if(touchH && touchV) {
|
||||||
hit.setHasHit(true);
|
hit.setHasHit(true);
|
||||||
tP.set(0,hit);
|
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())
|
|| (!p1LooksRight && (aH.getPosX()+p1.getPosX()+ aH.getSize_x() < pH.getPosX()+p2.getPosX()+pH.getSize_x())
|
||||||
&& (aH.getPosX() > pH.getPosX()));
|
&& (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) {
|
if(touchH && touchV) {
|
||||||
getHit(p2,hit,inputsP2.getLatestInputs());
|
getHit(p2,hit,inputsP2.getLatestInputs());
|
||||||
hit.setHasHit(true);
|
hit.setHasHit(true);
|
||||||
@ -628,6 +636,7 @@ public class match {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a character getting hit by an attack part.
|
* Handles a character getting hit by an attack part.
|
||||||
* @param c the character that's getting hit
|
* @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()));}
|
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
|
HITBOX DEBUG METHOD
|
||||||
*/
|
*/
|
||||||
|
@ -5,105 +5,105 @@ import org.json.simple.*;
|
|||||||
import org.json.simple.parser.*;
|
import org.json.simple.parser.*;
|
||||||
|
|
||||||
public class Config {
|
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 {
|
public int width, height, rounds;
|
||||||
|
public boolean fullscreen, hitboxes;
|
||||||
// initialize the parser
|
public String stage;
|
||||||
JSONParser jsonP = new JSONParser();
|
public String p1, p2;
|
||||||
try {
|
|
||||||
// read the json document
|
|
||||||
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("game.set"));
|
|
||||||
|
|
||||||
// to print all values
|
public Config() throws FileNotFoundException {
|
||||||
// System.out.println(jsonO.values());
|
parse();
|
||||||
|
}
|
||||||
|
|
||||||
// isolate the "test" part and print it
|
public void parse() throws FileNotFoundException {
|
||||||
// String test = (String) jsonO.get("test");
|
|
||||||
// System.out.println("ceci est un test :" + test);
|
|
||||||
|
|
||||||
|
// initialize the parser
|
||||||
JSONArray game = (JSONArray) jsonO.get("game");
|
JSONParser jsonP = new JSONParser();
|
||||||
JSONObject settings = (JSONObject) game.get(0);
|
try {
|
||||||
|
// read the json document
|
||||||
// print a case of this element
|
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("game.set"));
|
||||||
stage = (String) settings.get("stage");
|
|
||||||
|
|
||||||
// rounds
|
// to print all values
|
||||||
rounds = Integer.parseInt((String) settings.get("rounds"));
|
// System.out.println(jsonO.values());
|
||||||
|
|
||||||
// character selection
|
|
||||||
p1 = (String) settings.get("character1");
|
|
||||||
p2 = (String) settings.get("character2");
|
|
||||||
|
|
||||||
height = Integer.parseInt((String) settings.get("height")); // String to int
|
// isolate the "test" part and print it
|
||||||
width = Integer.parseInt((String) settings.get("width"));
|
// String test = (String) jsonO.get("test");
|
||||||
|
// System.out.println("ceci est un test :" + test);
|
||||||
// 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 game = (JSONArray) jsonO.get("game");
|
||||||
JSONArray array = new JSONArray();
|
JSONObject settings = (JSONObject) game.get(0);
|
||||||
|
|
||||||
JSONObject set = new JSONObject();
|
// print a case of this element
|
||||||
set.put("width", Integer.toString(width));
|
stage = (String) settings.get("stage");
|
||||||
set.put("height", Integer.toString(height));
|
|
||||||
set.put("rounds", Integer.toString(rounds));
|
// rounds
|
||||||
set.put("fullscreen", Boolean.toString(fullscreen));
|
rounds = Integer.parseInt((String) settings.get("rounds"));
|
||||||
set.put("hitboxes", Boolean.toString(hitboxes));
|
|
||||||
set.put("character1", character1);
|
// character selection
|
||||||
set.put("character2", character2);
|
p1 = (String) settings.get("character1");
|
||||||
set.put("stage", stage);
|
p2 = (String) settings.get("character2");
|
||||||
|
|
||||||
array.add(set);
|
height = Integer.parseInt((String) settings.get("height")); // String to int
|
||||||
|
width = Integer.parseInt((String) settings.get("width"));
|
||||||
metafile.put("game", array);
|
|
||||||
|
// 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)) {
|
try (FileWriter file = new FileWriter("game.set", false)) {
|
||||||
file.write(metafile.toJSONString());
|
file.write(metafile.toJSONString());
|
||||||
@ -114,5 +114,5 @@ public class Config {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user