Handling of the inputs done. Determines what the characters next frames will be depending on what th player has input.

This commit is contained in:
no 2021-06-07 17:38:35 +02:00
parent 67d4c9be53
commit 5b5960d554
6 changed files with 218 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package gameplay.actions;
import java.util.ArrayList;
import gameplay.entities.Status;
import gameplay.frames.*;
import gameplay.input.*;
@ -11,6 +12,9 @@ public class Attack implements Action {
*/
private static boolean isSpecial;
private static Status requiredStatus;
/**
* The suite of Inputs to have the move come out.
* For example, a classic fireball would be something like
@ -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();}
}

View File

@ -29,17 +29,26 @@ public class Character extends Entity {
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
*/
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;
}
}

View File

@ -0,0 +1,5 @@
package gameplay.entities;
public enum Status {
STANDING, JUMPING, KNOCKEDDOWN, BLOCKING
}

View File

@ -18,6 +18,11 @@ public class Frame {
private ArrayList<Passive_throw_HitBox> passThrowHitBox;
private ArrayList<Active_throw_Hitbox> 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<Passive_throw_HitBox>();
this.actThrowHitBox = new ArrayList<Active_throw_Hitbox>();
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<Passive_HitBox> passHitBox, ArrayList<Active_HitBox> actHitBox,
ArrayList<Passive_throw_HitBox> passThrowHitBox, ArrayList<Active_throw_Hitbox> 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;
}
/*
@ -54,4 +70,23 @@ public class Frame {
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;
}
}

View File

@ -4,6 +4,13 @@ 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
* Each element is a tab where each element represent a possible input
@ -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;
}
}

View File

@ -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());
}
}
}
}
}