DEADSOFTWARE

Add pigs
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GamePhysics.java
index 8b79fe0116273791655bac30dc245e82c962371e..3bcbc9b2bcf0b4b163c2a81a9d768c9e9cf2c99b 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.math.*;
+import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.Items;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
 import ru.deadsoftware.cavecraft.game.objects.Player;
@@ -15,7 +16,7 @@ public class GamePhysics {
 
     public GamePhysics(GameProc gameProc) {
         this.gameProc = gameProc;
-        gravity = new Vector2(0,1);
+        gravity = new Vector2(0,.9f);
     }
 
     private boolean checkJump(Rectangle rect, int dir) {
@@ -26,12 +27,14 @@ public class GamePhysics {
                     bl = gameProc.world.getForeMap(
                         (int)((rect.x+(rect.width/2))/16) - 1,
                         (int)(rect.y/16)+1);
+                if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16))>0) bl=0;
                 break;
             case 1:
                 if ((int)((rect.x+(rect.width/2))/16) + 1<gameProc.world.getWidth())
                     bl = gameProc.world.getForeMap(
                         (int)((rect.x+(rect.width/2))/16) + 1,
                         (int)(rect.y/16)+1);
+                if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16))>0) bl=0;
                 break;
             default:
                 bl=0;
@@ -65,17 +68,19 @@ public class GamePhysics {
     private void playerPhy(Player pl) {
         pl.position.add(pl.moveY);
         if (checkColl(pl.getRect())) {
-            pl.flyMode = false;
-            pl.canJump = true;
             int d = -1;
             if (pl.moveY.y<0) d=1; else if (pl.moveY.y>0) d=-1;
+            if (d==-1) {
+                pl.flyMode = false;
+                pl.canJump = true;
+            }
             pl.position.y = MathUtils.round(pl.position.y);
             while (checkColl(pl.getRect())) pl.position.y+=d;
             pl.moveY.setZero();
         } else {
             pl.canJump = false;
         }
-        if (!pl.flyMode) pl.moveY.add(gravity);
+        if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity);
         pl.position.add(pl.moveX);
         if (pl.position.x<0 ||
                 pl.position.x+pl.texWidth>=gameProc.world.getWidth()*16)
@@ -91,11 +96,13 @@ public class GamePhysics {
                 while (checkColl(pl.getRect())) pl.position.x += d;
             }
         }
-
-        /*if (checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && !pl.moveX.equals(Vector2.Zero)) {
+        if (pl.position.y > gameProc.world.getHeight()*16) {
+            pl.position = gameProc.world.getSpawnPoint().cpy();
+        }
+        if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && !pl.moveX.equals(Vector2.Zero)) {
             pl.moveY.add(0, -8);
             pl.canJump = false;
-        }*/
+        }
     }
 
     private void mobPhy(Mob mob) {
@@ -124,7 +131,6 @@ public class GamePhysics {
 }
 
     public void update(float delta) {
-
         for (Mob mob : gameProc.mobs) {
             mob.ai();
             mobPhy(mob);