Main Gameplay Loop done.

Only Missing Throws and Projectile handling.
Need to be fused with engine.
This commit is contained in:
Azra Victor
2021-06-09 13:14:17 +02:00
committed by no
parent 1ec5cddf3d
commit ed2f49ad0e
9 changed files with 324 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import engine.input.GamepadInput;
import gameplay.actions.Attack;
import gameplay.actions.attackPart;
import gameplay.entities.Status;
import gameplay.frames.Frame;
import gameplay.hitboxes.Active_HitBox;
import gameplay.hitboxes.Passive_HitBox;
import gameplay.input.InputBuffer;
@ -22,13 +23,18 @@ import static org.lwjgl.glfw.GLFW.*;
*
*/
public class match {
/**
* the number of inputs read for each character, a.k.a. for how many frames the inputs are saved in memory.
* the number of inputs read for each character, a.k.a. for how many frames the inputs are saved in memory.
*/
private static final int inputBufferSize = 120;
/**
* the level of the "ground", used to determine if a character is in the air or not.
*/
private static final int groundLevel = 250;
private int timer;
private int timer;
private InputBuffer inputsP1, inputsP2;
private int roundsWonP1, roundsWonP2;
private Character p1, p2; //characters of player 1 and 2
@ -60,8 +66,8 @@ public class match {
this.timer = 99;
this.inputsP1 = new InputBuffer(inputBufferSize);
this.inputsP2 = new InputBuffer(inputBufferSize);
this.p1.setPos(-500, 250); //TODO : change to better values if needed
this.p2.setPos(500, 250); //TODO : change to better values if needed
this.p1.setPos(-500, groundLevel); //TODO : change to better values if needed
this.p2.setPos(500, groundLevel); //TODO : change to better values if needed
}
/**
@ -144,11 +150,9 @@ public class match {
nextFrame = false;
if (engine.shouldClose()) engine.setRunning(false);
} */
int frame = 0;
boolean goToNextFrame = true;
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
boolean Joystick2Present = glfwJoystickPresent(GLFW_JOYSTICK_2);
match match = new match(new Character(),new Character()); //TOD0 : Change to not empty chars
match match = new match(new Character(),new Character()); //TODO : Change to not empty chars
if (Joystick1Present) {
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
@ -214,6 +218,47 @@ public class match {
case 21:
handleThrows();
handleHits(p1,p2,inputsP2);
handleHits(p2,p1,inputsP1);
ac(22);
break;
//Update of the current frame of each character
case 22:
if(p1.getCurrentframe().islastFrameOfHit()) {
p1.removeFirstAttackPart();
}
if(p2.getCurrentframe().islastFrameOfHit()) {
p2.removeFirstAttackPart();
}
nextFrame(p1,inputsP1);
nextFrame(p2,inputsP2);
updatePos(p1);
updatePos(p2);
boolean p1LooksRight = p1.getPosX() < p2.getPosX();
if(p1LooksRight) {
Frame f = new Frame();
f.clone(p2.getCurrentframe());
f.invertHitBoxes();
p2.setCurrentFrame(f);
} else {
Frame f = new Frame();
f.clone(p1.getCurrentframe());
f.invertHitBoxes();
p1.setCurrentFrame(f);
}
ac(23);
break;
//Waits the end of 1/60th of a second since start of frame then loops back to start
case 23:
timeStamp2 = System.currentTimeMillis();
while(timeStamp2-timeStamp1<(1000/60)) {
timeStamp2 = System.currentTimeMillis();
}
frameCount++;
timeStamp1 = System.currentTimeMillis();
ac(10);
break;
}
}
@ -322,7 +367,7 @@ public class match {
boolean touchV = (aH.getPosY() - aH.getSize_y() < pH.getPosY()) && (aH.getPosY() > pH.getPosY() - pH.getSize_y());
if(touchH && touchV) {
if(p2.)
getHit(p2,hit,inputsP2.getLatestInputs());
hit.setHasHit(true);
aP.set(0,hit);
}
@ -332,4 +377,101 @@ public class match {
}
}
/**
* Handles a character getting hit by an attack part.
* @param c the character that's getting hit
* @param aP the attackPart hitting the character
* @param inputs the current inputs of c
*/
private static void getHit(Character c, attackPart aP, Inputs inputs) {
boolean getsHit = (c.getStatus() == Status.JUMPING) || (c.getStatus() == Status.HITINAIR) || (c.getStatus() == Status.FALLING)
|| inputs.containsInput(ButtonIG.BACK)
|| (aP.isLow() && !inputs.containsInput(ButtonIG.DOWN))
|| (aP.isOverHead() && inputs.containsInput(ButtonIG.DOWN));
Frame[] nextFrames;
c.clearNextFrames();
if(getsHit) {
switch (c.getStatus()) {
case JUMPING: case HITINAIR: case FALLING :
nextFrames = new Frame[20];
for(int i = 0; i < nextFrames.length; i++) {
nextFrames[i] = c.getHitInAirFrame();
}
c.addNextFrames(nextFrames);
c.reduceHP(aP.getDamage());
c.setStatus(Status.HITINAIR);
break;
default :
c.clearNextFrames();
if(!aP.knocksDown()) {
nextFrames = new Frame[aP.getHitstun()];
if (inputs.containsInput(ButtonIG.DOWN)) {
for (int i = 0; i < nextFrames.length; i++) {
nextFrames[i] = c.getCrouchHitFrame();
}
} else {
for (int i = 0; i < nextFrames.length; i++) {
nextFrames[i] = c.getStandHitFrame();
}
}
} else {
nextFrames = new Frame[c.getKnockedDownFrames().length];
for (int i = 0; i < nextFrames.length; i++) {
nextFrames[i] = c.getKnockedDownFrames()[i];
}
}
c.addNextFrames(nextFrames);
c.reduceHP(aP.getDamage());
break;
}
} else {
nextFrames = new Frame[aP.getBlockstun()];
if(inputs.containsInput(ButtonIG.DOWN)) {
for(int i = 0; i < nextFrames.length; i++) {
nextFrames[i] = c.getCrouchGuardFrame();
}
} else {
for(int i = 0; i < nextFrames.length; i++) {
nextFrames[i] = c.getStandGuardFrame();
}
}
c.reduceHP(aP.getChipDamage());
c.addNextFrames(nextFrames);
}
}
/**
* Sets the character to its next logical frame
* @param c the character
* @param in the input buffer corresponding to the character
*/
private void nextFrame(Character c, InputBuffer in) {
if(!c.getFrames().getNextframe().equals(null)){
c.goToNextFrames();
} else {
switch(c.getStatus()) {
case FALLING:case HITINAIR:
if(c.getPosY() > groundLevel){
c.setStatus(Status.FALLING);
c.setCurrentFrame(c.getFallingframe());
} else {
c.setPos(c.getPosX(),groundLevel);
c.setStatus(Status.KNOCKEDDOWN);
c.addNextFrames(c.getKnockedDownFrames());
}
default:
c.setStatus(Status.NORMAL);
if(in.getLatestInputs().containsInput(ButtonIG.DOWN)) {
c.addNextFrames(c.getDefaultCrouchingFrames());
} else {c.addNextFrames(c.getDefaultStandingFrames());}
break;
}
}
}
private void updatePos(Character c) {
c.setPos((int)(c.getPosX()+c.getCurrentframe().getMove_x()),(int)(c.getPosY()+c.getCurrentframe().getMove_y()));
}
}