From 773e72fabe30f229a4893dea07b4ae87ce6bec27 Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 24 Jun 2021 15:00:14 +0200 Subject: [PATCH] =?UTF-8?q?CameraPushBack=20fonctionne=20=F0=9F=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gameplay/match/match.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index a704596..2ddc9d6 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -406,6 +406,7 @@ public class match { updatePos(p2,!p1LooksRight); pushBox(); + cameraPushBack(); if(p1LooksRight) { @@ -441,6 +442,7 @@ public class match { objP1.flipTextureWrapH(); } + engine.cameraTracking(); // Debug Hitbox Management removeHitboxEngine(); @@ -464,8 +466,6 @@ public class match { healthBarP1Obj.setCurrent(p1.getCurrentHP()); healthBarP1Obj.setMax(p1.getMaxHP()); healthBarP2Obj.setCurrent(p2.getCurrentHP()); healthBarP2Obj.setMax(p2.getMaxHP()); timerUI.setText(timer + ""); - // Tracking update - engine.cameraTracking(); timer = 99 - frameCount/60; @@ -753,6 +753,7 @@ public class match { } private static void pushBox(){ + int push = 100; 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 @@ -789,10 +790,19 @@ public class match { right = p1; rightObj = objP1; } + float leftOutOfView = left.getPosX() - (-engine.getViewXPos() - engine.getCamera().getDimension()); float rightOutOfView = (right.getPosX() + rightObj.getWidth() * rightObj.getScalingFactor()) - (-engine.getViewXPos() + engine.getCamera().getDimension()); - if(leftOutOfView < 0 && rightOutOfView > 0){ + + boolean leftOOB = left.getPosX() < -engine.getViewXPos() - engine.getCamera().getDimension(); + boolean rightOOB = right.getPosX() + rightObj.getWidth() * rightObj.getScalingFactor() > -engine.getViewXPos() + engine.getCamera().getDimension(); + + if(leftOOB && rightOutOfView - leftOutOfView > 0){ + System.out.println("Left: " + leftOutOfView); left.setPos((int) (left.getPosX() - leftOutOfView), left.getPosY()); + } + if(rightOOB && leftOutOfView + rightOutOfView < 0){ + System.out.println("Right: " + rightOutOfView); right.setPos((int) (right.getPosX() - rightOutOfView), right.getPosY()); } }