From 546c7c80eb7884183a3df1db7bb5627a18396dca Mon Sep 17 00:00:00 2001 From: fredboy Date: Sat, 20 Apr 2024 01:22:59 +0700 Subject: [PATCH] Fix hitting animation --- .../ru/deadsoftware/cavedroid/game/GameInput.java | 15 ++++++++++++--- .../deadsoftware/cavedroid/game/mobs/Player.java | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index 015d81a..27c4df0 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -193,6 +193,7 @@ public class GameInput { } private void useItem(int x, int y, int id, boolean bg) { + mPlayer.startHitting(); String key = getItem(id).isBlock() ? getBlockKey(id) : getItemKey(id); if (id > 0) { if (getItem(id).isBlock()) { @@ -322,6 +323,10 @@ public class GameInput { mGameWorld.placeToForeground(mCurX, mCurY, 8); break; + case Input.Keys.GRAVE: + mMobsController.getPlayer().gameMode = (mMobsController.getPlayer().gameMode + 1) % 2; + break; + case Input.Keys.ESCAPE: case Input.Keys.BACK: GameSaver.save(mMainConfig, mDropController, mMobsController, mGameWorld); @@ -487,11 +492,15 @@ public class GameInput { } void update() { - if (mTouchedDown && mTouchDownBtn == Input.Buttons.LEFT) { - pressLMB(); - } else { + if (!mTouchedDown) { mPlayer.stopHitting(); + return; } + + if (mTouchDownBtn == Input.Buttons.LEFT) { + pressLMB(); + } + if (mTouchedDown && TimeUtils.timeSinceMillis(mTouchDownTime) > 500) { holdMB(); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java index 34232f7..49c59ee 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java @@ -173,6 +173,7 @@ public class Player extends Mob { if (hitAnim < 30f || hitAnim > 90f) { if (hitting) { + hitAnim = MathUtils.clamp(hitAnim, 30f, 90f); hitAnimDelta = -hitAnimDelta; } else { hitAnimDelta = ANIMATION_SPEED; -- 2.29.2