This commit is contained in:
keizaal 2021-05-27 15:49:13 +02:00
commit e52f8e890e
5 changed files with 109 additions and 27 deletions

View File

@ -0,0 +1,14 @@
package Actions;
import input.*;
public class Attack {
private static boolean isSpecial;
/**
* The suite of Inputs to have the move come out.
* For example, a classic fireball would be something like
* {{DOWN},{DOWN,RIGHT},{RIGHT},{A}}
*/
private static Button[][] command;
}

View File

@ -0,0 +1,19 @@
package input;
public enum Button {
UP, DOWN, LEFT, RIGHT, 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 A : return 4;
case B : return 5;
case C : return 6;
case D : return 7;
default : return -1;
}
}
}

View File

@ -2,8 +2,6 @@ package input;
public class InputBuffer {
private static final Boolean[] baseInputs = {false,false,false,false,false,false,false,false};
/**
* 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
@ -11,7 +9,7 @@ public class InputBuffer {
* if the value at the corresponding index is true, then the input is pressed
* By default, no input is pressed.
*/
private Boolean[][] inputList;
private Inputs[] inputList;
/*
* the size of the input buffer
@ -31,16 +29,17 @@ public class InputBuffer {
public InputBuffer() {
this.size = 1;
this.pos = 0;
this.inputList = new Boolean[1][8];
setLatestInputs(baseInputs);
this.inputList = new Inputs[1];
}
public InputBuffer(int size) {
this.size = size;
this.pos = 0;
this.inputList = new Boolean[this.size][8];
this.inputList = new Inputs[this.size];
for(int i = 0; i < this.size; i++) {this.inputList[i] = baseInputs;}
for(int i = 0; i < this.size; i++) {
this.inputList[i] = new Inputs();
}
}
@ -48,7 +47,7 @@ public class InputBuffer {
/**
* @return the latest added inputs
*/
public Boolean[] getLatestInputs() {
public Inputs getLatestInputs() {
return this.inputList[this.pos];
}
@ -57,13 +56,8 @@ public class InputBuffer {
* Sets the last input without moving the current position
* @param inputs
*/
private void setLatestInputs(Boolean[] inputs) {
try {
for(int i = 0; i < 8; i++) {
this.inputList[pos][i] = inputs[i];
}
} catch (ArrayIndexOutOfBoundsException e) { //TODO : what do we do in this case ?
}
private void setLatestInputs(Inputs inputs) {
this.inputList[pos] = inputs;
}
/**
@ -78,7 +72,7 @@ public class InputBuffer {
* record a new input in the
* @param inputs a size 8 tab of inputs
*/
private void recordInputs(Boolean[] inputs) {
private void recordInputs(Inputs inputs) {
this.nextPos();
this.setLatestInputs(inputs);
}

View File

@ -1,11 +0,0 @@
package input;
import java.util.ArrayList;
public class Input_Attack {
/*
* The list of all input needed to make an attack
*/
//public ArrayList<Input> input_list;
}

View File

@ -0,0 +1,66 @@
package input;
/**
* The class handling the parsing of one input.
* @author Victor
*
*/
public class Inputs {
private static final int numberOfInputs = 8;
private static boolean[] tab;
public Inputs() {
this.tab = new boolean[numberOfInputs];
for(int i = 0; i < numberOfInputs; i ++) {
this.tab[i] = false;
}
}
/**
* record one input
* @param i the integer value corresponding to the tab location
*/
public void recordOneInput(Button b) {
int i = b.toInt();
this.tab[i] = true;
}
/**
* Check if a specific input (for example UP) has been recorded
* @param i the integer value corresponding to the input
* @return
*/
public boolean containsInput(Button b) {
return this.tab[b.toInt()];
}
/**
* Check if a number of inputs are contained simultaneously
* @param in a number of inputs. Check if those are containes in this
* @return true if all inputs of in are also in this
*/
public boolean containsInputs(Inputs in) {
for(int i = 0; i < numberOfInputs; i++) {
if(this.tab[i] != in.getInputs()[i]) {return false;}
}
return true;
}
/**
* Check if a number of inputs are contained simultaneously, in the form of an array of Buttons
* @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) {
for(int i = 0; i < bs.length; i++) {
if(!this.containsInput(bs[i])) { return false;}
}
return true;
}
public boolean[] getInputs() {
return this.tab;
}
}