DEADSOFTWARE

Fix bg break before fg
authorfredboy <fredboy@protonmail.com>
Fri, 3 May 2024 11:55:04 +0000 (18:55 +0700)
committerfredboy <fredboy@protonmail.com>
Fri, 3 May 2024 11:55:04 +0000 (18:55 +0700)
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java

index 0e8af6e0eed0407b1cc3a4be057ae2dc344f5b87..70be5a6b5333214b406b0bd5cda5920551c1801a 100644 (file)
@@ -157,6 +157,10 @@ public class Player extends Mob {
         mVelocity.y = JUMP_VELOCITY;
     }
 
+    private boolean checkBlockCanBeHit(Block block) {
+        return !block.isNone() && block.getParams().getHitPoints() >= 0;
+    }
+
     private void hitBlock(GameWorld gameWorld, GameItemsHolder gameItemsHolder) {
         if (!hitting || !hittingWithDamage) {
             return;
@@ -165,15 +169,20 @@ public class Player extends Mob {
         final Block foregroundBlock = gameWorld.getForeMap(cursorX, cursorY);
         final Block backgroundBlock = gameWorld.getBackMap(cursorX, cursorY);
 
-        if ((!foregroundBlock.isNone() && foregroundBlock.getParams().getHitPoints() >= 0) ||
-                (foregroundBlock.isNone() && !backgroundBlock.isNone() && backgroundBlock.getParams().getHitPoints() >= 0)) {
+
+        if ((checkBlockCanBeHit(foregroundBlock)) ||
+                (foregroundBlock.isNone() && checkBlockCanBeHit(backgroundBlock))) {
             if (gameMode == 0) {
-                if (!foregroundBlock.isNone() && blockDamage >= foregroundBlock.getParams().getHitPoints()) {
-                    gameWorld.destroyForeMap(cursorX, cursorY);
-                    blockDamage = 0;
-                } else if (!backgroundBlock.isNone() && blockDamage >= backgroundBlock.getParams().getHitPoints()) {
-                    gameWorld.destroyBackMap(cursorX, cursorY);
-                    blockDamage = 0;
+                if (!foregroundBlock.isNone()) {
+                    if (blockDamage >= foregroundBlock.getParams().getHitPoints()) {
+                        gameWorld.destroyForeMap(cursorX, cursorY);
+                        blockDamage = 0;
+                    }
+                } else if (!backgroundBlock.isNone()) {
+                    if (blockDamage >= backgroundBlock.getParams().getHitPoints()) {
+                        gameWorld.destroyBackMap(cursorX, cursorY);
+                        blockDamage = 0;
+                    }
                 }
             } else {
                 if (!foregroundBlock.isNone()) {
@@ -201,9 +210,9 @@ public class Player extends Mob {
         final Block backgroundBlock = gameWorld.getBackMap(cursorX, cursorY);
         @CheckForNull final Block target;
 
-        if (!foregroundBlock.isNone() && foregroundBlock.getParams().getHitPoints() >= 0) {
+        if (checkBlockCanBeHit(foregroundBlock)) {
             target = foregroundBlock;
-        } else if (!backgroundBlock.isNone() && backgroundBlock.getParams().getHitPoints() >= 0) {
+        } else if (checkBlockCanBeHit(backgroundBlock)) {
             target = backgroundBlock;
         } else {
             target = null;