From d6c35e24c517ce86b682d65777133675d3a3f7c3 Mon Sep 17 00:00:00 2001 From: no Date: Thu, 27 May 2021 13:03:29 +0200 Subject: [PATCH 1/4] slight adjustmentson the inputbuffer --- GamePlay/input/InputBuffer.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GamePlay/input/InputBuffer.java b/GamePlay/input/InputBuffer.java index 5225f9c..32e51fe 100644 --- a/GamePlay/input/InputBuffer.java +++ b/GamePlay/input/InputBuffer.java @@ -2,6 +2,7 @@ package input; public class InputBuffer { + private static final int numberOfInputs = 8; private static final Boolean[] baseInputs = {false,false,false,false,false,false,false,false}; /** @@ -31,16 +32,19 @@ public class InputBuffer { public InputBuffer() { this.size = 1; this.pos = 0; - this.inputList = new Boolean[1][8]; + this.inputList = new Boolean[1][numberOfInputs]; setLatestInputs(baseInputs); } public InputBuffer(int size) { this.size = size; this.pos = 0; - this.inputList = new Boolean[this.size][8]; + this.inputList = new Boolean[this.size][numberOfInputs]; - for(int i = 0; i < this.size; i++) {this.inputList[i] = baseInputs;} + for(int i = 0; i < this.size; i++) { + for(int j = 0; j < numberOfInputs; j++) { + this.inputList[i][j] = baseInputs[j];} + } } From e02acbcf5c6c5626a8bca97279cab749dbaf038d Mon Sep 17 00:00:00 2001 From: no Date: Thu, 27 May 2021 13:43:42 +0200 Subject: [PATCH 2/4] Started adjusting the handling of Inputs --- GamePlay/Actions/Attack.java | 5 ++++ GamePlay/input/Button.java | 19 ++++++++++++++ GamePlay/input/InputBuffer.java | 1 - GamePlay/input/Input_Attack.java | 11 -------- GamePlay/input/Inputs.java | 45 ++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 GamePlay/Actions/Attack.java create mode 100644 GamePlay/input/Button.java delete mode 100644 GamePlay/input/Input_Attack.java create mode 100644 GamePlay/input/Inputs.java diff --git a/GamePlay/Actions/Attack.java b/GamePlay/Actions/Attack.java new file mode 100644 index 0000000..5a3bbb9 --- /dev/null +++ b/GamePlay/Actions/Attack.java @@ -0,0 +1,5 @@ +package Actions; + +public class Attack { + +} diff --git a/GamePlay/input/Button.java b/GamePlay/input/Button.java new file mode 100644 index 0000000..85a90c7 --- /dev/null +++ b/GamePlay/input/Button.java @@ -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; + } + } +} diff --git a/GamePlay/input/InputBuffer.java b/GamePlay/input/InputBuffer.java index 32e51fe..570eabd 100644 --- a/GamePlay/input/InputBuffer.java +++ b/GamePlay/input/InputBuffer.java @@ -2,7 +2,6 @@ package input; public class InputBuffer { - private static final int numberOfInputs = 8; private static final Boolean[] baseInputs = {false,false,false,false,false,false,false,false}; /** diff --git a/GamePlay/input/Input_Attack.java b/GamePlay/input/Input_Attack.java deleted file mode 100644 index c61661f..0000000 --- a/GamePlay/input/Input_Attack.java +++ /dev/null @@ -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_list; - -} diff --git a/GamePlay/input/Inputs.java b/GamePlay/input/Inputs.java new file mode 100644 index 0000000..c34934f --- /dev/null +++ b/GamePlay/input/Inputs.java @@ -0,0 +1,45 @@ +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(int i) { + try { + this.tab[i] = true; + } catch (ArrayIndexOutOfBoundsException e) { + //TODO : what do we do here ? Error message ? + } + } + + /** + * 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()]; + } + + public boolean[] getInputs() { + return this.tab; + } + + +} From 2710c91b002f1b18a9852a41440e52564cdd9776 Mon Sep 17 00:00:00 2001 From: no Date: Thu, 27 May 2021 14:13:02 +0200 Subject: [PATCH 3/4] Added Handling of Inputs recognition. --- GamePlay/input/InputBuffer.java | 27 +++++++++------------------ GamePlay/input/Inputs.java | 31 ++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/GamePlay/input/InputBuffer.java b/GamePlay/input/InputBuffer.java index 570eabd..058e4b0 100644 --- a/GamePlay/input/InputBuffer.java +++ b/GamePlay/input/InputBuffer.java @@ -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,19 +29,17 @@ public class InputBuffer { public InputBuffer() { this.size = 1; this.pos = 0; - this.inputList = new Boolean[1][numberOfInputs]; - setLatestInputs(baseInputs); + this.inputList = new Inputs[1]; } public InputBuffer(int size) { this.size = size; this.pos = 0; - this.inputList = new Boolean[this.size][numberOfInputs]; + this.inputList = new Inputs[this.size]; for(int i = 0; i < this.size; i++) { - for(int j = 0; j < numberOfInputs; j++) { - this.inputList[i][j] = baseInputs[j];} - } + this.inputList[i] = new Inputs(); + } } @@ -51,7 +47,7 @@ public class InputBuffer { /** * @return the latest added inputs */ - public Boolean[] getLatestInputs() { + public Inputs getLatestInputs() { return this.inputList[this.pos]; } @@ -60,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; } /** @@ -81,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); } diff --git a/GamePlay/input/Inputs.java b/GamePlay/input/Inputs.java index c34934f..769a029 100644 --- a/GamePlay/input/Inputs.java +++ b/GamePlay/input/Inputs.java @@ -20,12 +20,9 @@ public class Inputs { * record one input * @param i the integer value corresponding to the tab location */ - public void recordOneInput(int i) { - try { + public void recordOneInput(Button b) { + int i = b.toInt(); this.tab[i] = true; - } catch (ArrayIndexOutOfBoundsException e) { - //TODO : what do we do here ? Error message ? - } } /** @@ -37,6 +34,30 @@ public class Inputs { 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; } From 31d5cad0fcb594cebfa1a09d9bbc3fa5daaefba9 Mon Sep 17 00:00:00 2001 From: no Date: Thu, 27 May 2021 14:26:14 +0200 Subject: [PATCH 4/4] Added base Attack class parameters. --- GamePlay/Actions/Attack.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/GamePlay/Actions/Attack.java b/GamePlay/Actions/Attack.java index 5a3bbb9..7a55549 100644 --- a/GamePlay/Actions/Attack.java +++ b/GamePlay/Actions/Attack.java @@ -1,5 +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; + }