small changes in match to reduce crashes

This commit is contained in:
Azra Victor 2021-06-10 12:40:09 +02:00 committed by no
parent 93f5727569
commit 63ac95865a
3 changed files with 27 additions and 15 deletions

View File

@ -44,7 +44,7 @@ public class Frame {
this.moveCancellable = true; this.moveCancellable = true;
this.isDashCancellable = true; this.isDashCancellable = true;
this.lastFrameOfHit = false; this.lastFrameOfHit = false;
this.sprite = new int[0]; this.sprite = new int[4];
} }
public Frame(Double move_y, Double move_x, ArrayList<Passive_HitBox> passHitBox, ArrayList<Active_HitBox> actHitBox, public Frame(Double move_y, Double move_x, ArrayList<Passive_HitBox> passHitBox, ArrayList<Active_HitBox> actHitBox,

View File

@ -49,7 +49,9 @@ public class nextFrameBuffer {
} }
public Frame getNextframe() { public Frame getNextframe() {
return this.next.current; try {
return this.next.current;
} catch(NullPointerException e) {return null;}
} }
/** /**

View File

@ -5,6 +5,7 @@ import engine.input.Button;
import engine.input.GamepadInput; import engine.input.GamepadInput;
import engine.math.Vector3f; import engine.math.Vector3f;
import engine.object.ObjectGl; import engine.object.ObjectGl;
import engine.object.Sprite;
import gameplay.Characters.Blue.CharacterBlue; import gameplay.Characters.Blue.CharacterBlue;
import gameplay.actions.Attack; import gameplay.actions.Attack;
import gameplay.actions.attackPart; import gameplay.actions.attackPart;
@ -70,6 +71,8 @@ public class match {
inputsP2 = new InputBuffer(inputBufferSize); inputsP2 = new InputBuffer(inputBufferSize);
p1.setPos(-750, groundLevel); //TODO : change to better values if needed p1.setPos(-750, groundLevel); //TODO : change to better values if needed
p2.setPos(-750, groundLevel); //TODO : change to better values if needed p2.setPos(-750, groundLevel); //TODO : change to better values if needed
objP1.translate(new Vector3f(p1.getPosX(),p1.getPosY(),0));
objP1.translate(new Vector3f(p2.getPosX(),p2.getPosY(),0));
} }
/** /**
@ -168,17 +171,17 @@ public class match {
p1 = CharacterBlue.generateCharBlue(); p1 = CharacterBlue.generateCharBlue();
p2 = CharacterBlue.generateCharBlue(); p2 = CharacterBlue.generateCharBlue();
objP1 = new ObjectGl(1f, 60f, 80f, 5f, path, null); objP1 = new Sprite(10f, 5f, path, null);
objP2 = new ObjectGl(2f, 60f, 80f, 5f, path, null); objP2 = new Sprite(15f, 5f, path, null);
objP2.setColor(new Vector3f(1.0f,0.0f,1.0f));
engine.add_objectGl(objP1); engine.add_objectGl(objP1);
engine.add_objectGl(objP2); engine.add_objectGl(objP2);
f = p1.getCurrentframe(); f = p1.getCurrentframe();
objP1.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP); objP1.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
objP1.translate(new Vector3f(-750,200,0));
f = p2.getCurrentframe(); f = p2.getCurrentframe();
objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP); objP2.setTextureWrap(f.getSprite()[0], f.getSprite()[1], f.getSprite()[2], f.getSprite()[3], ObjectGl.STICK_TOP);
objP2.translate(new Vector3f(750,200,0));
objP2.flipTextureWrapH(); objP2.flipTextureWrapH();
if (Joystick1Present) { if (Joystick1Present) {
@ -239,10 +242,12 @@ public class match {
//read both players inputs //read both players inputs
case 20: case 20:
gamepad1.inputRefresh(); if (glfwJoystickPresent(GLFW_JOYSTICK_1) && glfwJoystickPresent(GLFW_JOYSTICK_2)) {
inputsP1.recordInputsFromGamepad(gamepad1, p1.getPosX() < p2.getPosX()); gamepad1.inputRefresh();
gamepad2.inputRefresh(); inputsP1.recordInputsFromGamepad(gamepad1, p1.getPosX() < p2.getPosX());
inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX()); gamepad2.inputRefresh();
inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX());
}
handleInputs(p1, inputsP1); handleInputs(p1, inputsP1);
handleInputs(p2, inputsP2); handleInputs(p2, inputsP2);
ac(21); ac(21);
@ -250,9 +255,13 @@ public class match {
//start of the handling of hitboxes //start of the handling of hitboxes
case 21: case 21:
handleThrows(p1,p2); try {
handleHits(p1,p2,inputsP2); handleThrows(p1, p2);
handleHits(p2,p1,inputsP1); } catch (IndexOutOfBoundsException e) {}
try {
handleHits(p1, p2, inputsP2);
handleHits(p2, p1, inputsP1);
}catch (IndexOutOfBoundsException e) {};
ac(22); ac(22);
break; break;
@ -514,9 +523,10 @@ public class match {
* @param in the input buffer corresponding to the character * @param in the input buffer corresponding to the character
*/ */
private static void nextFrame(Character c, InputBuffer in) { private static void nextFrame(Character c, InputBuffer in) {
if(!c.getFrames().getNextframe().equals(null)){ try {
//if(!c.getFrames().getNextframe().equals(null)){
c.goToNextFrames(); c.goToNextFrames();
} else { } catch (NullPointerException e) {
switch(c.getStatus()) { switch(c.getStatus()) {
case FALLING:case HITINAIR: case FALLING:case HITINAIR:
if(c.getPosY() > groundLevel){ if(c.getPosY() > groundLevel){