From: fred-boy Date: Sat, 21 Apr 2018 18:22:03 +0000 (+0700) Subject: TP player when crossing world's edge X-Git-Tag: alpha0.2.1~9 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=e0aa1520178df544807f3e803b4b6169346b07fb;p=cavedroid.git TP player when crossing world's edge --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index b20575a..07587e6 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -24,7 +24,6 @@ public class GamePhysics { private boolean checkJump(Rectangle rect, int dir) { int bl = 0; - if (rect.x<0) rect.x-=16; switch (dir) { case 0: bl = gameProc.world.getForeMap( @@ -95,6 +94,8 @@ public class GamePhysics { while (checkColl(pl.getRect())) pl.position.x += d; } } + if (pl.position.x+pl.texWidth/2<0) pl.position.x+=gameProc.world.getWidth()*16; + if (pl.position.x+pl.texWidth/2>gameProc.world.getWidth()*16) pl.position.x-=gameProc.world.getWidth()*16; if (pl.position.y > gameProc.world.getHeight()*16) { pl.position = gameProc.world.getSpawnPoint().cpy(); } @@ -118,6 +119,8 @@ public class GamePhysics { } mob.moveY.add(gravity); mob.position.add(mob.moveX); + 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; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index f3ea4ac..2cdc302 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -67,7 +67,6 @@ public class GameProc { if (player.dir == 0) cursorX++; else cursorX--; } - if (player.position.x<0) cursorX--; } else if (!CaveGame.TOUCH){ cursorX = (int)(Gdx.input.getX()* (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)/16; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 9440938..009d9b7 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -92,8 +92,12 @@ public class GameRenderer { } private void drawMob(Mob mob) { + mob.draw(spriteBatch, + mob.position.x-camera.position.x-gameProc.world.getWidth()*16, mob.position.y-camera.position.y); mob.draw(spriteBatch, mob.position.x-camera.position.x, mob.position.y-camera.position.y); + mob.draw(spriteBatch, + mob.position.x-camera.position.x+gameProc.world.getWidth()*16, mob.position.y-camera.position.y); } private void drawPlayer(Player pl) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java index ab89dd7..daa00c0 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java @@ -32,10 +32,10 @@ public class GameWorld { int map = 0; try { if (x<0) { - x = x % (getWidth()-1)-1; + x = x % (getWidth()); x = getWidth()- Math.abs(x); } else if (x>0) { - x = x % (getWidth()-1)+1; + x = x % (getWidth()); } map = foreMap[x][y]; } catch (ArrayIndexOutOfBoundsException e) { @@ -47,10 +47,10 @@ public class GameWorld { public void setForeMap(int x, int y, int value) { try { if (x<0) { - x = x % (getWidth()-1)-1; + x = x % (getWidth()); x = getWidth()- Math.abs(x); } else if (x>0) { - x = x % (getWidth()-1)+1; + x = x % (getWidth()); } foreMap[x][y] = value; } catch (ArrayIndexOutOfBoundsException e) { @@ -62,10 +62,10 @@ public class GameWorld { int map = 0; try { if (x<0) { - x = x % (getWidth()-1)-1; + x = x % (getWidth()); x = getWidth()- Math.abs(x); } else if (x>0) { - x = x % (getWidth()-1)+1; + x = x % (getWidth()); } map = backMap[x][y]; } catch (ArrayIndexOutOfBoundsException e) { @@ -77,10 +77,10 @@ public class GameWorld { public void setBackMap(int x, int y, int value) { try { if (x<0) { - x = x % (getWidth()-1)-1; + x = x % (getWidth()); x = getWidth()- Math.abs(x); } else if (x>0) { - x = x % (getWidth()-1)+1; + x = x % (getWidth()); } backMap[x][y] = value; } catch (ArrayIndexOutOfBoundsException e) {