diff --git a/src/engine/input/InputConst.java b/src/engine/input/InputConst.java
index e45db72..85c927e 100644
--- a/src/engine/input/InputConst.java
+++ b/src/engine/input/InputConst.java
@@ -2,7 +2,7 @@ package engine.input;
public class InputConst {
/*
- Button ID
+ ButtonIG ID
*/
public final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7,
L_JoystickClick = 8, R_JoystickClick =9, up = 10, right = 11, down = 12, left = 13;
diff --git a/src/gameplay/actions/Action.java b/src/gameplay/actions/Action.java
index 8ae6805..2123c9c 100644
--- a/src/gameplay/actions/Action.java
+++ b/src/gameplay/actions/Action.java
@@ -1,10 +1,13 @@
package gameplay.actions;
import gameplay.frames.*;
+import gameplay.input.ButtonIG;
+
import java.util.ArrayList;
public interface Action {
ArrayList getFrame();
-
+
+ abstract ButtonIG[][] getCommand();
}
diff --git a/src/gameplay/actions/Attack.java b/src/gameplay/actions/Attack.java
index 9c1eb41..4f39091 100644
--- a/src/gameplay/actions/Attack.java
+++ b/src/gameplay/actions/Attack.java
@@ -16,7 +16,7 @@ public class Attack implements Action {
* For example, a classic fireball would be something like
* {{DOWN},{DOWN,RIGHT},{RIGHT},{A}}
*/
- private static Button[][] command;
+ private static ButtonIG[][] command;
/**
@@ -42,4 +42,29 @@ public class Attack implements Action {
}
return res;
}
+
+ public static boolean isIsSpecial() {
+ return isSpecial;
+ }
+
+ public static void setIsSpecial(boolean isSpecial) {
+ Attack.isSpecial = isSpecial;
+ }
+
+ @Override
+ public ButtonIG[][] getCommand() {
+ return command;
+ }
+
+ public static void setCommand(ButtonIG[][] command) {
+ Attack.command = command;
+ }
+
+ public attackPart[] getParts() {
+ return parts;
+ }
+
+ public void setParts(attackPart[] parts) {
+ this.parts = parts;
+ }
}
diff --git a/src/gameplay/actions/Dash.java b/src/gameplay/actions/Dash.java
index 80e07fc..3800c86 100644
--- a/src/gameplay/actions/Dash.java
+++ b/src/gameplay/actions/Dash.java
@@ -3,15 +3,15 @@ package gameplay.actions;
import java.util.ArrayList;
import gameplay.frames.Frame;
-import gameplay.input.Button;
+import gameplay.input.ButtonIG;
public class Dash implements Action {
/**
* The suite of Inputs to have the move come out.
* For example, a Front Dash would be something like
- * {{RIGHT},{RIGHT}}
+ * {{FORWARD},{FORWARD}}
*/
- private static Button[][] command;
+ private static ButtonIG[][] command;
private Frame[] frames;
@@ -25,4 +25,9 @@ public class Dash implements Action {
return res;
}
+ @Override
+ public ButtonIG[][] getCommand() {
+ return command;
+ }
+
}
diff --git a/src/gameplay/actions/Jump.java b/src/gameplay/actions/Jump.java
index e1befd5..5adabb0 100644
--- a/src/gameplay/actions/Jump.java
+++ b/src/gameplay/actions/Jump.java
@@ -3,16 +3,16 @@ package gameplay.actions;
import java.util.ArrayList;
import gameplay.frames.Frame;
-import gameplay.input.Button;
+import gameplay.input.ButtonIG;
public class Jump implements Action {
/**
* The Input to have the move come out.
* For example, a Front Jump would be something like
- * {UP,RIGHT}
+ * {{UP,RIGHT}}
*/
- private static Button[] command;
+ private static ButtonIG[][] command;
private Frame[] frames;
@@ -25,4 +25,9 @@ public class Jump implements Action {
return res;
}
+ @Override
+ public ButtonIG[][] getCommand() {
+ return command;
+ }
+
}
diff --git a/src/gameplay/actions/Throw.java b/src/gameplay/actions/Throw.java
index 6a9ed18..8d631ed 100644
--- a/src/gameplay/actions/Throw.java
+++ b/src/gameplay/actions/Throw.java
@@ -3,7 +3,7 @@ package gameplay.actions;
import java.util.ArrayList;
import gameplay.frames.Frame;
-import gameplay.input.Button;
+import gameplay.input.ButtonIG;
public class Throw implements Action {
@@ -17,7 +17,7 @@ public class Throw implements Action {
* For example, a Moonsault Press would be something like
* {{LEFT},{DOWN,LEFT},{DOWN},{DOWN,RIGHT},{RIGHT},{RIGHT,UP},{UP},{A}}
*/
- private static Button[][] command;
+ private static ButtonIG[][] command;
/**
* The different sections of the throw
@@ -50,4 +50,9 @@ public class Throw implements Action {
return res;
}
+ @Override
+ public ButtonIG[][] getCommand() {
+ return command;
+ }
+
}
diff --git a/src/gameplay/entities/Character.java b/src/gameplay/entities/Character.java
index ed069f6..b951fbc 100644
--- a/src/gameplay/entities/Character.java
+++ b/src/gameplay/entities/Character.java
@@ -1,6 +1,8 @@
package gameplay.entities;
+import gameplay.actions.*;
import gameplay.frames.Frame;
+import gameplay.frames.nextFrameBuffer;
/**
* Character class, which is a sub-class of an entity
@@ -9,6 +11,23 @@ import gameplay.frames.Frame;
*/
public class Character extends Entity {
private static int maxHP;
+
+ /**
+ * All of the attacks, both special and normal, of the character
+ * They should be put in the order of priority (attacks[0] being the highest priority)
+ * For example, you should have something like :
+ * {Rising Punch, FireBall, Jump D/C/B/A, Crouch D/C/B/A, Stand D/C/B/A}
+ */
+ private static Attack[] attacks;
+
+ private static Jump forwardJump;
+ private static Jump neutralJump;
+ private static Jump backJump;
+
+ private static Dash forwardDash;
+ private static Dash backDash;
+
+ private static Throw normalthrow;
/**
* Main constructor for a character. By default its max health is 1000 if not specified
@@ -28,4 +47,62 @@ public class Character extends Entity {
}
public int getMaxHP() { return this.maxHP;}
+
+ public static Attack[] getAttacks() {
+ return attacks;
+ }
+
+ public static void setAttacks(Attack[] attacks) {
+ Character.attacks = attacks;
+ }
+
+ public static Jump getForwardJump() {
+ return forwardJump;
+ }
+
+ public static void setForwardJump(Jump forwardJump) {
+ Character.forwardJump = forwardJump;
+ }
+
+ public static Jump getNeutralJump() {
+ return neutralJump;
+ }
+
+ public static void setNeutralJump(Jump neutralJump) {
+ Character.neutralJump = neutralJump;
+ }
+
+ public static Jump getBackJump() {
+ return backJump;
+ }
+
+ public static void setBackJump(Jump backJump) {
+ Character.backJump = backJump;
+ }
+
+ public static Dash getForwardDash() {
+ return forwardDash;
+ }
+
+ public static void setForwardDash(Dash forwardDash) {
+ Character.forwardDash = forwardDash;
+ }
+
+ public static Dash getBackDash() {
+ return backDash;
+ }
+
+ public static void setBackDash(Dash backDash) {
+ Character.backDash = backDash;
+ }
+
+ public static Throw getNormalthrow() {
+ return normalthrow;
+ }
+
+ public static void setNormalthrow(Throw normalthrow) {
+ Character.normalthrow = normalthrow;
+ }
+
+
}
diff --git a/src/gameplay/entities/Entity.java b/src/gameplay/entities/Entity.java
index 5d7bd38..57eda49 100644
--- a/src/gameplay/entities/Entity.java
+++ b/src/gameplay/entities/Entity.java
@@ -1,6 +1,9 @@
package gameplay.entities;
import gameplay.frames.Frame;
+import gameplay.frames.nextFrameBuffer;
+
+import java.util.ArrayList;
/**
* Entity class, which is the main class regrouping characters and projectiles
@@ -10,7 +13,8 @@ import gameplay.frames.Frame;
public class Entity {
private int posx;
private int posy;
- private Frame currentFrame;
+
+ private static nextFrameBuffer frames;
/**
* base constructor of the entity class
@@ -18,7 +22,7 @@ public class Entity {
public Entity() {
this.posx = 0;
this.posy = 0;
- this.currentFrame = new Frame();
+ this.frames = new nextFrameBuffer();
}
/**
@@ -30,21 +34,56 @@ public class Entity {
public Entity(int posx, int posy, Frame f) {
this.posx = posx;
this.posy = posy;
- this.currentFrame = f;
+ this.frames = new nextFrameBuffer();
+ this.frames.setCurrentFrame(f);
}
public void setPos(int x, int y) {
this.posx = x;
this.posy = y;
}
-
+
public void setCurrentFrame(Frame f) {
- this.currentFrame = f;
+ this.frames.setCurrentFrame(f);
}
-
+
public int getPosX() {return this.posx;}
public int getPosY() {return this.posy;}
- public Frame getCurrentframe() {return this.currentFrame;}
+ public Frame getCurrentframe() {return this.frames.getCurrentFrame();}
+
+ public static nextFrameBuffer Frames() {
+ return frames;
+ }
+
+ public void setFrames(nextFrameBuffer nextFrames) {
+ this.frames = nextFrames;
+ }
+
+ public void clearNextFrames() {
+ this.frames.emptyQueue();
+ }
+
+ /**
+ * adds frames to the character queue.
+ * Warning : does not clear the queue first
+ * @param f
+ */
+ public void addNextFrames(Frame[] f) {
+ for(int i = 0; i < f.length; i++) {
+ this.frames.addFrameToQueue(f[i]);
+ }
+ }
+
+ /**
+ * adds a list of frames to the character queue.
+ * Warning : does not clear the queue first
+ * @param f
+ */
+ public void addNextFramesList(ArrayList f) {
+ for(int i = 0; i < f.size(); i++) {
+ this.frames.addFrameToQueue(f.get(i));
+ }
+ }
}
diff --git a/src/gameplay/input/Button.java b/src/gameplay/input/ButtonIG.java
similarity index 63%
rename from src/gameplay/input/Button.java
rename to src/gameplay/input/ButtonIG.java
index 709b5dc..6df8166 100644
--- a/src/gameplay/input/Button.java
+++ b/src/gameplay/input/ButtonIG.java
@@ -1,14 +1,17 @@
package gameplay.input;
-public enum Button {
- UP, DOWN, LEFT, RIGHT, A, B, C, D;
+/**
+ * In-Game buttons, not to be mixed up with the physical gamepad buttons.
+ */
+public enum ButtonIG {
+ UP, DOWN, BACK, FORWARD, A, B, C, D;
public int toInt() {
switch (this) {
case UP : return 0;
case DOWN : return 1;
- case LEFT : return 2;
- case RIGHT : return 3;
+ case BACK : return 2;
+ case FORWARD : return 3;
case A : return 4;
case B : return 5;
case C : return 6;
@@ -21,8 +24,8 @@ public enum Button {
switch (this) {
case UP : return "UP";
case DOWN : return "DOWN";
- case LEFT : return "LEFT";
- case RIGHT : return "RIGHT";
+ case BACK : return "LEFT";
+ case FORWARD : return "RIGHT";
case A : return "A";
case B : return "B";
case C : return "C";
@@ -31,8 +34,8 @@ public enum Button {
}
}
- public static Button intToButton(int i) {
- Button[] b = {UP, DOWN, LEFT, RIGHT, A, B, C, D};
+ public static ButtonIG intToButton(int i) {
+ ButtonIG[] b = {UP, DOWN, BACK, FORWARD, A, B, C, D};
try {
return b[i];
} catch (ArrayIndexOutOfBoundsException e) {
diff --git a/src/gameplay/input/InputBuffer.java b/src/gameplay/input/InputBuffer.java
index fd9e877..e17a135 100644
--- a/src/gameplay/input/InputBuffer.java
+++ b/src/gameplay/input/InputBuffer.java
@@ -82,10 +82,11 @@ public class InputBuffer {
/**
* records the new Inputs from a gamepad in the gamepad buffer
* @param pad the gamepad to record
+ * @param facesRight whether the character faces right or not, to know which way is forward
*/
- public void recordInputsFromGamepad(GamepadInput pad) {
+ public void recordInputsFromGamepad(GamepadInput pad, boolean facesRight) {
Inputs in = new Inputs();
- in.recordFromGamepad(pad);
+ in.recordFromGamepad(pad, facesRight);
this.recordInputs(in);
}
}
diff --git a/src/gameplay/input/Inputs.java b/src/gameplay/input/Inputs.java
index 3ca6724..c5e2476 100644
--- a/src/gameplay/input/Inputs.java
+++ b/src/gameplay/input/Inputs.java
@@ -23,7 +23,7 @@ public class Inputs {
* record one input
* @param b the input to be recorded
*/
- public void recordOneInput(Button b) {
+ public void recordOneInput(ButtonIG b) {
int i = b.toInt();
this.tab[i] = true;
}
@@ -33,7 +33,7 @@ public class Inputs {
* @param b the button to be checked
* @return
*/
- public boolean containsInput(Button b) {
+ public boolean containsInput(ButtonIG b) {
return this.tab[b.toInt()];
}
@@ -54,7 +54,7 @@ public class Inputs {
* @param bs a number of inputs. Check if those are contained in this
* @return true if all inputs of in are also in this
*/
- public boolean containsButtonTab(Button[] bs) {
+ public boolean containsButtonTab(ButtonIG[] bs) {
for(int i = 0; i < bs.length; i++) {
if(!this.containsInput(bs[i])) { return false;}
}
@@ -65,21 +65,21 @@ 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 void recordFromGamepad(GamepadInput pad, boolean facesRight) {
+ this.tab[ButtonIG.UP.toInt()] = pad.checkPressed(InputConst.up);
+ this.tab[ButtonIG.DOWN.toInt()] = pad.checkPressed(InputConst.down);
+ this.tab[ButtonIG.BACK.toInt()] = (pad.checkPressed(InputConst.left) && facesRight) || (pad.checkPressed(InputConst.right)&&!facesRight);
+ this.tab[ButtonIG.FORWARD.toInt()] = (pad.checkPressed(InputConst.right) && facesRight) || (pad.checkPressed(InputConst.left) && !facesRight);
+ this.tab[ButtonIG.A.toInt()] = pad.checkPressed(InputConst.buttonX);
+ this.tab[ButtonIG.B.toInt()] = pad.checkPressed(InputConst.buttonA);
+ this.tab[ButtonIG.C.toInt()] = pad.checkPressed(InputConst.buttonY);
+ this.tab[ButtonIG.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() + " "; }
+ if(this.tab[i]) {s = s + ButtonIG.intToButton(i).toString() + " "; }
}
return s;
}
diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java
index 28b7a34..d23f05e 100644
--- a/src/gameplay/match/match.java
+++ b/src/gameplay/match/match.java
@@ -1,16 +1,11 @@
package gameplay.match;
-import engine.Engine;
import engine.input.Button;
import engine.input.GamepadInput;
-import engine.input.InputConst;
-import engine.object.ObjectGl;
import gameplay.input.InputBuffer;
-import gameplay.entities.*;
import gameplay.entities.Character;
-
-import java.util.ArrayList;
-import java.util.List;
+import gameplay.input.Inputs;
+import gameplay.input.ButtonIG;
import static org.lwjgl.glfw.GLFW.*;
@@ -35,6 +30,8 @@ public class match {
private static long timeStamp1;
private static long timeStamp2;
private static int frameCount;
+ private static GamepadInput gamepad1 = null;
+ private static GamepadInput gamepad2 = null;
/**
* base constructor of the match class.
@@ -101,14 +98,14 @@ public class match {
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
GamepadInput gamepad1 = null;
- Button jump = null;
+ ButtonIG jump = null;
if (Joystick1Present) {
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
List listJump = new ArrayList<>();
listJump.add(InputConst.buttonA);
- jump = new Button("jump", listJump, gamepad1);
+ jump = new ButtonIG("jump", listJump, gamepad1);
}
while (engine.isRunning()) {
@@ -148,13 +145,17 @@ public class match {
int frame = 0;
boolean goToNextFrame = true;
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
- GamepadInput gamepad1 = null;
+ boolean Joystick2Present = glfwJoystickPresent(GLFW_JOYSTICK_2);
match match = new match(new Character(),new Character()); //TOD0 : Change to not empty chars
if (Joystick1Present) {
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
}
+ if(Joystick2Present) {
+ gamepad2 = new GamepadInput(GLFW_JOYSTICK_2);
+ gamepad2.inputRefresh();
+ }
}
@@ -192,9 +193,32 @@ public class match {
//if p2 is at 0 health
case 13:
- roundsWonP2++;
+ roundsWonP1++;
ac(11);
break;
+
+ //read both players inputs
+ case 20:
+ gamepad1.inputRefresh();
+ gamepad2.inputRefresh();
+ inputsP1.recordInputsFromGamepad(gamepad1, p1.getPosX() < p2.getPosX());
+ inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX());
+ handleInputs(p1, inputsP1);
+ handleInputs(p2, inputsP2);
+ }
+ }
+
+ /**
+ * Will handle the inputs recorder and have the character do a corresponding action if possible
+ * Order of priority is Throw > Special > Normal > Jump > Dash > Crouch > Move > do nothing
+ * @param c
+ * @param input
+ */
+ private static void handleInputs(Character c, InputBuffer input) {
+ Inputs latestIn = input.getLatestInputs();
+ if(latestIn.containsButtonTab(c.getNormalthrow().getCommand()[0])) {
+ c.clearNextFrames();
+ c.addNextFramesList(c.getNormalthrow().getFrame());
}
}
}