X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGamePhysics.java;h=e38e3b0b3ef12e858795cb204a4d93cd9e271744;hb=3fb849898964a43a51cc6483ac72f5e3abbd01f0;hp=244875d9adecb9fbb33c8e2e4882982d5aa01b76;hpb=75e8bbe4c9dceaabd8bb7e7976ad9052cfb0a968;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 244875d..e38e3b0 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -1,12 +1,12 @@ package ru.deadsoftware.cavecraft.game; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Intersector; 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.game.mobs.Mob; +import ru.deadsoftware.cavecraft.game.objects.Drop; import ru.deadsoftware.cavecraft.game.objects.Player; import java.util.Iterator; @@ -29,11 +29,11 @@ public class GamePhysics { switch (dir) { case 0: bl = gameProc.world.getForeMap((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16)); - if (checkColl(new Rectangle(rect.x+rect.width/2, rect.y-18, rect.width, rect.height))) bl=0; + if (checkColl(new Rectangle(rect.x-8, rect.y-18, rect.width, rect.height))) bl=0; break; case 1: bl = gameProc.world.getForeMap((int)((rect.x+rect.width+8)/16),(int)((rect.y+rect.height-8)/16)); - if (checkColl(new Rectangle(rect.x+rect.width/2, rect.y-18, rect.width, rect.height))) bl=0; + if (checkColl(new Rectangle(rect.x+rect.width+8, rect.y-18, rect.width, rect.height))) bl=0; break; default: bl=0; @@ -67,6 +67,16 @@ public class GamePhysics { return gameProc.world.getForeMap((int)(rect.x+rect.width/2)/16, (int)(rect.y+rect.height/8*7)/16); } + private void dropPhy(Drop drop) { + if (drop.move.y < 9) drop.move.y += gravity.y/4; + drop.position.add(drop.move); + drop.position.y = MathUtils.round(drop.position.y); + while (checkColl(drop.getRect())) { + drop.position.y--; + drop.move.y = 0; + } + } + private void playerPhy(Player pl) { pl.position.add(pl.moveY); if (checkColl(pl.getRect())) { @@ -84,14 +94,17 @@ public class GamePhysics { } if (Items.isFluid(getBlock(pl.getRect()))) { + if (CaveGame.TOUCH && pl.moveX.x!=0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; if (!gameProc.swim) { - if (!pl.flyMode && pl.moveY.y < 9) pl.moveY.add(gravity.x / 2, gravity.y / 2); - if (!pl.flyMode && pl.moveY.y > 9) pl.moveY.add(0, -.9f); + if (!pl.flyMode && pl.moveY.y < 4.5f) pl.moveY.add(gravity.x / 4, gravity.y / 4); + if (!pl.flyMode && pl.moveY.y > 4.5f) pl.moveY.add(0, -1f); } else { pl.moveY.add(0, -.5f); if (pl.moveY.y<-3) pl.moveY.y = -3; } - } else if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity); + } else { + if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity); + } pl.position.add(pl.moveX); if (checkColl(pl.getRect())) { @@ -167,15 +180,22 @@ public class GamePhysics { } public void update(float delta) { - for (Mob mob : gameProc.mobs) { - mob.ai(); - mobPhy(mob); + for (Iterator it = gameProc.drops.iterator(); it.hasNext(); ) { + Drop drop = it.next(); + dropPhy(drop); + if (Intersector.overlaps(drop.getRect(), gameProc.player.getRect())) + drop.pickUpDrop(gameProc.player); + if (drop.pickedUp) it.remove(); } + for (Iterator it = gameProc.mobs.iterator(); it.hasNext();) { - Mob m = it.next(); - if (m.dead) + Mob mob = it.next(); + mob.ai(); + mobPhy(mob); + if (mob.dead) it.remove(); } + playerPhy(gameProc.player); gameProc.renderer.camera.position.set(