From: fred-boy Date: Mon, 10 Sep 2018 10:58:28 +0000 (+0700) Subject: Add logic to some blocks and fluids X-Git-Tag: alpha0.4~92 X-Git-Url: https://deadsoftware.ru/gitweb?a=commitdiff_plain;ds=inline;h=75e8bbe4c9dceaabd8bb7e7976ad9052cfb0a968;p=cavedroid.git Add logic to some blocks and fluids --- diff --git a/android/assets/terrain.png b/android/assets/terrain.png index 73cb45a..f17c02a 100644 Binary files a/android/assets/terrain.png and b/android/assets/terrain.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index e44e005..d151ec6 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.utils.TimeUtils; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.GameScreen; +import ru.deadsoftware.cavecraft.game.mobs.FallingSand; import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.misc.AppState; import ru.deadsoftware.cavecraft.misc.Assets; @@ -61,7 +62,10 @@ public class GameInput { break; case Input.Keys.SPACE: - if (gameProc.player.canJump) { + if (Items.isFluid(gameProc.world.getForeMap((int)(gameProc.player.position.x+gameProc.player.width/2)/16, + (int)(gameProc.player.position.y+gameProc.player.height/4*3)/16))) { + gameProc.swim = true; + } else if (gameProc.player.canJump) { gameProc.player.moveY.add(0, -7); } else if (!gameProc.player.flyMode) { gameProc.player.flyMode = true; @@ -102,6 +106,7 @@ public class GameInput { case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: if (gameProc.player.flyMode) gameProc.player.moveY.setZero(); + gameProc.swim = false; break; } } @@ -118,7 +123,7 @@ public class GameInput { } public void touchUp(int screenX, int screenY, int button) { - if (gameProc.isKeyDown) { + if (CaveGame.TOUCH && gameProc.isKeyDown) { keyUp(gameProc.keyDownCode); gameProc.isKeyDown = false; } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index c335908..244875d 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -1,5 +1,6 @@ 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; @@ -8,6 +9,8 @@ import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; +import java.util.Iterator; + public class GamePhysics { public static final int PL_SPEED = 2; @@ -26,16 +29,17 @@ 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-16, rect.y-18, rect.width, rect.height))) bl=0; + if (checkColl(new Rectangle(rect.x+rect.width/2, 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+16, rect.y-18, rect.width, rect.height))) bl=0; + if (checkColl(new Rectangle(rect.x+rect.width/2, rect.y-18, rect.width, rect.height))) bl=0; break; default: bl=0; } - return (bl>0 && Items.BLOCKS.getValueAt(bl).collision); + return (bl>0 && Items.BLOCKS.getValueAt(bl).toJump() && + (rect.y+rect.height)-Items.BLOCKS.getValueAt(bl).getRect((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16)).y>8); } private boolean checkColl(Rectangle rect) { @@ -59,6 +63,10 @@ public class GamePhysics { return false; } + private int getBlock(Rectangle rect) { + return gameProc.world.getForeMap((int)(rect.x+rect.width/2)/16, (int)(rect.y+rect.height/8*7)/16); + } + private void playerPhy(Player pl) { pl.position.add(pl.moveY); if (checkColl(pl.getRect())) { @@ -74,7 +82,17 @@ public class GamePhysics { } else { pl.canJump = false; } - if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity); + + if (Items.isFluid(getBlock(pl.getRect()))) { + 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); + } 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); + pl.position.add(pl.moveX); if (checkColl(pl.getRect())) { if (pl.canJump && !pl.flyMode) pl.position.y-=8; @@ -107,10 +125,21 @@ public class GamePhysics { mob.position.y = MathUtils.round(mob.position.y); while (checkColl(mob.getRect())) mob.position.y+=d; mob.moveY.setZero(); + if (mob.getType() > 0) { + gameProc.world.setForeMap((int)mob.position.x/16, (int)mob.position.y/16, mob.getType()); + mob.position.y = -1; + mob.dead = true; + } } else { mob.canJump = false; } - if (mob.moveY.y<18) mob.moveY.add(gravity); + + if (mob.getType()==0 && Items.isFluid(getBlock(mob.getRect()))) { + if (mob.moveY.y > 9) mob.moveY.add(0, -.9f); + mob.moveY.add(0, -.5f); + if (mob.moveY.y<-3) mob.moveY.y = -3; + } else if (mob.moveY.y<18) mob.moveY.add(gravity); + mob.position.add(mob.moveX); if (checkColl(mob.getRect())) { if (mob.canJump) { @@ -142,6 +171,11 @@ public class GamePhysics { mob.ai(); mobPhy(mob); } + for (Iterator it = gameProc.mobs.iterator(); it.hasNext();) { + Mob m = it.next(); + if (m.dead) + it.remove(); + } playerPhy(gameProc.player); gameProc.renderer.camera.position.set( diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 4b841bd..5d20e62 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -5,6 +5,8 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.utils.TimeUtils; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.GameScreen; +import ru.deadsoftware.cavecraft.game.mobs.FallingGravel; +import ru.deadsoftware.cavecraft.game.mobs.FallingSand; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -18,6 +20,10 @@ public class GameProc implements Serializable{ public static double RUN_TIME = 0; + public static boolean DO_UPD = false; + public static int UPD_X = -1, UPD_Y = -1; + public static int FUPD_X, FUPD_Y; + public Player player; public ArrayList mobs; @@ -31,7 +37,7 @@ public class GameProc implements Serializable{ public int ctrlMode; public int creativeScroll, maxCreativeScroll; - public boolean isTouchDown, isKeyDown; + public boolean isTouchDown, isKeyDown, swim; public int touchDownX, touchDownY, keyDownCode; public int touchDownButton; public long touchDownTime; @@ -110,9 +116,283 @@ public class GameProc implements Serializable{ } } + private void updateFluids(int x, int y) { + if (Items.isWater(world.getForeMap(x, y)) && world.getForeMap(x, y)!=8) { + if ((!Items.isWater(world.getForeMap(x-1,y)) || + (Items.isWater(world.getForeMap(x,y)) && world.getForeMap(x-1, y)>=world.getForeMap(x, y))) && + (!Items.isWater(world.getForeMap(x+1,y)) || + (Items.isWater(world.getForeMap(x,y)) && world.getForeMap(x+1, y)>=world.getForeMap(x, y)))){ + world.setForeMap(x, y, world.getForeMap(x, y)+1); + if (world.getForeMap(x, y)>62) world.setForeMap(x, y, 0); + } + } + + if (world.getForeMap(x, y) == 8) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,8); + updateBlock(x, y+2); + } else if (Items.isLava(world.getForeMap(x, y+1))) { + if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4); + else world.setForeMap(x, y+1, 66); + } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + if (world.getForeMap(x+1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || + (Items.isWater(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>60)) { + world.setForeMap(x+1,y,60); + updateBlock(x+1, y+1); + } else if (Items.isLava(world.getForeMap(x+1, y))) { + if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4); + else world.setForeMap(x+1, y, 66); + } else if (world.getForeMap(x+1, y)==60 && world.getForeMap(x+2, y)==8) world.setForeMap(x+1, y, 8); + + if (world.getForeMap(x-1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || + (Items.isWater(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>60)) { + world.setForeMap(x-1,y,60); + updateBlock(x-1, y+1); + } else if (Items.isLava(world.getForeMap(x-1, y))) { + if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4); + else world.setForeMap(x-1, y, 66); + } else if (world.getForeMap(x-1, y)==60 && world.getForeMap(x-2, y)==8) world.setForeMap(x-1, y, 8); + } + return; + } + if (world.getForeMap(x, y) == 60) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,8); + updateBlock(x, y+2); + } else if (Items.isLava(world.getForeMap(x, y+1))) { + if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4); + else world.setForeMap(x, y+1, 66); + } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + if (world.getForeMap(x+1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || + (Items.isWater(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>61)){ + world.setForeMap(x+1,y,61); + updateBlock(x+1, y+1); + } else if (Items.isLava(world.getForeMap(x+1, y))) { + if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4); + else world.setForeMap(x+1, y, 66); + } + + if (world.getForeMap(x-1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || + (Items.isWater(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>61)){ + world.setForeMap(x-1,y,61); + updateBlock(x-1, y+1); + } else if (Items.isLava(world.getForeMap(x-1, y))) { + if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4); + else world.setForeMap(x-1, y, 66); + } + } + return; + } + if (world.getForeMap(x, y) == 61) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,8); + updateBlock(x, y+2); + } else if (Items.isLava(world.getForeMap(x, y+1))) { + if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4); + else world.setForeMap(x, y+1, 66); + } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + if (world.getForeMap(x+1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ){ + world.setForeMap(x+1,y,62); + updateBlock(x+1, y+1); + } else if (Items.isLava(world.getForeMap(x+1, y))) { + if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4); + else world.setForeMap(x+1, y, 66); + } + + if (world.getForeMap(x-1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ){ + world.setForeMap(x-1,y,62); + updateBlock(x-1, y+1); + } else if (Items.isLava(world.getForeMap(x-1, y))) { + if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4); + else world.setForeMap(x-1, y, 66); + } + } + return; + } + if (world.getForeMap(x, y) == 62) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,8); + updateBlock(x, y+2); + } else if (Items.isLava(world.getForeMap(x, y+1))) { + if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4); + else world.setForeMap(x, y+1, 66); + } + return; + } + + if (Items.isLava(world.getForeMap(x, y)) && world.getForeMap(x, y)!=9) { + if ((!Items.isLava(world.getForeMap(x-1,y)) || + (Items.isLava(world.getForeMap(x,y)) && world.getForeMap(x-1, y)>=world.getForeMap(x, y))) && + (!Items.isLava(world.getForeMap(x+1,y)) || + (Items.isLava(world.getForeMap(x,y)) && world.getForeMap(x+1, y)>=world.getForeMap(x, y)))){ + world.setForeMap(x, y, world.getForeMap(x, y)+1); + if (world.getForeMap(x, y)>65) world.setForeMap(x, y, 0); + } + } + + if (world.getForeMap(x, y) == 9) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,9); + updateBlock(x, y+2); + } else if (Items.isWater(world.getForeMap(x, y+1))) { + world.setForeMap(x, y+1, 1); + } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + if (world.getForeMap(x+1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || + (Items.isLava(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>63)) { + world.setForeMap(x+1,y,63); + updateBlock(x+1, y+1); + } else if (Items.isWater(world.getForeMap(x+1, y))) { + world.setForeMap(x+1, y, 1); + } + + if (world.getForeMap(x-1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || + (Items.isLava(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>63)) { + world.setForeMap(x-1,y,63); + updateBlock(x-1, y+1); + } else if (Items.isWater(world.getForeMap(x-1, y))) { + world.setForeMap(x-1, y, 1); + } + } + return; + } + if (world.getForeMap(x, y) == 63) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,9); + updateBlock(x, y+2); + } else if (Items.isWater(world.getForeMap(x, y+1))) { + world.setForeMap(x, y+1, 1); + } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + if (world.getForeMap(x+1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || + (Items.isLava(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>64)){ + world.setForeMap(x+1,y,64); + updateBlock(x+1, y+1); + } else if (Items.isWater(world.getForeMap(x+1, y))) { + world.setForeMap(x+1, y, 1); + } + + if (world.getForeMap(x-1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || + (Items.isLava(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>64)){ + world.setForeMap(x-1,y,64); + updateBlock(x-1, y+1); + } else if (Items.isWater(world.getForeMap(x-1, y))) { + world.setForeMap(x-1, y, 1); + } + } + return; + } + if (world.getForeMap(x, y) == 64) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,9); + updateBlock(x, y+2); + } else if (Items.isWater(world.getForeMap(x, y+1))) { + world.setForeMap(x, y+1, 1); + } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + if (world.getForeMap(x+1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ){ + world.setForeMap(x+1,y,65); + updateBlock(x+1, y+1); + } else if (Items.isWater(world.getForeMap(x+1, y))) { + world.setForeMap(x+1, y, 1); + } + + if (world.getForeMap(x-1, y)==0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ){ + world.setForeMap(x-1,y,65); + updateBlock(x-1, y+1); + } else if (Items.isWater(world.getForeMap(x-1, y))) { + world.setForeMap(x-1, y, 1); + } + } + return; + } + if (world.getForeMap(x, y) == 65) { + if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) || + (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) { + world.setForeMap(x,y+1,9); + updateBlock(x, y+2); + } else if (Items.isWater(world.getForeMap(x, y+1))) { + world.setForeMap(x, y+1, 1); + } + return; + } + } + + private void updateBlock(int x, int y) { + if (world.getForeMap(x, y) == 10) { + if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x,y+1)).collision) { + world.setForeMap(x, y, 0); + mobs.add(new FallingSand(x*16, y*16)); + updateBlock(x, y-1); + } + } + + if (world.getForeMap(x, y) == 11) { + if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x,y+1)).collision) { + world.setForeMap(x, y, 0); + mobs.add(new FallingGravel(x*16, y*16)); + updateBlock(x, y-1); + } + } + + if (world.getForeMap(x, y) == 59) { + if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { + world.setForeMap(x,y,0); + updateBlock(x, y-1); + } + } + + if (world.getForeMap(x, y) == 2) { + if (world.getForeMap(x, y-1)>0 && (Items.BLOCKS.getValueAt(world.getForeMap(x, y-1)).collision || + Items.isFluid(world.getForeMap(x, y-1)))) { + world.setForeMap(x, y, 3); + } + } + } + public void update(float delta) { RUN_TIME += delta; + if (DO_UPD) { + for (int y=UPD_Y; y=(int)(renderer.camera.position.x+renderer.camera.viewportWidth)/16+1) { + FUPD_X = (int) renderer.camera.position.x / 16 - 1; + FUPD_Y++; + if (FUPD_Y>=(int)(renderer.camera.position.y+renderer.camera.viewportHeight)/16+1) { + FUPD_Y = (int) renderer.camera.position.y / 16 - 1; + } + } + physics.update(delta); moveCursor(); checkCursorBounds(); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 58564bf..fac4ba2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -1,7 +1,9 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.GameScreen; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java index 65c9d03..42050e2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java @@ -37,7 +37,7 @@ public class GameWorld { x = transformX(x); map = foreMap[x][y]; } catch (ArrayIndexOutOfBoundsException e) { - Gdx.app.error("GameWorld",e.toString()); + //Gdx.app.error("GameWorld",e.toString()); } return map; } @@ -47,7 +47,7 @@ public class GameWorld { x = transformX(x); foreMap[x][y] = value; } catch (ArrayIndexOutOfBoundsException e) { - Gdx.app.error("GameWorld", e.toString()); + //Gdx.app.error("GameWorld", e.toString()); } } @@ -57,7 +57,7 @@ public class GameWorld { x = transformX(x); map = backMap[x][y]; } catch (ArrayIndexOutOfBoundsException e) { - Gdx.app.error("GameWorld",e.toString()); + //Gdx.app.error("GameWorld",e.toString()); } return map; } @@ -67,13 +67,16 @@ public class GameWorld { x = transformX(x); backMap[x][y] = value; } catch (ArrayIndexOutOfBoundsException e) { - Gdx.app.error("GameWorld", e.toString()); + //Gdx.app.error("GameWorld", e.toString()); } } public void placeToForeground(int x, int y, int value) { - if (getForeMap(x,y) == 0 || value == 0) { + if (getForeMap(x,y) == 0 || value == 0 || !Items.BLOCKS.getValueAt(getForeMap(x, y)).collision) { setForeMap(x, y, value); + GameProc.UPD_X = x-8; + GameProc.UPD_Y = y-8; + GameProc.DO_UPD = true; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/Items.java b/core/src/ru/deadsoftware/cavecraft/game/Items.java index ca0c949..9987cbe 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/Items.java +++ b/core/src/ru/deadsoftware/cavecraft/game/Items.java @@ -7,67 +7,153 @@ public class Items { public static ArrayMap BLOCKS = new ArrayMap(); + public static boolean isFluid(int bl) { + return (bl == 8 || bl == 9 || bl == 60 || bl == 61 || bl == 62 || bl == 63 || bl == 64 || bl == 65); + } + + public static boolean isWater(int bl) { + return (bl == 8 || bl == 60 || bl == 61 || bl == 62); + } + + public static boolean isLava(int bl) { + return (bl == 9 || bl == 63 || bl == 64 || bl == 65); + } + public static void loadBlocks() { + //0 BLOCKS.put("none", null); + //1 BLOCKS.put("stone", new Block(0)); + //2 BLOCKS.put("grass", new Block(1)); + //3 BLOCKS.put("dirt", new Block(2)); + //4 BLOCKS.put("cobblestone", new Block(3)); + //5 BLOCKS.put("planks", new Block(4)); + //6 BLOCKS.put("sapling", new Block(5,false,false,true)); + //7 BLOCKS.put("bedrock", new Block(6)); + //8 BLOCKS.put("water", new Block(7,false,false,true)); + //9 BLOCKS.put("lava", new Block(8,false,false,false)); + //10 BLOCKS.put("sand", new Block(9)); + //11 BLOCKS.put("gravel", new Block(10)); + //12 BLOCKS.put("gold_ore", new Block(11)); + //13 BLOCKS.put("iron_ore", new Block(12)); + //14 BLOCKS.put("coal_ore", new Block(13)); + //15 BLOCKS.put("log", new Block(14)); + //16 BLOCKS.put("leaves", new Block(15)); + //17 BLOCKS.put("sponge", new Block(16)); + //18 BLOCKS.put("glass", new Block(17,true,false,true)); + //19 BLOCKS.put("lapis_ore", new Block(18)); + //20 BLOCKS.put("lapis_block", new Block(19)); + //21 BLOCKS.put("sandstone", new Block(20)); + //22 BLOCKS.put("noteblock", new Block(21)); + //23 BLOCKS.put("bed_l", new Block(22,false,true,true)); + //24 BLOCKS.put("bed_r", new Block(23, false,true, true)); + //25 BLOCKS.put("cobweb", new Block(24,false,false,true)); + //26 BLOCKS.put("tallgrass", new Block(25,false,false,true)); + //27 BLOCKS.put("deadbush", new Block(26,false,false,true)); + //28 BLOCKS.put("brick_block", new Block(27)); + //29 BLOCKS.put("dandelion", new Block(28,false,false,true)); + //30 BLOCKS.put("rose", new Block(29,false,false,true)); + //31 BLOCKS.put("brown_mushroom", new Block(30,false,false,true)); + //32 BLOCKS.put("red_mushroom", new Block(31,false,false,true)); + //33 BLOCKS.put("wool_while", new Block(32,true,false,false)); + //34 BLOCKS.put("wool_orange", new Block(33,true,false,false)); + //35 BLOCKS.put("wool_magenta", new Block(34,true,false,false)); + //36 BLOCKS.put("wool_lightblue", new Block(35,true,false,false)); + //37 BLOCKS.put("wool_yellow", new Block(36,true,false,false)); + //38 BLOCKS.put("wool_lime", new Block(37,true,false,false)); + //39 BLOCKS.put("wool_pink", new Block(38,true,false,false)); + //40 BLOCKS.put("wool_gray", new Block(39,true,false,false)); + //41 BLOCKS.put("wool_lightgray", new Block(40,true,false,false)); + //42 BLOCKS.put("wool_cyan", new Block(41,true,false,false)); + //43 BLOCKS.put("wool_purple", new Block(42,true,false,false)); + //44 BLOCKS.put("wool_blue", new Block(43,true,false,false)); + //45 BLOCKS.put("wool_brown", new Block(44,true,false,false)); + //46 BLOCKS.put("wool_green", new Block(45,true,false,false)); + //47 BLOCKS.put("wool_red", new Block(46,true,false,false)); + //48 BLOCKS.put("wool_black", new Block(47,true,false,false)); + //49 BLOCKS.put("gold_block", new Block(48)); + //50 BLOCKS.put("iron_block", new Block(49)); + //51 BLOCKS.put("stone_slab", new Block(0, 8, 16,8, 50, true, false, true)); + //52 BLOCKS.put("double_stone_slab", new Block(51)); + //53 BLOCKS.put("sandstone_slab", new Block(0, 8, 16,8, 52, true, false, true)); + //54 BLOCKS.put("wooden_slab", new Block(0, 8, 16,8, 53, true, false, true)); + //55 BLOCKS.put("cobblestone_slab", new Block(0, 8, 16,8, 54, true, false, true)); + //56 BLOCKS.put("brick_slab", new Block(0, 8, 16,8, 55, true, false, true)); - BLOCKS.put("stonebrick", new Block(56)); - BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 57, true, false, true)); - BLOCKS.put("cactus", new Block(1, 0, 14, 16, 58, true, false, true)); + //57 + BLOCKS.put("stonebrick", new Block(64)); + //58 + BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 56, true, false, true)); + //59 + BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, true, false, true)); + //60 + BLOCKS.put("water_12", new Block(58,false,false,true)); + //61 + BLOCKS.put("water_8", new Block(59,false,false,true)); + //62 + BLOCKS.put("water_4", new Block(60,false,false,true)); + //63 + BLOCKS.put("lava_12", new Block(61,false,false,true)); + //64 + BLOCKS.put("lava_8", new Block(62,false,false,true)); + //65 + BLOCKS.put("lava_4", new Block(63,false,false,true)); + //66 + BLOCKS.put("obsidian", new Block(65)); } public static void load() { diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index 8c0f4ca..97b5481 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -23,7 +23,6 @@ public class WorldGen { int t; res[0] = mid; for (int i=1; i-3 && t<3) t=0; else t/=Math.abs(t); if (i>width-(max-min)) { @@ -33,6 +32,12 @@ public class WorldGen { res[i] = res[i-1] + t; if (res[i]max) res[i] = max; + if (i>=width/2) { + bMap [i] = 1; + if (res[i] < 60) res[i] = 60; + } else { + bMap[i] = 0; + } } return res; } @@ -73,7 +78,7 @@ public class WorldGen { rand = new RandomXS128(seed); foreMap = new int[width][height]; backMap = new int[width][height]; - hMap = genLandscape(width, height/8*3, height/8, height/2); + hMap = genLandscape(width, height/4, height/8, height/2); for (int x=0; x