From 5b5960d5547f2ff3552a8df2994ef04cc66ccf0c Mon Sep 17 00:00:00 2001 From: no Date: Mon, 7 Jun 2021 17:38:35 +0200 Subject: [PATCH] Handling of the inputs done. Determines what the characters next frames will be depending on what th player has input. --- src/gameplay/actions/Attack.java | 16 ++++++- src/gameplay/entities/Character.java | 47 ++++++++++++++++++++ src/gameplay/entities/Status.java | 5 +++ src/gameplay/frames/Frame.java | 39 +++++++++++++++- src/gameplay/input/InputBuffer.java | 49 +++++++++++++++++++++ src/gameplay/match/match.java | 66 +++++++++++++++++++++++++++- 6 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 src/gameplay/entities/Status.java diff --git a/src/gameplay/actions/Attack.java b/src/gameplay/actions/Attack.java index 4f39091..87b64a5 100644 --- a/src/gameplay/actions/Attack.java +++ b/src/gameplay/actions/Attack.java @@ -2,6 +2,7 @@ package gameplay.actions; import java.util.ArrayList; +import gameplay.entities.Status; import gameplay.frames.*; import gameplay.input.*; @@ -9,7 +10,10 @@ public class Attack implements Action { /** * Defines if the attack is a special one (E.G. a fireball) or a normal one (a punch) */ - private static boolean isSpecial; + private static boolean isSpecial; + + private static Status requiredStatus; + /** * The suite of Inputs to have the move come out. @@ -67,4 +71,14 @@ public class Attack implements Action { public void setParts(attackPart[] parts) { this.parts = parts; } + + public static Status getRequiredStatus() { + return requiredStatus; + } + + public static void setRequiredStatus(Status requiredStatus) { + Attack.requiredStatus = requiredStatus; + } + + public boolean isSpecial() {return this.isSpecial();} } diff --git a/src/gameplay/entities/Character.java b/src/gameplay/entities/Character.java index b951fbc..f8d8462 100644 --- a/src/gameplay/entities/Character.java +++ b/src/gameplay/entities/Character.java @@ -28,6 +28,13 @@ public class Character extends Entity { private static Dash backDash; private static Throw normalthrow; + + private static Status status; + + private static Frame[] defaultStandingFrames; + private static Frame[] defaultCrouchingFrames; + private static Frame[] forwardWalkFrames; + private static Frame[] backWalkFrames; /** * Main constructor for a character. By default its max health is 1000 if not specified @@ -35,11 +42,13 @@ public class Character extends Entity { public Character() { super(); this.maxHP = 1000; + this.status = Status.STANDING; } public Character(int posx, int posy, Frame f, int maxHP) { super(posx, posy, f); this.maxHP = maxHP; + this.status = Status.STANDING; } public void setMaxHP(int HP) { @@ -104,5 +113,43 @@ public class Character extends Entity { Character.normalthrow = normalthrow; } + public static Status getStatus() { + return status; + } + public static void setStatus(Status status) { + Character.status = status; + } + + public static Frame[] getDefaultStandingFrames() { + return defaultStandingFrames; + } + + public static void setDefaultStandingFrames(Frame[] defaultStandingFrames) { + Character.defaultStandingFrames = defaultStandingFrames; + } + + public static Frame[] getDefaultCrouchingFrames() { + return defaultCrouchingFrames; + } + + public static void setDefaultCrouchingFrames(Frame[] defaultCrouchingFrames) { + Character.defaultCrouchingFrames = defaultCrouchingFrames; + } + + public static Frame[] getForwardWalkFrames() { + return forwardWalkFrames; + } + + public static void setForwardWalkFrames(Frame[] forwardWalkFrames) { + Character.forwardWalkFrames = forwardWalkFrames; + } + + public static Frame[] getBackWalkFrames() { + return backWalkFrames; + } + + public static void setBackWalkFrames(Frame[] backWalkFrames) { + Character.backWalkFrames = backWalkFrames; + } } diff --git a/src/gameplay/entities/Status.java b/src/gameplay/entities/Status.java new file mode 100644 index 0000000..2f565a6 --- /dev/null +++ b/src/gameplay/entities/Status.java @@ -0,0 +1,5 @@ +package gameplay.entities; + +public enum Status { + STANDING, JUMPING, KNOCKEDDOWN, BLOCKING +} diff --git a/src/gameplay/frames/Frame.java b/src/gameplay/frames/Frame.java index 14cf3cd..e5026eb 100644 --- a/src/gameplay/frames/Frame.java +++ b/src/gameplay/frames/Frame.java @@ -18,6 +18,11 @@ public class Frame { private ArrayList passThrowHitBox; private ArrayList actThrowHitBox; private Push_HitBox pushHitBox; + private boolean normalCancellable; + private boolean specialCancellable; + private boolean jumpCancellable; + private boolean moveCancellable; + private boolean isDashCancellable; public Frame() { this.move_y = 0.0; @@ -27,11 +32,17 @@ public class Frame { this.passThrowHitBox = new ArrayList(); this.actThrowHitBox = new ArrayList(); this.pushHitBox = new Push_HitBox(); + this.normalCancellable = true; + this.specialCancellable = true; + this.jumpCancellable = true; + this.moveCancellable = true; + this.isDashCancellable = true; } public Frame(Double move_y, Double move_x, ArrayList passHitBox, ArrayList actHitBox, ArrayList passThrowHitBox, ArrayList actThrowHitBox, - Push_HitBox pushHitBox) { + Push_HitBox pushHitBox, boolean normalCancellable, boolean specialCancellable, boolean jumpCancellable, + boolean moveCancellable, boolean isDashCancellable) { this.move_y = move_y; this.move_x = move_x; this.passHitBox = passHitBox; @@ -39,6 +50,11 @@ public class Frame { this.passThrowHitBox = passThrowHitBox; this.actThrowHitBox = actThrowHitBox; this.pushHitBox = pushHitBox; + this.normalCancellable = normalCancellable; + this.specialCancellable = specialCancellable; + this.jumpCancellable = jumpCancellable; + this.moveCancellable = moveCancellable; + this.isDashCancellable = isDashCancellable; } /* @@ -53,5 +69,24 @@ public class Frame { this.actThrowHitBox = new ArrayList(); this.pushHitBox = new Push_HitBox(); } - + + public boolean isNormalCancellable() { + return normalCancellable; + } + + public boolean isSpecialCancellable() { + return specialCancellable; + } + + public boolean isJumpCancellable() { + return jumpCancellable; + } + + public boolean isMoveCancellable() { + return moveCancellable; + } + + public boolean isDashCancellable() { + return isDashCancellable; + } } diff --git a/src/gameplay/input/InputBuffer.java b/src/gameplay/input/InputBuffer.java index e17a135..7b184da 100644 --- a/src/gameplay/input/InputBuffer.java +++ b/src/gameplay/input/InputBuffer.java @@ -3,6 +3,13 @@ package gameplay.input; import engine.input.GamepadInput; public class InputBuffer { + + /** + * The number of past frames to check for a certain input pas another one. + * For example, if you need to input DOWN, then FORWARD, and we know FORWARD has been input on frame 25, + * this indicates that you need to check for DOWN on frames 20 to 24 + */ + private static final int pastFramesToCheck = 5; /** * a list of various inputs being recorded, such as inputs pressed at each frame @@ -89,5 +96,47 @@ public class InputBuffer { in.recordFromGamepad(pad, facesRight); this.recordInputs(in); } + + /** + * Checks for a command to be recognized. The last input of the command has to have been input on the current frame + * @param command + * @return true if the command is recognized,false if not + */ + public boolean commandRecognized(ButtonIG[][] command) { + boolean ret = true; + int backCounter; + int startFrameCount = this.pos; + int frameToCheck; + try { + ret = this.inputList[pos].containsButtonTab(command[command.length - 1]); + } catch (ArrayIndexOutOfBoundsException e ) { + return true; + } + for(int i = command.length - 2; i <= 0 && ret; i--) { + backCounter = 1; + if(startFrameCount - backCounter < 0) {frameToCheck = this.size - (backCounter - startFrameCount);} + else {frameToCheck = startFrameCount - backCounter;} + boolean search = true; + while(ret && search) { + if(this.inputList[frameToCheck].containsButtonTab(command[i])) { + ret = true; + search = false; + } else { + if(backCounter == pastFramesToCheck) { + ret = false; + search = false; + } + else { + backCounter++; + if(startFrameCount - backCounter < 0) {frameToCheck = this.size - (backCounter - startFrameCount);} + else {frameToCheck = startFrameCount - backCounter;} + } + } + startFrameCount = frameToCheck; + } + } + + return ret; + } } diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index d23f05e..4b12082 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -2,6 +2,8 @@ package gameplay.match; import engine.input.Button; import engine.input.GamepadInput; +import gameplay.actions.Attack; +import gameplay.entities.Status; import gameplay.input.InputBuffer; import gameplay.entities.Character; import gameplay.input.Inputs; @@ -216,9 +218,71 @@ public class match { */ private static void handleInputs(Character c, InputBuffer input) { Inputs latestIn = input.getLatestInputs(); - if(latestIn.containsButtonTab(c.getNormalthrow().getCommand()[0])) { + boolean actionSet = false; + if(latestIn.containsButtonTab(c.getNormalthrow().getCommand()[0]) && c.getCurrentframe().isNormalCancellable()) { c.clearNextFrames(); c.addNextFramesList(c.getNormalthrow().getFrame()); + actionSet = true; + } else { + int atkCount = 0; + //do an attack if possible + while(atkCount < c.getAttacks().length && !actionSet) { + Attack atk = c.getAttacks()[atkCount]; + Boolean attackIsPossible = input.commandRecognized(atk.getCommand()) + && atk.getRequiredStatus().equals(c.getStatus()) + && ((atk.isSpecial() && c.getCurrentframe().isSpecialCancellable()) + || (!atk.isSpecial() && c.getCurrentframe().isNormalCancellable())); + if(attackIsPossible) { + c.clearNextFrames(); + c.addNextFramesList(atk.getFrame()); + actionSet = true; + } + atkCount++; + } + if(c.getCurrentframe().isJumpCancellable() && !actionSet) { + if (input.commandRecognized(c.getForwardJump().getCommand())) { + c.clearNextFrames(); + c.addNextFramesList(c.getForwardJump().getFrame()); + actionSet = true; + c.setStatus(Status.JUMPING); + } else if (input.commandRecognized(c.getBackJump().getCommand())) { + c.clearNextFrames(); + c.addNextFramesList(c.getForwardJump().getFrame()); + actionSet = true; + c.setStatus(Status.JUMPING); + } else if (input.commandRecognized(c.getNeutralJump().getCommand())) { + c.clearNextFrames(); + c.addNextFramesList(c.getNeutralJump().getFrame()); + actionSet = true; + c.setStatus(Status.JUMPING); + } + } + if(c.getCurrentframe().isDashCancellable() && !actionSet) { + if (input.commandRecognized(c.getForwardDash().getCommand())) { + c.clearNextFrames(); + c.addNextFramesList(c.getForwardDash().getFrame()); + actionSet = true; + } else if (input.commandRecognized(c.getBackDash().getCommand())) { + c.clearNextFrames(); + c.addNextFramesList(c.getBackDash().getFrame()); + actionSet = true; + } + } + if(c.getCurrentframe().isMoveCancellable() && !actionSet) { + if(input.getLatestInputs().containsInput(ButtonIG.DOWN)) { + c.clearNextFrames(); + c.addNextFrames(c.getDefaultCrouchingFrames()); + } else if(input.getLatestInputs().containsInput(ButtonIG.BACK)) { + c.clearNextFrames(); + c.addNextFrames(c.getBackWalkFrames()); + } if(input.getLatestInputs().containsInput(ButtonIG.FORWARD)) { + c.clearNextFrames(); + c.addNextFrames(c.getForwardWalkFrames()); + } + } + } + + } }