From 4d25745edeb53f87a49dbde125df53de869d6fd0 Mon Sep 17 00:00:00 2001 From: fredboy Date: Mon, 15 Apr 2024 19:38:12 +0700 Subject: [PATCH] Fix jumping and ui controls --- android/build.gradle | 3 +++ .../ru/deadsoftware/cavedroid/AndroidLauncher.java | 1 - .../src/ru/deadsoftware/cavedroid/game/GameInput.java | 6 +++++- .../ru/deadsoftware/cavedroid/game/GamePhysics.java | 9 +++++---- .../ru/deadsoftware/cavedroid/game/GameRenderer.java | 11 ++++++----- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 106767b..f0e5e52 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -46,6 +46,9 @@ android { applicationIdSuffix ".debug" } } + buildFeatures { + buildConfig true + } } diff --git a/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java b/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java index 3019a9e..88b6261 100644 --- a/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java +++ b/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java @@ -4,7 +4,6 @@ import android.content.pm.PackageManager; import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; -import com.badlogic.gdx.backends.android.BuildConfig; public class AndroidLauncher extends AndroidApplication { @Override diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index 3da4e2e..7221d16 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -68,7 +68,7 @@ public class GameInput { if (checkSwim()) { mPlayer.swim = true; } else if (mPlayer.canJump()) { - mPlayer.getVelocity().add(0, -180); + mPlayer.getVelocity().add(0, GamePhysics.PL_JUMP_VELOCITY); } else if (!mPlayer.isFlyMode() && mPlayer.gameMode == 1) { mPlayer.setFlyMode(true); mPlayer.getVelocity().y = 0; @@ -386,6 +386,10 @@ public class GameInput { } public void touchDragged(float screenX, float screenY) { + if (Math.abs(screenX - mTouchDownX) < 16 && Math.abs(screenY - mTouchDownY) < 16) { + return; + } + mDragging = true; if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY) && Math.abs(screenY - mTouchDownY) > 16) { if (insideCreativeInv(screenX, screenY)) { diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index 8d5d24c..7d13744 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java @@ -19,9 +19,10 @@ import java.util.Iterator; @GameScope public class GamePhysics { - public static final int PL_SPEED = 120; + public static final float PL_SPEED = 69.072f; + public static final float PL_JUMP_VELOCITY = -133.332f; - private final Vector2 gravity = new Vector2(0, .09f); + private final Vector2 gravity = new Vector2(0, 444.44f); private final GameWorld mGameWorld; private final MainConfig mMainConfig; @@ -210,7 +211,7 @@ public class GamePhysics { } } else { if (!player.isFlyMode() && player.getVelocity().y < 1080) { - player.getVelocity().add(gravity); + player.getVelocity().y += gravity.y * delta; } } @@ -223,7 +224,7 @@ public class GamePhysics { mobXColl(player); if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getVelocity().x != 0 && checkJump(player)) { - player.getVelocity().add(0, -480); + player.getVelocity().y = PL_JUMP_VELOCITY; player.setCanJump(false); } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java index 44ec9ba..84cea1b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java @@ -291,11 +291,12 @@ public class GameRenderer extends Renderer { drawString("Y: " + player.getUpperMapY(), 0, 20); drawString("CurX: " + mGameInput.getCurX(), 0, 30); drawString("CurY: " + mGameInput.getCurY(), 0, 40); - drawString("Mobs: " + mMobsController.getSize(), 0, 50); - drawString("Drops: " + mDropController.getSize(), 0, 60); - drawString("Block: " + GameItems.getBlockKey(mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY())), 0, 70); - drawString("Hand: " + GameItems.getItemKey(mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot]), 0, 80); - drawString("Game mode: " + player.gameMode, 0, 90); + drawString("Velocity: " + player.getVelocity(), 0, 50); + drawString("Mobs: " + mMobsController.getSize(), 0, 60); + drawString("Drops: " + mDropController.getSize(), 0, 70); + drawString("Block: " + GameItems.getBlockKey(mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY())), 0, 80); + drawString("Hand: " + GameItems.getItemKey(mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot]), 0, 90); + drawString("Game mode: " + player.gameMode, 0, 100); spriter.end(); } -- 2.29.2