Added lots of parameters to Entity and Character so it woul be easier to handle actions during gameplay.
This commit is contained in:
@ -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) {
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user