From 1ec5cddf3d6b5c77548f56a8c9eb719032eacaed Mon Sep 17 00:00:00 2001 From: no Date: Wed, 9 Jun 2021 02:14:51 +0200 Subject: [PATCH] Hit Handling. Unfinished. --- src/gameplay/actions/attackPart.java | 13 ++++++ src/gameplay/entities/Character.java | 42 ++++++++++++++++++- src/gameplay/entities/Status.java | 2 +- src/gameplay/frames/Frame.java | 16 +++---- src/gameplay/hitboxes/HitBox.java | 25 ++++++++++- src/gameplay/match/match.java | 63 ++++++++++++++++++++++++---- 6 files changed, 142 insertions(+), 19 deletions(-) diff --git a/src/gameplay/actions/attackPart.java b/src/gameplay/actions/attackPart.java index 9310f6f..da85585 100644 --- a/src/gameplay/actions/attackPart.java +++ b/src/gameplay/actions/attackPart.java @@ -29,6 +29,7 @@ public class attackPart { this.knockbackOnHit = knockbackOnHit; this.knockbackOnHit = knockbackOnBlock; this.frames = frames; + if(this.frames.length >= 1) {this.frames[this.frames.length-1].setLastFrameOfHit(true);} this.hasHit = false; } @@ -46,6 +47,7 @@ public class attackPart { this.knockbackOnHit = 0.0; this.knockbackOnBlock = 0.0; this.hasHit = false; + if(this.frames.length >= 1) {this.frames[this.frames.length -1].setLastFrameOfHit(true);} } public boolean hasHit() { @@ -111,4 +113,15 @@ public class attackPart { public void setKnockbackOnBlock(double 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(); + } } diff --git a/src/gameplay/entities/Character.java b/src/gameplay/entities/Character.java index f8d8462..0f50432 100644 --- a/src/gameplay/entities/Character.java +++ b/src/gameplay/entities/Character.java @@ -4,6 +4,8 @@ import gameplay.actions.*; import gameplay.frames.Frame; import gameplay.frames.nextFrameBuffer; +import java.util.ArrayList; + /** * Character class, which is a sub-class of an entity * @author Victor @@ -11,6 +13,7 @@ import gameplay.frames.nextFrameBuffer; */ public class Character extends Entity { private static int maxHP; + private static int currentHP; /** * 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[] forwardWalkFrames; private static Frame[] backWalkFrames; + + private ArrayList nextAttackParts; /** * 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() { super(); 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) { super(posx, posy, f); this.maxHP = maxHP; - this.status = Status.STANDING; + this.status = Status.NORMAL; + this.currentHP = this.maxHP; } + public void setMaxHP(int HP) { this.maxHP = HP; @@ -152,4 +160,34 @@ public class Character extends Entity { public static void setBackWalkFrames(Frame[] backWalkFrames) { Character.backWalkFrames = backWalkFrames; } + + public ArrayList getNextAttackParts() { + return nextAttackParts; + } + + public void setNextAttackParts(ArrayList nextAttackParts) { + this.nextAttackParts = new ArrayList(nextAttackParts); + } + + public void setAttackPartsArray(attackPart[] parts) { + this.nextAttackParts = new ArrayList(); + 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; + } } diff --git a/src/gameplay/entities/Status.java b/src/gameplay/entities/Status.java index 2f565a6..dd45ec4 100644 --- a/src/gameplay/entities/Status.java +++ b/src/gameplay/entities/Status.java @@ -1,5 +1,5 @@ package gameplay.entities; public enum Status { - STANDING, JUMPING, KNOCKEDDOWN, BLOCKING + NORMAL, JUMPING, KNOCKEDDOWN, BLOCKING, FALLING, HITINAIR } diff --git a/src/gameplay/frames/Frame.java b/src/gameplay/frames/Frame.java index a6161b1..50ea8b9 100644 --- a/src/gameplay/frames/Frame.java +++ b/src/gameplay/frames/Frame.java @@ -23,7 +23,7 @@ public class Frame { private boolean jumpCancellable; private boolean moveCancellable; private boolean isDashCancellable; - private boolean firstFrameOfHit; + private boolean lastFrameOfHit; public Frame() { this.setMove_y(0.0); @@ -38,7 +38,7 @@ public class Frame { this.jumpCancellable = true; this.moveCancellable = true; this.isDashCancellable = true; - this.firstFrameOfHit = false; + this.lastFrameOfHit = false; } public Frame(Double move_y, Double move_x, ArrayList passHitBox, ArrayList actHitBox, @@ -57,7 +57,7 @@ public class Frame { this.jumpCancellable = jumpCancellable; this.moveCancellable = moveCancellable; this.isDashCancellable = isDashCancellable; - this.firstFrameOfHit = false; + this.lastFrameOfHit = false; } /* @@ -149,11 +149,13 @@ public class Frame { this.pushHitBox = pushHitBox; } - public boolean isFirstFrameOfHit() { - return firstFrameOfHit; + public boolean islastFrameOfHit() { + return lastFrameOfHit; } - public void setFirstFrameOfHit(boolean firstFrameOfHit) { - this.firstFrameOfHit = firstFrameOfHit; + public void setLastFrameOfHit(boolean lastFrameOfHit) { + this.lastFrameOfHit = lastFrameOfHit; } + + } diff --git a/src/gameplay/hitboxes/HitBox.java b/src/gameplay/hitboxes/HitBox.java index 1fa984c..55c706d 100644 --- a/src/gameplay/hitboxes/HitBox.java +++ b/src/gameplay/hitboxes/HitBox.java @@ -96,5 +96,28 @@ public class HitBox { 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; + } } \ No newline at end of file diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 4b12082..8cb017c 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -3,12 +3,17 @@ package gameplay.match; import engine.input.Button; import engine.input.GamepadInput; import gameplay.actions.Attack; +import gameplay.actions.attackPart; import gameplay.entities.Status; +import gameplay.hitboxes.Active_HitBox; +import gameplay.hitboxes.Passive_HitBox; import gameplay.input.InputBuffer; import gameplay.entities.Character; import gameplay.input.Inputs; import gameplay.input.ButtonIG; +import java.util.ArrayList; + import static org.lwjgl.glfw.GLFW.*; /** @@ -25,7 +30,6 @@ public class match { private int timer; private InputBuffer inputsP1, inputsP2; - private int hpP1, hpP2; private int roundsWonP1, roundsWonP2; private Character p1, p2; //characters of player 1 and 2 @@ -45,8 +49,6 @@ public class match { this.inputsP2 = new InputBuffer(inputBufferSize); this.p1 = p1; this.p2 = p2; - this.hpP1 = p1.getMaxHP(); - this.hpP2 = p2.getMaxHP(); this.roundsWonP1 = 0; this.roundsWonP2 = 0; } @@ -58,8 +60,6 @@ public class match { this.timer = 99; this.inputsP1 = 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.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 case 10: - if(this.hpP1 <= 0 && hpP2 <= 0) { ac(11);} - else if(this.hpP1 <= 0) { ac(12);} - else if(this.hpP2 <= 0) { ac(13);} + if(p1.getCurrentHP() <= 0 && p2.getCurrentHP() <= 0) { ac(11);} + else if(p1.getCurrentHP() <= 0) { ac(12);} + else if(p2.getCurrentHP() <= 0) { ac(13);} else { ac(20);} break; @@ -207,6 +207,14 @@ public class match { inputsP2.recordInputsFromGamepad(gamepad2, p2.getPosX() <= p1.getPosX()); handleInputs(p1, inputsP1); 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) { c.clearNextFrames(); c.addNextFramesList(atk.getFrame()); + c.setAttackPartsArray(atk.getParts()); actionSet = true; } 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 activeP1 = new ArrayList(p1.getCurrentframe().getActHitBox()); + ArrayList passiveP2 = new ArrayList(p2.getCurrentframe().getPassHitBox()); + ArrayList aP = new ArrayList(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); + } + + } + } + } + } + }