From 48e8142bcb57dd20cca7dca5064103904dcb3cb9 Mon Sep 17 00:00:00 2001 From: fredboy Date: Fri, 3 May 2024 18:55:04 +0700 Subject: [PATCH] Fix bg break before fg --- .../cavedroid/game/mobs/Player.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java index 0e8af6e..70be5a6 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java @@ -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; -- 2.29.2