Hit Handling. Unfinished.

This commit is contained in:
no 2021-06-09 02:14:51 +02:00
parent ced29d97b8
commit 1ec5cddf3d
6 changed files with 142 additions and 19 deletions

View File

@ -29,6 +29,7 @@ public class attackPart {
this.knockbackOnHit = knockbackOnHit; this.knockbackOnHit = knockbackOnHit;
this.knockbackOnHit = knockbackOnBlock; this.knockbackOnHit = knockbackOnBlock;
this.frames = frames; this.frames = frames;
if(this.frames.length >= 1) {this.frames[this.frames.length-1].setLastFrameOfHit(true);}
this.hasHit = false; this.hasHit = false;
} }
@ -46,6 +47,7 @@ public class attackPart {
this.knockbackOnHit = 0.0; this.knockbackOnHit = 0.0;
this.knockbackOnBlock = 0.0; this.knockbackOnBlock = 0.0;
this.hasHit = false; this.hasHit = false;
if(this.frames.length >= 1) {this.frames[this.frames.length -1].setLastFrameOfHit(true);}
} }
public boolean hasHit() { public boolean hasHit() {
@ -111,4 +113,15 @@ public class attackPart {
public void setKnockbackOnBlock(double knockbackOnBlock) { public void setKnockbackOnBlock(double knockbackOnBlock) {
this.knockbackOnBlock = knockbackOnBlock; this.knockbackOnBlock = knockbackOnBlock;
} }
public void clone(attackPart aP) {
this.hasHit = aP.hasHit();
this.blockstun = aP.getBlockstun();
this.hitstun = aP.getHitstun();
this.chipDamage = aP.getChipDamage();
this.frames = aP.getFrames();
this.knockbackOnHit = aP.getKnockbackOnHit();
this.knockbackOnBlock = aP.getKnockbackOnBlock();
this.damage = aP.getDamage();
}
} }

View File

@ -4,6 +4,8 @@ import gameplay.actions.*;
import gameplay.frames.Frame; import gameplay.frames.Frame;
import gameplay.frames.nextFrameBuffer; import gameplay.frames.nextFrameBuffer;
import java.util.ArrayList;
/** /**
* Character class, which is a sub-class of an entity * Character class, which is a sub-class of an entity
* @author Victor * @author Victor
@ -11,6 +13,7 @@ import gameplay.frames.nextFrameBuffer;
*/ */
public class Character extends Entity { public class Character extends Entity {
private static int maxHP; private static int maxHP;
private static int currentHP;
/** /**
* All of the attacks, both special and normal, of the character * All of the attacks, both special and normal, of the character
@ -35,6 +38,8 @@ public class Character extends Entity {
private static Frame[] defaultCrouchingFrames; private static Frame[] defaultCrouchingFrames;
private static Frame[] forwardWalkFrames; private static Frame[] forwardWalkFrames;
private static Frame[] backWalkFrames; private static Frame[] backWalkFrames;
private ArrayList<attackPart> nextAttackParts;
/** /**
* Main constructor for a character. By default its max health is 1000 if not specified * Main constructor for a character. By default its max health is 1000 if not specified
@ -42,14 +47,17 @@ public class Character extends Entity {
public Character() { public Character() {
super(); super();
this.maxHP = 1000; this.maxHP = 1000;
this.status = Status.STANDING; this.currentHP = this.maxHP;
this.status = Status.NORMAL;
} }
public Character(int posx, int posy, Frame f, int maxHP) { public Character(int posx, int posy, Frame f, int maxHP) {
super(posx, posy, f); super(posx, posy, f);
this.maxHP = maxHP; this.maxHP = maxHP;
this.status = Status.STANDING; this.status = Status.NORMAL;
this.currentHP = this.maxHP;
} }
public void setMaxHP(int HP) { public void setMaxHP(int HP) {
this.maxHP = HP; this.maxHP = HP;
@ -152,4 +160,34 @@ public class Character extends Entity {
public static void setBackWalkFrames(Frame[] backWalkFrames) { public static void setBackWalkFrames(Frame[] backWalkFrames) {
Character.backWalkFrames = backWalkFrames; Character.backWalkFrames = backWalkFrames;
} }
public ArrayList<attackPart> getNextAttackParts() {
return nextAttackParts;
}
public void setNextAttackParts(ArrayList<attackPart> nextAttackParts) {
this.nextAttackParts = new ArrayList<attackPart>(nextAttackParts);
}
public void setAttackPartsArray(attackPart[] parts) {
this.nextAttackParts = new ArrayList<attackPart>();
for(int i = 0; i < parts.length; i++) {
this.nextAttackParts.add(parts[i]);
}
}
public static int getCurrentHP() {
return currentHP;
}
public void setCurrentHP(int currentHP) {
this.currentHP = currentHP;
}
/**
* puts the character's current hp back to its max value
*/
public void resetCurrentHP() {
this.currentHP = this.maxHP;
}
} }

View File

@ -1,5 +1,5 @@
package gameplay.entities; package gameplay.entities;
public enum Status { public enum Status {
STANDING, JUMPING, KNOCKEDDOWN, BLOCKING NORMAL, JUMPING, KNOCKEDDOWN, BLOCKING, FALLING, HITINAIR
} }

View File

@ -23,7 +23,7 @@ public class Frame {
private boolean jumpCancellable; private boolean jumpCancellable;
private boolean moveCancellable; private boolean moveCancellable;
private boolean isDashCancellable; private boolean isDashCancellable;
private boolean firstFrameOfHit; private boolean lastFrameOfHit;
public Frame() { public Frame() {
this.setMove_y(0.0); this.setMove_y(0.0);
@ -38,7 +38,7 @@ public class Frame {
this.jumpCancellable = true; this.jumpCancellable = true;
this.moveCancellable = true; this.moveCancellable = true;
this.isDashCancellable = true; this.isDashCancellable = true;
this.firstFrameOfHit = false; this.lastFrameOfHit = false;
} }
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,
@ -57,7 +57,7 @@ public class Frame {
this.jumpCancellable = jumpCancellable; this.jumpCancellable = jumpCancellable;
this.moveCancellable = moveCancellable; this.moveCancellable = moveCancellable;
this.isDashCancellable = isDashCancellable; this.isDashCancellable = isDashCancellable;
this.firstFrameOfHit = false; this.lastFrameOfHit = false;
} }
/* /*
@ -149,11 +149,13 @@ public class Frame {
this.pushHitBox = pushHitBox; this.pushHitBox = pushHitBox;
} }
public boolean isFirstFrameOfHit() { public boolean islastFrameOfHit() {
return firstFrameOfHit; return lastFrameOfHit;
} }
public void setFirstFrameOfHit(boolean firstFrameOfHit) { public void setLastFrameOfHit(boolean lastFrameOfHit) {
this.firstFrameOfHit = firstFrameOfHit; this.lastFrameOfHit = lastFrameOfHit;
} }
} }

View File

@ -96,5 +96,28 @@ public class HitBox {
return horiz && ver; return horiz && ver;
} }
public Double getPosX() {
return position_x;
}
public Double getPosY() {
return position_y;
}
public Double getSize_x() {
return size_x;
}
public void setSize_x(Double size_x) {
this.size_x = size_x;
}
public Double getSize_y() {
return size_y;
}
public void setSize_y(Double size_y) {
this.size_y = size_y;
}
} }

View File

@ -3,12 +3,17 @@ package gameplay.match;
import engine.input.Button; import engine.input.Button;
import engine.input.GamepadInput; import engine.input.GamepadInput;
import gameplay.actions.Attack; import gameplay.actions.Attack;
import gameplay.actions.attackPart;
import gameplay.entities.Status; import gameplay.entities.Status;
import gameplay.hitboxes.Active_HitBox;
import gameplay.hitboxes.Passive_HitBox;
import gameplay.input.InputBuffer; import gameplay.input.InputBuffer;
import gameplay.entities.Character; import gameplay.entities.Character;
import gameplay.input.Inputs; import gameplay.input.Inputs;
import gameplay.input.ButtonIG; import gameplay.input.ButtonIG;
import java.util.ArrayList;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
/** /**
@ -25,7 +30,6 @@ public class match {
private int timer; private int timer;
private InputBuffer inputsP1, inputsP2; private InputBuffer inputsP1, inputsP2;
private int hpP1, hpP2;
private int roundsWonP1, roundsWonP2; private int roundsWonP1, roundsWonP2;
private Character p1, p2; //characters of player 1 and 2 private Character p1, p2; //characters of player 1 and 2
@ -45,8 +49,6 @@ public class match {
this.inputsP2 = new InputBuffer(inputBufferSize); this.inputsP2 = new InputBuffer(inputBufferSize);
this.p1 = p1; this.p1 = p1;
this.p2 = p2; this.p2 = p2;
this.hpP1 = p1.getMaxHP();
this.hpP2 = p2.getMaxHP();
this.roundsWonP1 = 0; this.roundsWonP1 = 0;
this.roundsWonP2 = 0; this.roundsWonP2 = 0;
} }
@ -58,8 +60,6 @@ public class match {
this.timer = 99; this.timer = 99;
this.inputsP1 = new InputBuffer(inputBufferSize); this.inputsP1 = new InputBuffer(inputBufferSize);
this.inputsP2 = new InputBuffer(inputBufferSize); this.inputsP2 = new InputBuffer(inputBufferSize);
this.hpP1 = p1.getMaxHP();
this.hpP2 = p2.getMaxHP();
this.p1.setPos(-500, 250); //TODO : change to better values if needed 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.p2.setPos(500, 250); //TODO : change to better values if needed
} }
@ -174,9 +174,9 @@ public class match {
//checks if one or both of the chars are out of health //checks if one or both of the chars are out of health
case 10: case 10:
if(this.hpP1 <= 0 && hpP2 <= 0) { ac(11);} if(p1.getCurrentHP() <= 0 && p2.getCurrentHP() <= 0) { ac(11);}
else if(this.hpP1 <= 0) { ac(12);} else if(p1.getCurrentHP() <= 0) { ac(12);}
else if(this.hpP2 <= 0) { ac(13);} else if(p2.getCurrentHP() <= 0) { ac(13);}
else { ac(20);} else { ac(20);}
break; break;
@ -207,6 +207,14 @@ public class match {
inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX()); inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX());
handleInputs(p1, inputsP1); handleInputs(p1, inputsP1);
handleInputs(p2, inputsP2); handleInputs(p2, inputsP2);
ac(21);
break;
//start of the handling of hitboxes
case 21:
handleThrows();
handleHits(p1,p2,inputsP2);
} }
} }
@ -235,6 +243,7 @@ public class match {
if(attackIsPossible) { if(attackIsPossible) {
c.clearNextFrames(); c.clearNextFrames();
c.addNextFramesList(atk.getFrame()); c.addNextFramesList(atk.getFrame());
c.setAttackPartsArray(atk.getParts());
actionSet = true; actionSet = true;
} }
atkCount++; atkCount++;
@ -285,4 +294,42 @@ public class match {
} }
private static void handleThrows() {
}
/**
* handles the if the first character hits the second one
* @param p1 the character whose hits to handle
* @param p2 the character who is or isn't hit
* @param inputsP2 the inputs of the player 2, used to see if they're guarding
*/
private static void handleHits(Character p1, Character p2, InputBuffer inputsP2) {
ArrayList<Active_HitBox> activeP1 = new ArrayList<Active_HitBox>(p1.getCurrentframe().getActHitBox());
ArrayList<Passive_HitBox> passiveP2 = new ArrayList<Passive_HitBox>(p2.getCurrentframe().getPassHitBox());
ArrayList<attackPart> aP = new ArrayList<attackPart>(p1.getNextAttackParts());
attackPart hit = new attackPart(aP.get(0).getFrames());
hit.clone(aP.get(0));
for(Active_HitBox aH : activeP1) {
for(Passive_HitBox pH : passiveP2) {
if(!hit.hasHit()){
boolean p1LooksRight = p1.getPosX() < p2.getPosX();
boolean touchH = (p1LooksRight && (aH.getPosX()+p1.getPosX()+ aH.getSize_x() > pH.getPosX()+p2.getPosX()+pH.getSize_x())
&& (aH.getPosX() < pH.getPosX()))
|| (!p1LooksRight && (aH.getPosX()+p1.getPosX()+ aH.getSize_x() < pH.getPosX()+p2.getPosX()+pH.getSize_x())
&& (aH.getPosX() > pH.getPosX()));
boolean touchV = (aH.getPosY() - aH.getSize_y() < pH.getPosY()) && (aH.getPosY() > pH.getPosY() - pH.getSize_y());
if(touchH && touchV) {
if(p2.)
hit.setHasHit(true);
aP.set(0,hit);
}
}
}
}
}
} }