From 02ca99eb904d7e9e28d636f2cffbf29d4bf03b83 Mon Sep 17 00:00:00 2001 From: fredboy Date: Mon, 15 Apr 2024 22:45:00 +0700 Subject: [PATCH] Fix swimming --- .../cavedroid/game/GamePhysics.java | 26 +++++++++++++------ .../cavedroid/game/GameRenderer.java | 12 +++++---- .../cavedroid/desktop/DesktopLauncher.java | 3 +-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index 7d13744..9149705 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java @@ -21,6 +21,7 @@ public class GamePhysics { public static final float PL_SPEED = 69.072f; public static final float PL_JUMP_VELOCITY = -133.332f; + public static final float PL_TERMINAL_VELOCITY = 1254.4f; private final Vector2 gravity = new Vector2(0, 444.44f); @@ -166,6 +167,9 @@ public class GamePhysics { if (d == -1) { mob.setCanJump(true); mob.setFlyMode(false); + + int dmg = ((int)Math.max(0f, (((mob.getVelocity().y * mob.getVelocity().y) / (2 * gravity.y)) - 48f) / 16f)); + if (dmg > 0) System.out.println("Damage: " + dmg); } mob.y = MathUtils.round(mob.getY()); @@ -176,6 +180,12 @@ public class GamePhysics { mob.getVelocity().y = 0; + + + //todo fall damage + // h = (v^2) / 2g + // dmg = max(0, (h - 48) / 32) - half of blocks fallen starting from 3 blocks height + } else { mob.y += 1; mob.setCanJump(checkColl(mob)); @@ -197,20 +207,20 @@ public class GamePhysics { player.swim = true; } if (!player.swim) { - if (!player.isFlyMode() && player.getVelocity().y < 270f) { - player.getVelocity().x += gravity.y / 4; + if (!player.isFlyMode() && player.getVelocity().y < 32f) { + player.getVelocity().y += gravity.y * delta; } - if (!player.isFlyMode() && player.getVelocity().y > 270f) { - player.getVelocity().add(0, -60f); + if (!player.isFlyMode() && player.getVelocity().y > 32f) { + player.getVelocity().y -= player.getVelocity().y * 32f * delta; } } else { - player.getVelocity().add(0, -30f); - if (player.getVelocity().y < -180) { - player.getVelocity().y = -180; + player.getVelocity().y += PL_JUMP_VELOCITY * delta; + if (player.getVelocity().y < -PL_SPEED) { + player.getVelocity().y = -PL_SPEED; } } } else { - if (!player.isFlyMode() && player.getVelocity().y < 1080) { + if (!player.isFlyMode() && player.getVelocity().y < PL_TERMINAL_VELOCITY) { player.getVelocity().y += gravity.y * delta; } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java index 84cea1b..b177779 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java @@ -292,11 +292,13 @@ public class GameRenderer extends Renderer { drawString("CurX: " + mGameInput.getCurX(), 0, 30); drawString("CurY: " + mGameInput.getCurY(), 0, 40); 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); + drawString("Swim: " + player.swim, 0, 60); + drawString("Mobs: " + mMobsController.getSize(), 0, 70); + drawString("Drops: " + mDropController.getSize(), 0, 80); + drawString("Block: " + GameItems.getBlockKey(mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY())), 0, 90); + drawString("Hand: " + GameItems.getItemKey(mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot]), 0, 100); + drawString("Game mode: " + player.gameMode, 0, 110); + drawString("Check swim: " + GameItems.isFluid(mGameWorld.getForeMap(player.getMapX(), player.getLowerMapY())), 0, 120); spriter.end(); } diff --git a/desktop/src/ru/deadsoftware/cavedroid/desktop/DesktopLauncher.java b/desktop/src/ru/deadsoftware/cavedroid/desktop/DesktopLauncher.java index cc0bb93..c30a617 100644 --- a/desktop/src/ru/deadsoftware/cavedroid/desktop/DesktopLauncher.java +++ b/desktop/src/ru/deadsoftware/cavedroid/desktop/DesktopLauncher.java @@ -9,10 +9,9 @@ class DesktopLauncher { public static void main (String[] arg) { Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setWindowIcon(Files.FileType.Internal, "icons/icon256.png", "icons/icon128.png"); -// config.setForegroundFPS(144); config.setTitle("CaveDroid"); config.setWindowedMode(960, 540); - config.useVsync(false); + config.useVsync(true); boolean touch = false; for (String anArg : arg) { -- 2.29.2