X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGameProc.java;h=8910d498670f0ba295af780595406fa815289927;hp=da028621decbfd3cd09fde9ec7549744993944f6;hb=99a56427db13dd0ecd025e433a438b77245cb739;hpb=e31e819b4fc6afdc3612e0ada5066dab638e89ac diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index da02862..8910d49 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -19,35 +19,31 @@ import java.util.ArrayList; public class GameProc implements Serializable { - public static double RUN_TIME = 0; + static boolean DO_UPD = false; + static int UPD_X = -1, UPD_Y = -1; - public static boolean DO_UPD = false; - public static int UPD_X = -1, UPD_Y = -1; + public transient GameWorld world; + public transient GameRenderer renderer; + public transient GamePhysics physics; public Player player; - public ArrayList mobs; public ArrayList drops; - public transient GameWorld world; - public transient GameRenderer renderer; - public transient GamePhysics physics; - - public int curX, curY; - public int slot; - public int ctrlMode; - public int creativeScroll, maxCreativeScroll; - public int blockDmg = 0; - public boolean isTouchDown, isKeyDown, swim; - public int touchDownX, touchDownY, keyDownCode; - public int touchDownBtn; + public boolean isTouchDown, isKeyDown; + public int ctrlMode, touchDownX, touchDownY, touchDownBtn, keyDownCode; public long touchDownTime; + int curX, curY; + int creativeScroll, maxCreativeScroll; + int blockDmg = 0; + + public GameProc(int gameMode) { world = new GameWorld(); world.generate(1024, 256); - player = new Player(world.getSpawnPoint(), gameMode); + player = new Player(world, gameMode); drops = new ArrayList(); mobs = new ArrayList(); for (int i = 0; i < 16; i++) { @@ -78,16 +74,16 @@ public class GameProc implements Serializable { private boolean isAutoselectable(int x, int y) { return (world.getForeMap(x, y) > 0 && - GameItems.getBlock(world.getForeMap(x, y)).coll); + GameItems.getBlock(world.getForeMap(x, y)).hasCollision()); } private void moveCursor() { int pastX = curX, pastY = curY; if (ctrlMode == 0 && CaveGame.TOUCH) { - curX = (int) (player.pos.x + player.texWidth / 2) / 16; - if (player.dir == 0) curX--; + curX = player.getMapX(); + if (player.getDir() == 0) curX--; else curX++; - curY = (int) (player.pos.y + player.texWidth) / 16; + curY = (int) (player.pos.y + player.getWidth()) / 16; if (!isAutoselectable(curX, curY)) { curY++; } @@ -95,7 +91,7 @@ public class GameProc implements Serializable { curY++; } if (!isAutoselectable(curX, curY)) { - if (player.dir == 0) curX++; + if (player.getDir() == 0) curX++; else curX--; } } else if (!CaveGame.TOUCH) { @@ -114,10 +110,10 @@ public class GameProc implements Serializable { if (curY < 0) curY = 0; if (curY >= world.getHeight()) curY = world.getHeight() - 1; if (ctrlMode == 1) { - if (curX * 16 + 8 < player.pos.x + player.texWidth / 2) - player.dir = 0; - if (curX * 16 + 8 > player.pos.x + player.texWidth / 2) - player.dir = 1; + if (curX * 16 + 8 < player.pos.x + player.getWidth() / 2) + player.setDir(0); + if (curX * 16 + 8 > player.pos.x + player.getWidth() / 2) + player.setDir(1); } } @@ -137,15 +133,15 @@ public class GameProc implements Serializable { if (world.getForeMap(x, y) == 8 || world.getForeMap(x, y) == 60) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); updateBlock(x, y + 2); } else if (GameItems.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, 68); - } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { if (world.getForeMap(x + 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) || + (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) || (GameItems.isWater(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 61)) { world.setForeMap(x + 1, y, 61); updateBlock(x + 1, y + 1); @@ -156,7 +152,7 @@ public class GameProc implements Serializable { world.setForeMap(x + 1, y, 8); if (world.getForeMap(x - 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) || + (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) || (GameItems.isWater(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 61)) { world.setForeMap(x - 1, y, 61); updateBlock(x - 1, y + 1); @@ -170,15 +166,15 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 61) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); updateBlock(x, y + 2); } else if (GameItems.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, 68); - } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { if (world.getForeMap(x + 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) || + (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) || (GameItems.isWater(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 62)) { world.setForeMap(x + 1, y, 62); updateBlock(x + 1, y + 1); @@ -188,7 +184,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) || + (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) || (GameItems.isWater(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 62)) { world.setForeMap(x - 1, y, 62); updateBlock(x - 1, y + 1); @@ -201,15 +197,15 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 62) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); updateBlock(x, y + 2); } else if (GameItems.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, 68); - } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { if (world.getForeMap(x + 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y)))) { + (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y)))) { world.setForeMap(x + 1, y, 63); updateBlock(x + 1, y + 1); } else if (GameItems.isLava(world.getForeMap(x + 1, y))) { @@ -218,7 +214,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y)))) { + (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y)))) { world.setForeMap(x - 1, y, 63); updateBlock(x - 1, y + 1); } else if (GameItems.isLava(world.getForeMap(x - 1, y))) { @@ -230,7 +226,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 63) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 61 && world.getForeMap(x, y + 1) <= 63) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); updateBlock(x, y + 2); } else if (GameItems.isLava(world.getForeMap(x, y + 1))) { @@ -256,14 +252,14 @@ public class GameProc implements Serializable { if (world.getForeMap(x, y) == 9 || world.getForeMap(x, y) == 64) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); updateBlock(x, y + 2); } else if (GameItems.isWater(world.getForeMap(x, y + 1))) { world.setForeMap(x, y + 1, 1); - } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { if (world.getForeMap(x + 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) || + (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) || (GameItems.isLava(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 65)) { world.setForeMap(x + 1, y, 65); updateBlock(x + 1, y + 1); @@ -272,7 +268,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) || + (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) || (GameItems.isLava(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 65)) { world.setForeMap(x - 1, y, 65); updateBlock(x - 1, y + 1); @@ -284,14 +280,14 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 65) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); updateBlock(x, y + 2); } else if (GameItems.isWater(world.getForeMap(x, y + 1))) { world.setForeMap(x, y + 1, 1); - } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { if (world.getForeMap(x + 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y))) || + (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y))) || (GameItems.isLava(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 66)) { world.setForeMap(x + 1, y, 66); updateBlock(x + 1, y + 1); @@ -300,7 +296,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y))) || + (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y))) || (GameItems.isLava(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 66)) { world.setForeMap(x - 1, y, 66); updateBlock(x - 1, y + 1); @@ -312,14 +308,14 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 66) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); updateBlock(x, y + 2); } else if (GameItems.isWater(world.getForeMap(x, y + 1))) { world.setForeMap(x, y + 1, 1); - } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + } else if (GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { if (world.getForeMap(x + 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x + 1, y)).coll && !GameItems.isFluid(world.getForeMap(x + 1, y)))) { + (!GameItems.getBlock(world.getForeMap(x + 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x + 1, y)))) { world.setForeMap(x + 1, y, 67); updateBlock(x + 1, y + 1); } else if (GameItems.isWater(world.getForeMap(x + 1, y))) { @@ -327,7 +323,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!GameItems.getBlock(world.getForeMap(x - 1, y)).coll && !GameItems.isFluid(world.getForeMap(x - 1, y)))) { + (!GameItems.getBlock(world.getForeMap(x - 1, y)).hasCollision() && !GameItems.isFluid(world.getForeMap(x - 1, y)))) { world.setForeMap(x - 1, y, 67); updateBlock(x - 1, y + 1); } else if (GameItems.isWater(world.getForeMap(x - 1, y))) { @@ -338,7 +334,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 67) { if (world.getForeMap(x, y + 1) == 0 || (world.getForeMap(x, y + 1) >= 65 && world.getForeMap(x, y + 1) <= 67) || - (!GameItems.getBlock(world.getForeMap(x, y + 1)).coll && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { + (!GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision() && !GameItems.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); updateBlock(x, y + 2); } else if (GameItems.isWater(world.getForeMap(x, y + 1))) { @@ -350,7 +346,7 @@ public class GameProc implements Serializable { private void updateBlock(int x, int y) { if (world.getForeMap(x, y) == 10) { - if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { world.setForeMap(x, y, 0); mobs.add(new FallingSand(x * 16, y * 16)); updateBlock(x, y - 1); @@ -358,29 +354,29 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 11) { - if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { world.setForeMap(x, y, 0); mobs.add(new FallingGravel(x * 16, y * 16)); updateBlock(x, y - 1); } } - if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).rb) { - if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) { + if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).requiresBlock()) { + if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) { world.destroyForeMap(x, y, this); updateBlock(x, y - 1); } } if (world.getForeMap(x, y) == 2) { - if (world.getForeMap(x, y - 1) > 0 && (GameItems.getBlock(world.getForeMap(x, y - 1)).coll || + if (world.getForeMap(x, y - 1) > 0 && (GameItems.getBlock(world.getForeMap(x, y - 1)).hasCollision() || GameItems.isFluid(world.getForeMap(x, y - 1)))) { world.setForeMap(x, y, 3); } } } - public void useItem(int x, int y, int id, boolean bg) { + void useItem(int x, int y, int id, boolean bg) { if (id > 0 && GameItems.getItem(id).getType() == 0) { if (!bg) world.placeToForeground(x, y, GameItems.getItem(id).getBlock()); else world.placeToBackground(x, y, GameItems.getItem(id).getBlock()); @@ -388,8 +384,6 @@ public class GameProc implements Serializable { } public void update(float delta) { - RUN_TIME += delta; - if (DO_UPD) { for (int y = UPD_Y; y < UPD_Y + 16; y++) for (int x = UPD_X; x < UPD_X + 16; x++) { @@ -410,7 +404,9 @@ public class GameProc implements Serializable { if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) { if ((world.getForeMap(curX, curY) > 0 && GameItems.getBlock(world.getForeMap(curX, curY)).getHp() >= 0) || - world.getBackMap(curX, curY) > 0 && GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0) { + (world.getForeMap(curX, curY) == 0 && + world.getBackMap(curX, curY) > 0 && + GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0)) { if (player.gameMode == 0) { blockDmg++; if (world.getForeMap(curX, curY) > 0) { @@ -425,8 +421,8 @@ public class GameProc implements Serializable { } } } else { - if (world.getForeMap(curX, curY) > 0) world.setForeMap(curX, curY, 0); - else if (world.getBackMap(curX, curY) > 0) world.setBackMap(curX, curY, 0); + if (world.getForeMap(curX, curY) > 0) world.placeToForeground(curX, curY, 0); + else if (world.getBackMap(curX, curY) > 0) world.placeToBackground(curX, curY, 0); isTouchDown = false; } } @@ -434,7 +430,7 @@ public class GameProc implements Serializable { if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { if (touchDownBtn == Input.Buttons.RIGHT) { - useItem(curX, curY, player.inv[slot], true); + useItem(curX, curY, player.inv[player.invSlot], true); isTouchDown = false; } else if (touchDownY < Assets.invBar.getRegionHeight() && touchDownX > renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 &&