X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FGamePhysics.java;h=1ff603c26148f9a473cd9705bfc29ae665e1690a;hb=6a71a9abc5bc34547c0e4bea7ab19a6bee628a3c;hp=cd900d873dc1398e6b41ea492be77a87feaca25a;hpb=3fdc2291218f6d3903ce923563d1e12051690c37;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index cd900d8..1ff603c 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java @@ -20,7 +20,6 @@ import java.util.Iterator; @GameScope 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; @@ -209,6 +208,11 @@ 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) { + mob.damage(dmg); + } } mob.y = MathUtils.round(mob.getY()); @@ -219,14 +223,6 @@ 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)); @@ -256,8 +252,8 @@ public class GamePhysics { } } else { player.getVelocity().y += PL_JUMP_VELOCITY * delta; - if (player.getVelocity().y < -PL_SPEED) { - player.getVelocity().y = -PL_SPEED; + if (player.getVelocity().y < -player.getSpeed()) { + player.getVelocity().y = -player.getSpeed(); } } } else { @@ -275,7 +271,7 @@ public class GamePhysics { mobXColl(player); if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getVelocity().x != 0 && checkJump(player)) { - player.getVelocity().y = PL_JUMP_VELOCITY; + player.jump(); player.setCanJump(false); } } @@ -288,8 +284,8 @@ public class GamePhysics { mob.getVelocity().y += PL_JUMP_VELOCITY * delta; - if (mob.getVelocity().y < -PL_SPEED) { - mob.getVelocity().y = -PL_SPEED; + if (mob.getVelocity().y < -mob.getSpeed()) { + mob.getVelocity().y = -mob.getSpeed(); } } else if (!mob.isFlyMode() && mob.getVelocity().y < PL_TERMINAL_VELOCITY) { mob.getVelocity().y += gravity.y * delta; @@ -306,7 +302,7 @@ public class GamePhysics { mobXColl(mob); if (mob.canJump() && mob.getVelocity().x != 0 && checkJump(mob)) { - mob.getVelocity().y = PL_JUMP_VELOCITY; + mob.jump(); mob.setCanJump(false); } } @@ -322,7 +318,7 @@ public class GamePhysics { } } - for (Iterator it = mMobsController.getIterator(); it.hasNext(); ) { + for (Iterator it = mMobsController.getMobs().iterator(); it.hasNext(); ) { Mob mob = it.next(); mob.ai(mGameWorld, delta); mobPhy(mob, delta);