X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGamePhysics.java;h=c335908a26b41ce274c4e72ec58f80e01f553a19;hb=d5e611f9fb8deb93a9403b41f17dc000b9fa63ce;hp=07587e688129906f76e67401b01f8afd15b01778;hpb=6ab2a53526f16de139d39a59c3d800e5f3013c68;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 07587e6..c335908 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -5,7 +5,6 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.CaveGame; -import ru.deadsoftware.cavecraft.Items; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -23,21 +22,15 @@ public class GamePhysics { } private boolean checkJump(Rectangle rect, int dir) { - int bl = 0; + int bl; switch (dir) { case 0: - 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; - if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16)-1)>0) bl=0; + bl = gameProc.world.getForeMap((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16)); + if (checkColl(new Rectangle(rect.x-16, rect.y-18, rect.width, rect.height))) bl=0; break; case 1: - 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; - if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16)-1)>0) bl=0; + bl = gameProc.world.getForeMap((int)((rect.x+rect.width+8)/16),(int)((rect.y+rect.height-8)/16)); + if (checkColl(new Rectangle(rect.x+16, rect.y-18, rect.width, rect.height))) bl=0; break; default: bl=0; @@ -70,7 +63,7 @@ public class GamePhysics { pl.position.add(pl.moveY); if (checkColl(pl.getRect())) { int d = -1; - if (pl.moveY.y<0) d=1; else if (pl.moveY.y>0) d=-1; + if (pl.moveY.y<0) d=1; if (d==-1) { pl.flyMode = false; pl.canJump = true; @@ -108,24 +101,39 @@ public class GamePhysics { private void mobPhy(Mob mob) { mob.position.add(mob.moveY); if (checkColl(mob.getRect())) { - mob.canJump = true; int d = -1; - if (mob.moveY.y<0) d=1; else if (mob.moveY.y>0) d=-1; + if (mob.moveY.y<0) d=1; + if (d==-1) mob.canJump = true; mob.position.y = MathUtils.round(mob.position.y); while (checkColl(mob.getRect())) mob.position.y+=d; mob.moveY.setZero(); } else { mob.canJump = false; } - mob.moveY.add(gravity); + if (mob.moveY.y<18) mob.moveY.add(gravity); mob.position.add(mob.moveX); + if (checkColl(mob.getRect())) { + if (mob.canJump) { + mob.position.y-=8; + } + if (checkColl(mob.getRect())) { + if (mob.canJump) mob.position.y+=8; + int d = 0; + if (mob.moveX.x < 0) d = 1; + else if (mob.moveX.x > 0) d = -1; + mob.position.x = MathUtils.round(mob.position.x); + while (checkColl(mob.getRect())) mob.position.x += d; + if (mob.canJump) mob.changeDir(); + } + } if (mob.position.x+mob.width/2<0) mob.position.x+=gameProc.world.getWidth()*16; if (mob.position.x+mob.width/2>gameProc.world.getWidth()*16) mob.position.x-=gameProc.world.getWidth()*16; - if (checkColl(mob.getRect())) { - int d = 0; - if (mob.moveX.x<0) d=1; else if (mob.moveX.x>0) d=-1; - mob.position.x = MathUtils.round(mob.position.x); - while (checkColl(mob.getRect())) mob.position.x+=d; + if (mob.position.y > gameProc.world.getHeight()*16) { + mob.position.y = 0; + } + if (checkJump(mob.getRect(), mob.dir) && mob.canJump && !mob.moveX.equals(Vector2.Zero)) { + mob.moveY.add(0, -8); + mob.canJump = false; } }