Write echoes all user settings to the game.set JSON File
+ * @param width the width of the game window
+ * @param height the height of the game window
+ * @param rounds the number of rounds to be played
+ * @param fullscreen whether or not to show the window fullscreen
+ * @param hitboxes whether or not to display the hitboxes
+ * @param character1 the name of the character chosen by player 1
+ * @param character2 the name of the character chosen by player 2
+ * @param stage the name of the stage
+ * @throws FileNotFoundException if the game.set file does not exist
+ * @throws IOException in case of IO error
+ * @throws Exception for any other unaccounted for exception
+ * @author François Autin
+ */
+ @SuppressWarnings("unchecked")
+ private 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());
+ file.close();
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns the current resolution setting
+ * @return a string of the (width)x(height) format
+ * @author François Autin
+ */
public String getResolution() {
- return "" + Integer.toString(config.width) + "x" + Integer.toString(config.height);
+ return "" + Integer.toString(width) + "x" + Integer.toString(height);
}
+ /**
+ * Returns the current fullscreen setting
+ * @return
A boolean:
true if fullscreen mode
false if windowed mode
+ * @author François Autin
+ */
public boolean getFullscreen() {
- return config.fullscreen;
+ return fullscreen;
}
+ /**
+ * Returns the current hitbox setting
+ * @return
A boolean:
true if hitboxes are to be showed
false if hitboxes are to be hidden
+ * @author François Autin
+ */
public boolean getHitboxes() {
- return config.hitboxes;
+ return hitboxes;
}
+ /**
+ * Returns the current rounds setting
+ * @return The number of rounds to be played
+ * @author François Autin
+ */
public String getRounds() {
- return Integer.toString(config.rounds);
+ return Integer.toString(rounds);
}
+ /**
+ * Returns the current fullscreen setting
+ * @return the name of the character chosen by player 1
+ * @author François Autin
+ */
public String getChar1() {
- return config.p1;
+ return p1;
}
+ /**
+ * Returns the current fullscreen setting
+ * @return the name of the character chosen by player 2
+ * @author François Autin
+ */
public String getChar2() {
- return config.p2;
+ return p2;
}
}
diff --git a/src/launcher/launcher.fxml b/src/launcher/launcher.fxml
index c8a3caa..4baa1c9 100644
--- a/src/launcher/launcher.fxml
+++ b/src/launcher/launcher.fxml
@@ -1,5 +1,10 @@
+
+
@@ -50,7 +55,7 @@
-
From a67cee242be263e370b4da1c990ae94a9dd0ee11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Autin?=
Date: Thu, 24 Jun 2021 02:31:55 +0200
Subject: [PATCH 2/7] Added 320x240 resolution option
---
src/launcher/Launcher.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/launcher/Launcher.java b/src/launcher/Launcher.java
index 1ea4779..a7b2dea 100644
--- a/src/launcher/Launcher.java
+++ b/src/launcher/Launcher.java
@@ -67,7 +67,7 @@ public class Launcher extends Application {
// Getting resolution ChoiceBox object from namespace
ChoiceBox cb = (ChoiceBox) namespace.get("resolution");
// Assigning list of possible choices to ChoiceBox
- ObservableList availableres = FXCollections.observableArrayList("640x480", "800x600", "1024x768", "1280x720", "1366x768", "1600x900", "1920x1080");
+ ObservableList availableres = FXCollections.observableArrayList("320x240", "640x480", "800x600", "1024x768", "1280x720", "1366x768", "1600x900", "1920x1080");
cb.setItems(availableres);
// Setting default ChoiceBox value to the one already in the config file
if (!availableres.contains(setter.getResolution())) {
@@ -183,6 +183,10 @@ public class Launcher extends Application {
int width, height;
ChoiceBox cb = (ChoiceBox) namespace.get("resolution");
switch (cb.getValue()) {
+ case "320x240":
+ width = 320;
+ height = 240;
+ break;
case "800x600":
width = 800;
height = 600;
From 1c208d9792b2c000795baa9fd56a69f6fb15b7d0 Mon Sep 17 00:00:00 2001
From: Antoine
Date: Thu, 24 Jun 2021 02:54:22 +0200
Subject: [PATCH 3/7] handleHits && handleThrows now take into account the y
position of the entity
---
src/gameplay/match/match.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java
index 819ca17..429df02 100644
--- a/src/gameplay/match/match.java
+++ b/src/gameplay/match/match.java
@@ -584,7 +584,7 @@ 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 = (p1.getPosY() - atH.getPosY() - atH.getSize_y() < p2.getPosY() - ptH.getPosY()) && (p1.getPosY() - atH.getPosY() > p2.getPosY() - ptH.getPosY() - ptH.getSize_y());
if(touchH && touchV) {
hit.setHasHit(true);
tP.set(0,hit);
@@ -616,7 +616,7 @@ 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 = (p1.getPosY() - aH.getPosY() - aH.getSize_y() < p2.getPosY() - pH.getPosY()) && (p1.getPosY() - aH.getPosY() > p2.getPosY() - pH.getPosY() - pH.getSize_y());
if(touchH && touchV) {
getHit(p2,hit,inputsP2.getLatestInputs());
hit.setHasHit(true);
From ad8a67b2744f192d2183e4ea2fc61b2148696c26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9o?=
Date: Thu, 24 Jun 2021 02:55:39 +0200
Subject: [PATCH 4/7] hitboxes fixed
---
src/gameplay/match/match.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java
index 819ca17..d74d1db 100644
--- a/src/gameplay/match/match.java
+++ b/src/gameplay/match/match.java
@@ -381,6 +381,7 @@ public class match {
case 21:
try {
handleThrows(p1, p2);
+ handleThrows(p2,p1);
} catch (IndexOutOfBoundsException e) {}
try {
handleHits(p1, p2, inputsP2);
@@ -584,7 +585,7 @@ 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 +617,7 @@ 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);
From af9624eeecd786539192cc0a4acca4ca1b337aee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Autin?=
Date: Thu, 24 Jun 2021 01:25:09 +0000
Subject: [PATCH 5/7] Delete Config.java
---
src/launcher/Config.java | 118 ---------------------------------------
1 file changed, 118 deletions(-)
delete mode 100644 src/launcher/Config.java
diff --git a/src/launcher/Config.java b/src/launcher/Config.java
deleted file mode 100644
index c1f4517..0000000
--- a/src/launcher/Config.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package launcher;
-
-import java.io.*;
-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"));
-
- // 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);
-
-
- 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());
- file.close();
-
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
From 7f2a4800c61a4f3ee5eb214753119bd85a060cb3 Mon Sep 17 00:00:00 2001
From: Antoine
Date: Thu, 24 Jun 2021 03:31:54 +0200
Subject: [PATCH 6/7] =?UTF-8?q?Premi=C3=A8re=20impl=C3=A9mentation=20des?=
=?UTF-8?q?=20pushBox?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/gameplay/match/match.java | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java
index 0ad69d9..ab524fe 100644
--- a/src/gameplay/match/match.java
+++ b/src/gameplay/match/match.java
@@ -392,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);
@@ -406,6 +406,8 @@ public class match {
updatePos(p1,p1LooksRight);
updatePos(p2,!p1LooksRight);
+ pushBox();
+
if(p1LooksRight) {
f = p1.getCurrentframe();
@@ -633,6 +635,7 @@ public class match {
}
}
+
/**
* Handles a character getting hit by an attack part.
* @param c the character that's getting hit
@@ -736,6 +739,27 @@ 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());
+ }
+ }
+
+ }
+
/*
HITBOX DEBUG METHOD
*/
From 76f96a2bada13d75db3661b9db62b34def714808 Mon Sep 17 00:00:00 2001
From: Antoine
Date: Thu, 24 Jun 2021 03:55:43 +0200
Subject: [PATCH 7/7] =?UTF-8?q?Premi=C3=A8re=20impl=C3=A9mentation=20du=20?=
=?UTF-8?q?cameraPushBack?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/gameplay/match/match.java | 25 +++++++
src/launcher/Config.java | 118 ++++++++++++++++++++++++++++++++++
2 files changed, 143 insertions(+)
create mode 100644 src/launcher/Config.java
diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java
index ab524fe..cd4a951 100644
--- a/src/gameplay/match/match.java
+++ b/src/gameplay/match/match.java
@@ -407,6 +407,7 @@ public class match {
updatePos(p2,!p1LooksRight);
pushBox();
+ cameraPushBack();
if(p1LooksRight) {
@@ -757,7 +758,31 @@ public class match {
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());
+ }
}
/*
diff --git a/src/launcher/Config.java b/src/launcher/Config.java
new file mode 100644
index 0000000..9d95420
--- /dev/null
+++ b/src/launcher/Config.java
@@ -0,0 +1,118 @@
+package launcher;
+
+import java.io.*;
+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"));
+
+ // 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);
+
+
+ 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());
+ file.close();
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}