X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FGamePhysics.java;h=38253948725eae1e5fbf6c874509d1d7fe13f771;hb=e7a1e15a93abaafa8e2e0435336483a198cc697c;hp=7d13744d9260f7cfb86774641ff70e57c0d67930;hpb=4d25745edeb53f87a49dbde125df53de869d6fd0;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index 7d13744..3825394 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); @@ -176,6 +177,14 @@ 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 + // 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); + } else { mob.y += 1; mob.setCanJump(checkColl(mob)); @@ -197,20 +206,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; } } @@ -231,17 +240,17 @@ public class GamePhysics { private void mobPhy(Mob mob, float delta) { if (mob.getType() == Mob.Type.MOB && GameItems.isFluid(getBlock(mob))) { - if (mob.getVelocity().y > 540) { - mob.getVelocity().add(0, -5.4f); + if (mob.getVelocity().y > 32f) { + mob.getVelocity().y -= mob.getVelocity().y * 32f * delta; } - mob.getVelocity().add(0, -30f); + mob.getVelocity().y += PL_JUMP_VELOCITY * delta; - if (mob.getVelocity().y < -180) { - mob.getVelocity().y = -180; + if (mob.getVelocity().y < -PL_SPEED) { + mob.getVelocity().y = -PL_SPEED; } - } else if (!mob.isFlyMode() && mob.getVelocity().y < 1080) { - mob.getVelocity().add(gravity); + } else if (!mob.isFlyMode() && mob.getVelocity().y < PL_TERMINAL_VELOCITY) { + mob.getVelocity().y += gravity.y * delta; } mob.y += mob.getVelocity().y * delta; @@ -255,7 +264,7 @@ public class GamePhysics { mobXColl(mob); if (mob.canJump() && mob.getVelocity().x != 0 && checkJump(mob)) { - mob.getVelocity().add(0, -480); + mob.getVelocity().y += PL_JUMP_VELOCITY; mob.setCanJump(false); } }