DEADSOFTWARE

Add player health
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GamePhysics.java
index cd900d873dc1398e6b41ea492be77a87feaca25a..4127b6dba4ee9fbb6af1b90d3c47390591467d9f 100644 (file)
@@ -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);
         }
     }