Added lots of parameters to Entity and Character so it woul be easier to handle actions during gameplay.

This commit is contained in:
no
2021-06-07 15:55:04 +02:00
parent 9ea45e793a
commit 67d4c9be53
12 changed files with 239 additions and 52 deletions

View File

@ -1,16 +1,11 @@
package gameplay.match;
import engine.Engine;
import engine.input.Button;
import engine.input.GamepadInput;
import engine.input.InputConst;
import engine.object.ObjectGl;
import gameplay.input.InputBuffer;
import gameplay.entities.*;
import gameplay.entities.Character;
import java.util.ArrayList;
import java.util.List;
import gameplay.input.Inputs;
import gameplay.input.ButtonIG;
import static org.lwjgl.glfw.GLFW.*;
@ -35,6 +30,8 @@ public class match {
private static long timeStamp1;
private static long timeStamp2;
private static int frameCount;
private static GamepadInput gamepad1 = null;
private static GamepadInput gamepad2 = null;
/**
* base constructor of the match class.
@ -101,14 +98,14 @@ public class match {
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
GamepadInput gamepad1 = null;
Button jump = null;
ButtonIG jump = null;
if (Joystick1Present) {
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
List<Integer> listJump = new ArrayList<>();
listJump.add(InputConst.buttonA);
jump = new Button("jump", listJump, gamepad1);
jump = new ButtonIG("jump", listJump, gamepad1);
}
while (engine.isRunning()) {
@ -148,13 +145,17 @@ public class match {
int frame = 0;
boolean goToNextFrame = true;
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
GamepadInput gamepad1 = null;
boolean Joystick2Present = glfwJoystickPresent(GLFW_JOYSTICK_2);
match match = new match(new Character(),new Character()); //TOD0 : Change to not empty chars
if (Joystick1Present) {
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
}
if(Joystick2Present) {
gamepad2 = new GamepadInput(GLFW_JOYSTICK_2);
gamepad2.inputRefresh();
}
}
@ -192,9 +193,32 @@ public class match {
//if p2 is at 0 health
case 13:
roundsWonP2++;
roundsWonP1++;
ac(11);
break;
//read both players inputs
case 20:
gamepad1.inputRefresh();
gamepad2.inputRefresh();
inputsP1.recordInputsFromGamepad(gamepad1, p1.getPosX() < p2.getPosX());
inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX());
handleInputs(p1, inputsP1);
handleInputs(p2, inputsP2);
}
}
/**
* Will handle the inputs recorder and have the character do a corresponding action if possible
* Order of priority is Throw > Special > Normal > Jump > Dash > Crouch > Move > do nothing
* @param c
* @param input
*/
private static void handleInputs(Character c, InputBuffer input) {
Inputs latestIn = input.getLatestInputs();
if(latestIn.containsButtonTab(c.getNormalthrow().getCommand()[0])) {
c.clearNextFrames();
c.addNextFramesList(c.getNormalthrow().getFrame());
}
}
}