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:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user