From 7f2a4800c61a4f3ee5eb214753119bd85a060cb3 Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 24 Jun 2021 03:31:54 +0200 Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20impl=C3=A9mentation=20des=20pus?= =?UTF-8?q?hBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gameplay/match/match.java | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 0ad69d9..ab524fe 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -392,13 +392,13 @@ public class match { //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); @@ -406,6 +406,8 @@ public class match { updatePos(p1,p1LooksRight); updatePos(p2,!p1LooksRight); + pushBox(); + if(p1LooksRight) { f = p1.getCurrentframe(); @@ -633,6 +635,7 @@ public class match { } } + /** * Handles a character getting hit by an attack part. * @param c the character that's getting hit @@ -736,6 +739,27 @@ public class match { else {c.setPos((int)(c.getPosX()-c.getCurrentframe().getMove_x()),(int)(c.getPosY()+c.getCurrentframe().getMove_y()));} } + private static void pushBox(){ + Push_HitBox phb1 = p1.getCurrentframe().getPushHitBox(); + Push_HitBox phb2 = p2.getCurrentframe().getPushHitBox(); + // Check if there is an intersection only on the x axis, if we push on the y axis character could get stuck in the air + boolean lookRight = p1.getPosX() < p2.getPosX(); + float sizeIntersection = lookRight ? p1.getPosX() + phb1.getPosX() + phb1.getSize_x() - p2.getPosX() - phb2.getPosX() + : p2.getPosX() + phb2.getPosX() + phb2.getSize_x() - p1.getPosX() - phb1.getPosX(); + boolean col = 0 < sizeIntersection; + boolean colV = (phb1.getPosY() + p1.getPosY() - phb1.getSize_y() < phb2.getPosY() + p2.getPosY()) && (phb1.getPosY() + p1.getPosY() > phb2.getPosY() + p2.getPosY() - phb2.getSize_y()); + if (col && colV){ + if(lookRight){ + p1.setPos((int) (p1.getPosX() - sizeIntersection/2), p1.getPosY()); + p2.setPos((int) (p2.getPosX() + sizeIntersection/2), p2.getPosY()); + } else { + p1.setPos((int) (p1.getPosX() + sizeIntersection/2), p1.getPosY()); + p2.setPos((int) (p2.getPosX() - sizeIntersection/2), p2.getPosY()); + } + } + + } + /* HITBOX DEBUG METHOD */