summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 193c44f)
raw | patch | inline | side by side (parent: 193c44f)
author | fredboy <fredboy@protonmail.com> | |
Fri, 3 May 2024 11:55:04 +0000 (18:55 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Fri, 3 May 2024 11:55:04 +0000 (18:55 +0700) |
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java | patch | blob | history |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 0e8af6e0eed0407b1cc3a4be057ae2dc344f5b87..70be5a6b5333214b406b0bd5cda5920551c1801a 100644 (file)
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;
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()) {
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;