From feb58daa2c3e8126871e9d4f26e978d2fc1fb01c Mon Sep 17 00:00:00 2001 From: fred-boy Date: Sun, 30 Sep 2018 21:04:05 +0700 Subject: [PATCH] Some refactor --- .../ru/deadsoftware/cavecraft/GameScreen.java | 22 +- .../cavecraft/game/GameInput.java | 156 ++++----- .../cavecraft/game/GamePhysics.java | 66 ++-- .../deadsoftware/cavecraft/game/GameProc.java | 144 ++++---- .../cavecraft/game/GameRenderer.java | 307 +++++++++--------- .../cavecraft/game/GameSaver.java | 8 +- .../cavecraft/game/GameWorld.java | 8 +- .../ru/deadsoftware/cavecraft/game/Items.java | 270 +++++++-------- .../cavecraft/game/mobs/FallingGravel.java | 2 +- .../cavecraft/game/mobs/FallingSand.java | 2 +- .../cavecraft/game/objects/Block.java | 28 +- .../cavecraft/game/objects/Item.java | 14 +- .../cavecraft/menu/MenuRenderer.java | 24 +- .../deadsoftware/cavecraft/misc/Assets.java | 109 +++---- .../cavecraft/misc/InputHandlerGame.java | 40 +-- .../cavecraft/misc/InputHandlerMenu.java | 14 +- .../deadsoftware/cavecraft/misc/Renderer.java | 35 +- 17 files changed, 636 insertions(+), 613 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java index 2704dbc..541bc8e 100644 --- a/core/src/ru/deadsoftware/cavecraft/GameScreen.java +++ b/core/src/ru/deadsoftware/cavecraft/GameScreen.java @@ -13,7 +13,7 @@ public class GameScreen implements Screen { public static int FPS; public static boolean SHOW_DEBUG = false; - private GameProc gameProc; + private GameProc gp; private Renderer renderer; private MenuRenderer menuRenderer; @@ -34,7 +34,7 @@ public class GameScreen implements Screen { } private void game(float delta) { - gameProc.update(delta); + gp.update(delta); } private void menu() { @@ -58,21 +58,21 @@ public class GameScreen implements Screen { break; case NEW_GAME: - gameProc = new GameProc(); - renderer = gameProc.renderer; - Gdx.input.setInputProcessor(new InputHandlerGame(gameProc)); + gp = new GameProc(); + renderer = gp.renderer; + Gdx.input.setInputProcessor(new InputHandlerGame(gp)); CaveGame.STATE = AppState.GAME_PLAY; break; case LOAD_GAME: - gameProc = GameSaver.load(); - renderer = gameProc.renderer; - Gdx.input.setInputProcessor(new InputHandlerGame(gameProc)); + gp = GameSaver.load(); + renderer = gp.renderer; + Gdx.input.setInputProcessor(new InputHandlerGame(gp)); CaveGame.STATE = AppState.GAME_PLAY; break; case SAVE_GAME: - GameSaver.save(gameProc); + GameSaver.save(gp); CaveGame.STATE = AppState.MENU_MAIN; break; @@ -94,8 +94,8 @@ public class GameScreen implements Screen { break; case GAME_PLAY: case GAME_CREATIVE_INV: - gameProc.resetRenderer(); - renderer = gameProc.renderer; + gp.resetRenderer(); + renderer = gp.renderer; break; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index 7cac744..608ed9f 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -10,79 +10,79 @@ import ru.deadsoftware.cavecraft.misc.Assets; public class GameInput { - private GameProc gameProc; + private GameProc gp; - public GameInput(GameProc gameProc) { - this.gameProc = gameProc; + public GameInput(GameProc gp) { + this.gp = gp; } private boolean checkSwim() { - return (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))); + return (Items.isFluid(gp.world.getForeMap((int) (gp.player.position.x + gp.player.width / 2) / 16, + (int) (gp.player.position.y + gp.player.height / 4 * 3) / 16))); } private void wasdPressed(int keycode) { - if (gameProc.ctrlMode == 0 || !CaveGame.TOUCH) { + if (gp.ctrlMode == 0 || !CaveGame.TOUCH) { switch (keycode) { case Input.Keys.A: - gameProc.player.move.x = -GamePhysics.PL_SPEED; - gameProc.player.dir = 0; - if (CaveGame.TOUCH && checkSwim()) gameProc.swim = true; + gp.player.move.x = -GamePhysics.PL_SPEED; + gp.player.dir = 0; + if (CaveGame.TOUCH && checkSwim()) gp.swim = true; break; case Input.Keys.D: - gameProc.player.move.x = GamePhysics.PL_SPEED; - gameProc.player.dir = 1; - if (CaveGame.TOUCH && checkSwim()) gameProc.swim = true; + gp.player.move.x = GamePhysics.PL_SPEED; + gp.player.dir = 1; + if (CaveGame.TOUCH && checkSwim()) gp.swim = true; break; } } else if (CaveGame.TOUCH) { switch (keycode) { case Input.Keys.A: - gameProc.cursorX--; + gp.curX--; break; case Input.Keys.D: - gameProc.cursorX++; + gp.curX++; break; case Input.Keys.W: - gameProc.cursorY--; + gp.curY--; break; case Input.Keys.S: - gameProc.cursorY++; + gp.curY++; break; } - gameProc.blockDmg = 0; + gp.blockDmg = 0; } } public void keyDown(int keycode) { - gameProc.isKeyDown = true; - gameProc.keyDownCode = keycode; + gp.isKeyDown = true; + gp.keyDownCode = keycode; if (keycode == Input.Keys.W || keycode == Input.Keys.A || keycode == Input.Keys.S || keycode == Input.Keys.D) { wasdPressed(keycode); } else switch (keycode) { case Input.Keys.ALT_LEFT: if (CaveGame.TOUCH) { - gameProc.ctrlMode++; - if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0; + gp.ctrlMode++; + if (gp.ctrlMode > 1) gp.ctrlMode = 0; } break; case Input.Keys.SPACE: if (checkSwim()) { - gameProc.swim = true; - } else if (gameProc.player.canJump) { - gameProc.player.move.add(0, -7); - } else if (!gameProc.player.flyMode) { - gameProc.player.flyMode = true; - gameProc.player.move.y = 0; + gp.swim = true; + } else if (gp.player.canJump) { + gp.player.move.add(0, -7); + } else if (!gp.player.flyMode) { + gp.player.flyMode = true; + gp.player.move.y = 0; } else { - gameProc.player.move.y = -GamePhysics.PL_SPEED; + gp.player.move.y = -GamePhysics.PL_SPEED; } break; case Input.Keys.CONTROL_LEFT: - gameProc.player.move.y = GamePhysics.PL_SPEED; + gp.player.move.y = GamePhysics.PL_SPEED; break; case Input.Keys.E: @@ -91,7 +91,7 @@ public class GameInput { break; case Input.Keys.G: - gameProc.mobs.add(new Pig(gameProc.cursorX * 16, gameProc.cursorY * 16)); + gp.mobs.add(new Pig(gp.curX * 16, gp.curY * 16)); break; case Input.Keys.ESCAPE: @@ -109,14 +109,14 @@ public class GameInput { switch (keycode) { case Input.Keys.A: case Input.Keys.D: - gameProc.player.move.x = 0; - if (CaveGame.TOUCH && gameProc.swim) gameProc.swim = false; + gp.player.move.x = 0; + if (CaveGame.TOUCH && gp.swim) gp.swim = false; break; case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: - if (gameProc.player.flyMode) gameProc.player.move.y = 0; - if (gameProc.swim) gameProc.swim = false; + if (gp.player.flyMode) gp.player.move.y = 0; + if (gp.swim) gp.swim = false; break; } } @@ -125,62 +125,62 @@ public class GameInput { } public void touchDown(int screenX, int screenY, int button) { - gameProc.touchDownTime = TimeUtils.millis(); - gameProc.isTouchDown = true; - gameProc.touchDownButton = button; - gameProc.touchDownX = screenX; - gameProc.touchDownY = screenY; + gp.touchDownTime = TimeUtils.millis(); + gp.isTouchDown = true; + gp.touchDownBtn = button; + gp.touchDownX = screenX; + gp.touchDownY = screenY; } public void touchUp(int screenX, int screenY, int button) { - if (CaveGame.TOUCH && gameProc.isKeyDown) { - keyUp(gameProc.keyDownCode); - gameProc.isKeyDown = false; + if (CaveGame.TOUCH && gp.isKeyDown) { + keyUp(gp.keyDownCode); + gp.isKeyDown = false; } - if (gameProc.isTouchDown) { + if (gp.isTouchDown) { if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && - screenX > gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 && - screenX < gameProc.renderer.camera.viewportWidth / 2 + Assets.creativeInv.getRegionWidth() / 2 && - screenY > gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 && - screenY < gameProc.renderer.camera.viewportHeight / 2 + Assets.creativeInv.getRegionHeight() / 2) { - int ix = (int) (screenX - (gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18; - int iy = (int) (screenY - (gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18; - int item = gameProc.creativeScroll * 8 + (ix + iy * 8); + screenX > gp.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 && + screenX < gp.renderer.getWidth() / 2 + Assets.creativeInv.getRegionWidth() / 2 && + screenY > gp.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 && + screenY < gp.renderer.getHeight() / 2 + Assets.creativeInv.getRegionHeight() / 2) { + int ix = (int) (screenX - (gp.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18; + int iy = (int) (screenY - (gp.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18; + int item = gp.creativeScroll * 8 + (ix + iy * 8); if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1; - if (item >= 0 && item < Items.ITEMS.size()) { + if (item >= 0 && item < Items.items.size()) { for (int i = 8; i > 0; i--) { - gameProc.player.inventory[i] = gameProc.player.inventory[i - 1]; + gp.player.inventory[i] = gp.player.inventory[i - 1]; } - gameProc.player.inventory[0] = item; + gp.player.inventory[0] = item; } } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) { CaveGame.STATE = AppState.GAME_PLAY; } else if (screenY < Assets.invBar.getRegionHeight() && - screenX > gameProc.renderer.camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 && - screenX < gameProc.renderer.camera.viewportWidth / 2 + Assets.invBar.getRegionWidth() / 2) { - gameProc.invSlot = (int) ((screenX - (gameProc.renderer.camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2)) / 20); + screenX > gp.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 && + screenX < gp.renderer.getWidth() / 2 + Assets.invBar.getRegionWidth() / 2) { + gp.invSlot = (int) ((screenX - (gp.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2)) / 20); } else if (button == Input.Buttons.RIGHT) { - gameProc.useItem(gameProc.cursorX, gameProc.cursorY, - gameProc.player.inventory[gameProc.invSlot], false); + gp.useItem(gp.curX, gp.curY, + gp.player.inventory[gp.invSlot], false); } else if (button == Input.Buttons.LEFT) { - gameProc.blockDmg = 0; + gp.blockDmg = 0; } } - gameProc.isTouchDown = false; + gp.isTouchDown = false; } public void touchDragged(int screenX, int screenY) { - if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY - gameProc.touchDownY) > 16) { - if (screenX > gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 && - screenX < gameProc.renderer.camera.viewportWidth / 2 + Assets.creativeInv.getRegionWidth() / 2 && - screenY > gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 && - screenY < gameProc.renderer.camera.viewportHeight / 2 + Assets.creativeInv.getRegionHeight() / 2) { - gameProc.creativeScroll -= (screenY - gameProc.touchDownY) / 16; - gameProc.touchDownX = screenX; - gameProc.touchDownY = screenY; - if (gameProc.creativeScroll < 0) gameProc.creativeScroll = 0; - if (gameProc.creativeScroll > gameProc.maxCreativeScroll) - gameProc.creativeScroll = gameProc.maxCreativeScroll; + if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY - gp.touchDownY) > 16) { + if (screenX > gp.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 && + screenX < gp.renderer.getWidth() / 2 + Assets.creativeInv.getRegionWidth() / 2 && + screenY > gp.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 && + screenY < gp.renderer.getHeight() / 2 + Assets.creativeInv.getRegionHeight() / 2) { + gp.creativeScroll -= (screenY - gp.touchDownY) / 16; + gp.touchDownX = screenX; + gp.touchDownY = screenY; + if (gp.creativeScroll < 0) gp.creativeScroll = 0; + if (gp.creativeScroll > gp.maxCreativeScroll) + gp.creativeScroll = gp.maxCreativeScroll; } } } @@ -188,15 +188,15 @@ public class GameInput { public void scrolled(int amount) { switch (CaveGame.STATE) { case GAME_PLAY: - gameProc.invSlot += amount; - if (gameProc.invSlot < 0) gameProc.invSlot = 8; - if (gameProc.invSlot > 8) gameProc.invSlot = 0; + gp.invSlot += amount; + if (gp.invSlot < 0) gp.invSlot = 8; + if (gp.invSlot > 8) gp.invSlot = 0; break; case GAME_CREATIVE_INV: - gameProc.creativeScroll += amount; - if (gameProc.creativeScroll < 0) gameProc.creativeScroll = 0; - if (gameProc.creativeScroll > gameProc.maxCreativeScroll) - gameProc.creativeScroll = gameProc.maxCreativeScroll; + gp.creativeScroll += amount; + if (gp.creativeScroll < 0) gp.creativeScroll = 0; + if (gp.creativeScroll > gp.maxCreativeScroll) + gp.creativeScroll = gp.maxCreativeScroll; break; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 142e959..fe0765a 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -15,12 +15,12 @@ public class GamePhysics { public static final int PL_SPEED = 2; - private GameProc gameProc; + private GameProc gp; private Vector2 gravity; - public GamePhysics(GameProc gameProc) { - this.gameProc = gameProc; + public GamePhysics(GameProc gp) { + this.gp = gp; gravity = new Vector2(0, .9f); } @@ -28,18 +28,18 @@ public class GamePhysics { int bl; switch (dir) { case 0: - bl = gameProc.world.getForeMap((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16)); + bl = gp.world.getForeMap((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16)); 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)); + bl = gp.world.getForeMap((int) ((rect.x + rect.width + 8) / 16), (int) ((rect.y + rect.height - 8) / 16)); if (checkColl(new Rectangle(rect.x + rect.width + 8, rect.y - 18, rect.width, rect.height))) bl = 0; break; default: bl = 0; } - 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); + 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) { @@ -49,12 +49,12 @@ public class GamePhysics { int maxX = (int) ((rect.x + rect.width / 2) / 16) + 4; int maxY = (int) ((rect.y + rect.height / 2) / 16) + 4; if (minY < 0) minY = 0; - if (maxY > gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); + if (maxY > gp.world.getHeight()) maxY = gp.world.getHeight(); for (int y = minY; y < maxY; y++) { for (int x = minX; x < maxX; x++) { - bl = gameProc.world.getForeMap(x, y); - if (bl > 0 && Items.BLOCKS.getValueAt(bl).collision) { - if (Intersector.overlaps(rect, Items.BLOCKS.getValueAt(bl).getRect(x, y))) { + bl = gp.world.getForeMap(x, y); + if (bl > 0 && Items.blocks.getValueAt(bl).coll) { + if (Intersector.overlaps(rect, Items.blocks.getValueAt(bl).getRect(x, y))) { return true; } } @@ -64,7 +64,7 @@ public class GamePhysics { } private int getBlock(Rectangle rect) { - return gameProc.world.getForeMap((int) (rect.x + rect.width / 2) / 16, (int) (rect.y + rect.height / 8 * 7) / 16); + return gp.world.getForeMap((int) (rect.x + rect.width / 2) / 16, (int) (rect.y + rect.height / 8 * 7) / 16); } private void dropPhy(Drop drop) { @@ -94,8 +94,8 @@ public class GamePhysics { } if (Items.isFluid(getBlock(pl.getRect()))) { - if (CaveGame.TOUCH && pl.move.x != 0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; - if (!gameProc.swim) { + if (CaveGame.TOUCH && pl.move.x != 0 && !gp.swim && !pl.flyMode) gp.swim = true; + if (!gp.swim) { if (!pl.flyMode && pl.move.y < 4.5f) pl.move.add(gravity.x / 4, gravity.y / 4); if (!pl.flyMode && pl.move.y > 4.5f) pl.move.add(0, -1f); } else { @@ -118,11 +118,11 @@ 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(); + if (pl.position.x + pl.texWidth / 2 < 0) pl.position.x += gp.world.getWidth() * 16; + if (pl.position.x + pl.texWidth / 2 > gp.world.getWidth() * 16) + pl.position.x -= gp.world.getWidth() * 16; + if (pl.position.y > gp.world.getHeight() * 16) { + pl.position = gp.world.getSpawnPoint().cpy(); } if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && pl.move.x != 0) { pl.move.add(0, -8); @@ -140,7 +140,7 @@ public class GamePhysics { while (checkColl(mob.getRect())) mob.position.y += d; mob.move.y = 0; if (mob.getType() > 0) { - gameProc.world.setForeMap((int) mob.position.x / 16, (int) mob.position.y / 16, mob.getType()); + gp.world.setForeMap((int) mob.position.x / 16, (int) mob.position.y / 16, mob.getType()); mob.position.y = -1; mob.dead = true; } @@ -169,10 +169,10 @@ public class GamePhysics { 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 (mob.position.y > gameProc.world.getHeight() * 16) { + if (mob.position.x + mob.width / 2 < 0) mob.position.x += gp.world.getWidth() * 16; + if (mob.position.x + mob.width / 2 > gp.world.getWidth() * 16) + mob.position.x -= gp.world.getWidth() * 16; + if (mob.position.y > gp.world.getHeight() * 16) { mob.position.y = 0; } if (checkJump(mob.getRect(), mob.dir) && mob.canJump && mob.move.x != 0) { @@ -182,15 +182,15 @@ public class GamePhysics { } public void update(float delta) { - for (Iterator it = gameProc.drops.iterator(); it.hasNext(); ) { + for (Iterator it = gp.drops.iterator(); it.hasNext(); ) { Drop drop = it.next(); dropPhy(drop); - if (Intersector.overlaps(drop.getRect(), gameProc.player.getRect())) - drop.pickUpDrop(gameProc.player); + if (Intersector.overlaps(drop.getRect(), gp.player.getRect())) + drop.pickUpDrop(gp.player); if (drop.pickedUp) it.remove(); } - for (Iterator it = gameProc.mobs.iterator(); it.hasNext(); ) { + for (Iterator it = gp.mobs.iterator(); it.hasNext(); ) { Mob mob = it.next(); mob.ai(); mobPhy(mob); @@ -198,13 +198,11 @@ public class GamePhysics { it.remove(); } - playerPhy(gameProc.player); + playerPhy(gp.player); - gameProc.renderer.camera.position.set( - gameProc.player.position.x + gameProc.player.texWidth / 2 - gameProc.renderer.camera.viewportWidth / 2, - gameProc.player.position.y + gameProc.player.height / 2 - gameProc.renderer.camera.viewportHeight / 2, - 0 - ); + gp.renderer.setCamPos( + gp.player.position.x + gp.player.texWidth / 2 - gp.renderer.getWidth() / 2, + gp.player.position.y + gp.player.height / 2 - gp.renderer.getHeight() / 2); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index e4d12b2..f79694f 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -33,7 +33,7 @@ public class GameProc implements Serializable { public transient GameRenderer renderer; public transient GamePhysics physics; - public int cursorX, cursorY; + public int curX, curY; public int invSlot; public int ctrlMode; public int creativeScroll, maxCreativeScroll; @@ -41,7 +41,7 @@ public class GameProc implements Serializable { public boolean isTouchDown, isKeyDown, swim; public int touchDownX, touchDownY, keyDownCode; - public int touchDownButton; + public int touchDownBtn; public long touchDownTime; public GameProc() { @@ -62,7 +62,7 @@ public class GameProc implements Serializable { renderer = new GameRenderer(this, 480, 480 * ((float) GameScreen.getHeight() / GameScreen.getWidth())); } - maxCreativeScroll = Items.ITEMS.size() / 8; + maxCreativeScroll = Items.items.size() / 8; GameSaver.save(this); } @@ -78,45 +78,45 @@ public class GameProc implements Serializable { private boolean isAutoselectable(int x, int y) { return (world.getForeMap(x, y) > 0 && - Items.BLOCKS.getValueAt(world.getForeMap(x, y)).collision); + Items.blocks.getValueAt(world.getForeMap(x, y)).coll); } private void moveCursor() { - int pastX = cursorX, pastY = cursorY; + int pastX = curX, pastY = curY; if (ctrlMode == 0 && CaveGame.TOUCH) { - cursorX = (int) (player.position.x + player.texWidth / 2) / 16; - if (player.dir == 0) cursorX--; - else cursorX++; - cursorY = (int) (player.position.y + player.texWidth) / 16; - if (!isAutoselectable(cursorX, cursorY)) { - cursorY++; + curX = (int) (player.position.x + player.texWidth / 2) / 16; + if (player.dir == 0) curX--; + else curX++; + curY = (int) (player.position.y + player.texWidth) / 16; + if (!isAutoselectable(curX, curY)) { + curY++; } - if (!isAutoselectable(cursorX, cursorY)) { - cursorY++; + if (!isAutoselectable(curX, curY)) { + curY++; } - if (!isAutoselectable(cursorX, cursorY)) { - if (player.dir == 0) cursorX++; - else cursorX--; + if (!isAutoselectable(curX, curY)) { + if (player.dir == 0) curX++; + else curX--; } } else if (!CaveGame.TOUCH) { - cursorX = (int) (Gdx.input.getX() * - (renderer.camera.viewportWidth / GameScreen.getWidth()) + renderer.camera.position.x) / 16; - cursorY = (int) (Gdx.input.getY() * - (renderer.camera.viewportHeight / GameScreen.getHeight()) + renderer.camera.position.y) / 16; + curX = (int) (Gdx.input.getX() * + (renderer.getWidth() / GameScreen.getWidth()) + renderer.getCamX()) / 16; + curY = (int) (Gdx.input.getY() * + (renderer.getHeight() / GameScreen.getHeight()) + renderer.getCamY()) / 16; if ((Gdx.input.getX() * - (renderer.camera.viewportWidth / GameScreen.getWidth()) + renderer.camera.position.x) < 0) - cursorX--; + (renderer.getWidth() / GameScreen.getWidth()) + renderer.getCamX()) < 0) + curX--; } - if (pastX != cursorX || pastY != cursorY) blockDmg = 0; + if (pastX != curX || pastY != curY) blockDmg = 0; } private void checkCursorBounds() { - if (cursorY < 0) cursorY = 0; - if (cursorY >= world.getHeight()) cursorY = world.getHeight() - 1; + if (curY < 0) curY = 0; + if (curY >= world.getHeight()) curY = world.getHeight() - 1; if (ctrlMode == 1) { - if (cursorX * 16 + 8 < player.position.x + player.texWidth / 2) + if (curX * 16 + 8 < player.position.x + player.texWidth / 2) player.dir = 0; - if (cursorX * 16 + 8 > player.position.x + player.texWidth / 2) + if (curX * 16 + 8 > player.position.x + player.texWidth / 2) player.dir = 1; } } @@ -137,15 +137,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); 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, 68); - } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + } else if (Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { if (world.getForeMap(x + 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x + 1, y)).coll && !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); @@ -156,7 +156,7 @@ public class GameProc implements Serializable { 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.blocks.getValueAt(world.getForeMap(x - 1, y)).coll && !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); @@ -170,15 +170,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); 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, 68); - } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + } else if (Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { if (world.getForeMap(x + 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x + 1, y)).coll && !Items.isFluid(world.getForeMap(x + 1, y))) || (Items.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 +188,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x - 1, y)).coll && !Items.isFluid(world.getForeMap(x - 1, y))) || (Items.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 +201,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); 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, 68); - } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + } else if (Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { if (world.getForeMap(x + 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y)))) { + (!Items.blocks.getValueAt(world.getForeMap(x + 1, y)).coll && !Items.isFluid(world.getForeMap(x + 1, y)))) { world.setForeMap(x + 1, y, 63); updateBlock(x + 1, y + 1); } else if (Items.isLava(world.getForeMap(x + 1, y))) { @@ -218,7 +218,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y)))) { + (!Items.blocks.getValueAt(world.getForeMap(x - 1, y)).coll && !Items.isFluid(world.getForeMap(x - 1, y)))) { world.setForeMap(x - 1, y, 63); updateBlock(x - 1, y + 1); } else if (Items.isLava(world.getForeMap(x - 1, y))) { @@ -230,7 +230,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 60); updateBlock(x, y + 2); } else if (Items.isLava(world.getForeMap(x, y + 1))) { @@ -256,14 +256,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); 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) { + } else if (Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { if (world.getForeMap(x + 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x + 1, y)).coll && !Items.isFluid(world.getForeMap(x + 1, y))) || (Items.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 +272,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x - 1, y)).coll && !Items.isFluid(world.getForeMap(x - 1, y))) || (Items.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 +284,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); 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) { + } else if (Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { if (world.getForeMap(x + 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x + 1, y)).coll && !Items.isFluid(world.getForeMap(x + 1, y))) || (Items.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 +300,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (!Items.blocks.getValueAt(world.getForeMap(x - 1, y)).coll && !Items.isFluid(world.getForeMap(x - 1, y))) || (Items.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 +312,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); 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) { + } else if (Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { if (world.getForeMap(x + 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y)))) { + (!Items.blocks.getValueAt(world.getForeMap(x + 1, y)).coll && !Items.isFluid(world.getForeMap(x + 1, y)))) { world.setForeMap(x + 1, y, 67); updateBlock(x + 1, y + 1); } else if (Items.isWater(world.getForeMap(x + 1, y))) { @@ -327,7 +327,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x - 1, y) == 0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y)))) { + (!Items.blocks.getValueAt(world.getForeMap(x - 1, y)).coll && !Items.isFluid(world.getForeMap(x - 1, y)))) { world.setForeMap(x - 1, y, 67); updateBlock(x - 1, y + 1); } else if (Items.isWater(world.getForeMap(x - 1, y))) { @@ -338,7 +338,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) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision && !Items.isFluid(world.getForeMap(x, y + 1)))) { + (!Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll && !Items.isFluid(world.getForeMap(x, y + 1)))) { world.setForeMap(x, y + 1, 64); updateBlock(x, y + 2); } else if (Items.isWater(world.getForeMap(x, y + 1))) { @@ -350,7 +350,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 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + if (world.getForeMap(x, y + 1) == 0 || !Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { world.setForeMap(x, y, 0); mobs.add(new FallingSand(x * 16, y * 16)); updateBlock(x, y - 1); @@ -358,7 +358,7 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 11) { - if (world.getForeMap(x, y + 1) == 0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + if (world.getForeMap(x, y + 1) == 0 || !Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { world.setForeMap(x, y, 0); mobs.add(new FallingGravel(x * 16, y * 16)); updateBlock(x, y - 1); @@ -366,14 +366,14 @@ public class GameProc implements Serializable { } if (world.getForeMap(x, y) == 59) { - if (world.getForeMap(x, y + 1) == 0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + if (world.getForeMap(x, y + 1) == 0 || !Items.blocks.getValueAt(world.getForeMap(x, y + 1)).coll) { 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 || + if (world.getForeMap(x, y - 1) > 0 && (Items.blocks.getValueAt(world.getForeMap(x, y - 1)).coll || Items.isFluid(world.getForeMap(x, y - 1)))) { world.setForeMap(x, y, 3); } @@ -381,9 +381,9 @@ public class GameProc implements Serializable { } public void useItem(int x, int y, int id, boolean bg) { - if (id > 0 && Items.ITEMS.get(id).getType() == 0) { - if (!bg) world.placeToForeground(x, y, Items.ITEMS.get(id).getBlock()); - else world.placeToBackground(x, y, Items.ITEMS.get(id).getBlock()); + if (id > 0 && Items.items.get(id).getType() == 0) { + if (!bg) world.placeToForeground(x, y, Items.items.get(id).getBlock()); + else world.placeToBackground(x, y, Items.items.get(id).getBlock()); } } @@ -399,7 +399,7 @@ public class GameProc implements Serializable { } for (int y = 0; y < world.getHeight(); y++) { - for (int x = (int) renderer.camera.position.x / 16 - 1; x < (int) (renderer.camera.position.x + renderer.camera.viewportWidth) / 16 + 1; x++) { + for (int x = (int) renderer.getCamX() / 16 - 1; x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) { updateFluids(x, y); } } @@ -408,26 +408,26 @@ public class GameProc implements Serializable { moveCursor(); checkCursorBounds(); - if (isTouchDown && touchDownButton == Input.Buttons.LEFT) { - if (world.getForeMap(cursorX, cursorY) > 0 && - Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp() >= 0) {// || world.getBackMap(cursorX, cursorY) > 0) { + if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) { + if (world.getForeMap(curX, curY) > 0 && + Items.blocks.getValueAt(world.getForeMap(curX, curY)).getHp() >= 0) {// || world.getBackMap(curX, curY) > 0) { blockDmg++; - if (blockDmg >= Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp()) { - if (Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getDrop() > 0) - drops.add(new Drop(cursorX * 16 + 4, cursorY * 16 + 4, Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getDrop())); - world.placeToForeground(cursorX, cursorY, 0); + if (blockDmg >= Items.blocks.getValueAt(world.getForeMap(curX, curY)).getHp()) { + if (Items.blocks.getValueAt(world.getForeMap(curX, curY)).getDrop() > 0) + drops.add(new Drop(curX * 16 + 4, curY * 16 + 4, Items.blocks.getValueAt(world.getForeMap(curX, curY)).getDrop())); + world.placeToForeground(curX, curY, 0); blockDmg = 0; } } } if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { - if (touchDownButton == Input.Buttons.RIGHT) { - useItem(cursorX, cursorY, player.inventory[invSlot], true); + if (touchDownBtn == Input.Buttons.RIGHT) { + useItem(curX, curY, player.inventory[invSlot], true); isTouchDown = false; } else if (touchDownY < Assets.invBar.getRegionHeight() && - touchDownX > renderer.camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 && - touchDownX < renderer.camera.viewportWidth / 2 + Assets.invBar.getRegionWidth() / 2) { + touchDownX > renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 && + touchDownX < renderer.getWidth() / 2 + Assets.invBar.getRegionWidth() / 2) { CaveGame.STATE = AppState.GAME_CREATIVE_INV; isTouchDown = false; } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 8ed1ebd..cbcaeb8 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -3,7 +3,6 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.math.MathUtils; -import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.GameScreen; import ru.deadsoftware.cavecraft.game.mobs.Mob; @@ -14,173 +13,194 @@ import ru.deadsoftware.cavecraft.misc.Renderer; public class GameRenderer extends Renderer { - private GameProc gameProc; + private GameProc gp; - public GameRenderer(GameProc gameProc, float width, float heigth) { + public GameRenderer(GameProc gp, float width, float heigth) { super(width, heigth); Gdx.gl.glClearColor(0f, .6f, .6f, 1f); - this.gameProc = gameProc; + this.gp = gp; + } + + private float drawX(int x) { + return x * 16 - getCamX(); + } + + private float drawY(int y) { + return y * 16 - getCamY(); + } + + private void drawWreck() { + if (gp.blockDmg > 0) { + spriter.draw(Assets.wreck[ + 10 * gp.blockDmg / + Items.blocks.getValueAt(gp.world.getForeMap(gp.curX, gp.curY)).getHp()], + gp.curX * 16 - getCamX(), + gp.curY * 16 - getCamY()); + } } private void drawWorldBackground() { - int minX = (int) (camera.position.x / 16) - 1; - int minY = (int) (camera.position.y / 16) - 1; - int maxX = (int) ((camera.position.x + camera.viewportWidth) / 16) + 1; - int maxY = (int) ((camera.position.y + camera.viewportHeight) / 16) + 1; + int minX = (int) (getCamX() / 16) - 1; + int minY = (int) (getCamY() / 16) - 1; + int maxX = (int) ((getCamX() + getWidth()) / 16) + 1; + int maxY = (int) ((getCamY() + getHeight()) / 16) + 1; if (minY < 0) minY = 0; - if (maxY > gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); + if (maxY > gp.world.getHeight()) maxY = gp.world.getHeight(); for (int y = minY; y < maxY; y++) { for (int x = minX; x < maxX; x++) { - if ((gameProc.world.getForeMap(x, y) == 0 || Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).transparent) - && gameProc.world.getBackMap(x, y) > 0) { - spriteBatch.draw( - Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x, y)).getTexture()], - x * 16 - camera.position.x, y * 16 - camera.position.y); - Assets.shade.setPosition(x * 16 - camera.position.x, y * 16 - camera.position.y); - Assets.shade.draw(spriteBatch); + if ((gp.world.getForeMap(x, y) == 0 || Items.blocks.getValueAt(gp.world.getForeMap(x, y)).tp) + && gp.world.getBackMap(x, y) > 0) { + spriter.draw( + Assets.blockTex[Items.blocks.getValueAt(gp.world.getBackMap(x, y)).getTex()], + drawX(x), drawY(y)); + if (gp.world.getForeMap(x, y) == 0) drawWreck(); + Assets.shade.setPosition(drawX(x), drawY(y)); + Assets.shade.draw(spriter); } - if (gameProc.world.getForeMap(x, y) > 0 && Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).background) { - spriteBatch.draw( - Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).getTexture()], - x * 16 - camera.position.x, y * 16 - camera.position.y); + if (gp.world.getForeMap(x, y) > 0 && Items.blocks.getValueAt(gp.world.getForeMap(x, y)).bg) { + spriter.draw( + Assets.blockTex[Items.blocks.getValueAt(gp.world.getForeMap(x, y)).getTex()], + drawX(x), drawY(y)); + drawWreck(); } } } } private void drawWorldForeground() { - int minX = (int) (camera.position.x / 16) - 1; - int minY = (int) (camera.position.y / 16) - 1; - int maxX = (int) ((camera.position.x + camera.viewportWidth) / 16) + 1; - int maxY = (int) ((camera.position.y + camera.viewportHeight) / 16) + 1; + int minX = (int) (getCamX() / 16) - 1; + int minY = (int) (getCamY() / 16) - 1; + int maxX = (int) ((getCamX() + getWidth()) / 16) + 1; + int maxY = (int) ((getCamY() + getHeight()) / 16) + 1; if (minY < 0) minY = 0; - if (maxY > gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); + if (maxY > gp.world.getHeight()) maxY = gp.world.getHeight(); for (int y = minY; y < maxY; y++) { for (int x = minX; x < maxX; x++) { - if (gameProc.world.getForeMap(x, y) > 0 && !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).background) { - spriteBatch.draw( - Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).getTexture()], - x * 16 - camera.position.x, y * 16 - camera.position.y); + if (gp.world.getForeMap(x, y) > 0 && !Items.blocks.getValueAt(gp.world.getForeMap(x, y)).bg) { + spriter.draw( + Assets.blockTex[Items.blocks.getValueAt(gp.world.getForeMap(x, y)).getTex()], + drawX(x), drawY(y)); + drawWreck(); } } } } 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); + mob.draw(spriter, + mob.position.x - getCamX() - gp.world.getWidth() * 16, mob.position.y - getCamY()); + mob.draw(spriter, + mob.position.x - getCamX(), mob.position.y - getCamY()); + mob.draw(spriter, + mob.position.x - getCamX() + gp.world.getWidth() * 16, mob.position.y - getCamY()); } private void drawDrop(Drop drop) { - switch (Items.ITEMS.get(drop.getId()).getType()) { + switch (Items.items.get(drop.getId()).getType()) { case 0: - Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].setPosition(drop.position.x - camera.position.x - gameProc.world.getWidth() * 16, drop.position.y - camera.position.y); - Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].draw(spriteBatch); - Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].setPosition(drop.position.x - camera.position.x, drop.position.y - camera.position.y); - Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].draw(spriteBatch); - Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].setPosition(drop.position.x - camera.position.x + gameProc.world.getWidth() * 16, drop.position.y - camera.position.y); - Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].draw(spriteBatch); + Assets.blockTex[Items.items.get(drop.getId()).getTex()].setPosition(drop.position.x - getCamX() - gp.world.getWidth() * 16, drop.position.y - getCamY()); + Assets.blockTex[Items.items.get(drop.getId()).getTex()].draw(spriter); + Assets.blockTex[Items.items.get(drop.getId()).getTex()].setPosition(drop.position.x - getCamX(), drop.position.y - getCamY()); + Assets.blockTex[Items.items.get(drop.getId()).getTex()].draw(spriter); + Assets.blockTex[Items.items.get(drop.getId()).getTex()].setPosition(drop.position.x - getCamX() + gp.world.getWidth() * 16, drop.position.y - getCamY()); + Assets.blockTex[Items.items.get(drop.getId()).getTex()].draw(spriter); } } private void drawPlayer(Player pl) { - if (pl.move.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) { - Assets.playerSprite[0][2].rotate(Player.ANIM_SPEED); - Assets.playerSprite[1][2].rotate(-Player.ANIM_SPEED); - Assets.playerSprite[0][3].rotate(-Player.ANIM_SPEED); - Assets.playerSprite[1][3].rotate(Player.ANIM_SPEED); + if (pl.move.x != 0 || Assets.plSprite[0][2].getRotation() != 0) { + Assets.plSprite[0][2].rotate(Player.ANIM_SPEED); + Assets.plSprite[1][2].rotate(-Player.ANIM_SPEED); + Assets.plSprite[0][3].rotate(-Player.ANIM_SPEED); + Assets.plSprite[1][3].rotate(Player.ANIM_SPEED); } else { - Assets.playerSprite[0][2].setRotation(0); - Assets.playerSprite[1][2].setRotation(0); - Assets.playerSprite[0][3].setRotation(0); - Assets.playerSprite[1][3].setRotation(0); + Assets.plSprite[0][2].setRotation(0); + Assets.plSprite[1][2].setRotation(0); + Assets.plSprite[0][3].setRotation(0); + Assets.plSprite[1][3].setRotation(0); } - if (Assets.playerSprite[0][2].getRotation() >= 60 || Assets.playerSprite[0][2].getRotation() <= -60) + if (Assets.plSprite[0][2].getRotation() >= 60 || Assets.plSprite[0][2].getRotation() <= -60) Player.ANIM_SPEED = -Player.ANIM_SPEED; //back hand - Assets.playerSprite[1][2].setPosition( - pl.position.x - camera.position.x - 6, - pl.position.y - camera.position.y); - Assets.playerSprite[1][2].draw(spriteBatch); + Assets.plSprite[1][2].setPosition( + pl.position.x - getCamX() - 6, + pl.position.y - getCamY()); + Assets.plSprite[1][2].draw(spriter); //back leg - Assets.playerSprite[1][3].setPosition( - pl.position.x - camera.position.x - 6, - pl.position.y - camera.position.y + 10); - Assets.playerSprite[1][3].draw(spriteBatch); + Assets.plSprite[1][3].setPosition( + pl.position.x - getCamX() - 6, + pl.position.y - getCamY() + 10); + Assets.plSprite[1][3].draw(spriter); //front leg - Assets.playerSprite[0][3].setPosition( - pl.position.x - camera.position.x - 6, - pl.position.y - camera.position.y + 10); - Assets.playerSprite[0][3].draw(spriteBatch); + Assets.plSprite[0][3].setPosition( + pl.position.x - getCamX() - 6, + pl.position.y - getCamY() + 10); + Assets.plSprite[0][3].draw(spriter); //head - spriteBatch.draw(Assets.playerSprite[pl.dir][0], - pl.position.x - camera.position.x - 2, - pl.position.y - camera.position.y - 2); + spriter.draw(Assets.plSprite[pl.dir][0], + pl.position.x - getCamX() - 2, + pl.position.y - getCamY() - 2); //body - spriteBatch.draw(Assets.playerSprite[pl.dir][1], - pl.position.x - camera.position.x - 2, pl.position.y - camera.position.y + 8); + spriter.draw(Assets.plSprite[pl.dir][1], + pl.position.x - getCamX() - 2, pl.position.y - getCamY() + 8); //item in hand - if (pl.inventory[gameProc.invSlot] > 0) - switch (Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getType()) { + if (pl.inventory[gp.invSlot] > 0) + switch (Items.items.get(pl.inventory[gp.invSlot]).getType()) { case 0: - Assets.blockTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].setPosition( - pl.position.x - camera.position.x - 8 * MathUtils.sin(MathUtils.degRad * Assets.playerSprite[0][2].getRotation()), - pl.position.y - camera.position.y + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.playerSprite[0][2].getRotation())); - Assets.blockTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].draw(spriteBatch); + Assets.blockTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].setPosition( + pl.position.x - getCamX() - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()), + pl.position.y - getCamY() + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation())); + Assets.blockTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].draw(spriter); break; default: - Assets.itemTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].flip((pl.dir == 0), false); - Assets.itemTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].setRotation( - -45 + pl.dir * 90 + Assets.playerSprite[0][2].getRotation()); - Assets.itemTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].setPosition( - pl.position.x - camera.position.x - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.playerSprite[0][2].getRotation()), - pl.position.y - camera.position.y + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.playerSprite[0][2].getRotation())); - Assets.itemTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].draw(spriteBatch); - Assets.itemTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].flip((pl.dir == 0), false); + Assets.itemTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].flip((pl.dir == 0), false); + Assets.itemTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].setRotation( + -45 + pl.dir * 90 + Assets.plSprite[0][2].getRotation()); + Assets.itemTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].setPosition( + pl.position.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()), + pl.position.y - getCamY() + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation())); + Assets.itemTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].draw(spriter); + Assets.itemTex[Items.items.get(pl.inventory[gp.invSlot]).getTex()].flip((pl.dir == 0), false); break; } //front hand - Assets.playerSprite[0][2].setPosition( - pl.position.x - camera.position.x - 6, - pl.position.y - camera.position.y); - Assets.playerSprite[0][2].draw(spriteBatch); + Assets.plSprite[0][2].setPosition( + pl.position.x - getCamX() - 6, + pl.position.y - getCamY()); + Assets.plSprite[0][2].draw(spriter); } private void drawCreative() { - float x = camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2; - float y = camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2; - spriteBatch.draw(Assets.creativeInv, x, y); - spriteBatch.draw(Assets.creativeScroll, x + 156, - y + 18 + (gameProc.creativeScroll * (72 / gameProc.maxCreativeScroll))); - for (int i = gameProc.creativeScroll * 8; i < gameProc.creativeScroll * 8 + 40; i++) { - if (i > 0 && i < Items.ITEMS.size()) - switch (Items.ITEMS.get(i).getType()) { + float x = getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2; + float y = getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2; + spriter.draw(Assets.creativeInv, x, y); + spriter.draw(Assets.creativeScr, x + 156, + y + 18 + (gp.creativeScroll * (72 / gp.maxCreativeScroll))); + for (int i = gp.creativeScroll * 8; i < gp.creativeScroll * 8 + 40; i++) { + if (i > 0 && i < Items.items.size()) + switch (Items.items.get(i).getType()) { case 0: - spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(i).getTexture()], - x + 8 + ((i - gameProc.creativeScroll * 8) % 8) * 18, - y + 18 + ((i - gameProc.creativeScroll * 8) / 8) * 18); + spriter.draw(Assets.blockTex[Items.items.get(i).getTex()], + x + 8 + ((i - gp.creativeScroll * 8) % 8) * 18, + y + 18 + ((i - gp.creativeScroll * 8) / 8) * 18); break; case 1: - spriteBatch.draw(Assets.itemTextures[Items.ITEMS.get(i).getTexture()], - x + 8 + ((i - gameProc.creativeScroll * 8) % 8) * 18, - y + 18 + ((i - gameProc.creativeScroll * 8) / 8) * 18); + spriter.draw(Assets.itemTex[Items.items.get(i).getTex()], + x + 8 + ((i - gp.creativeScroll * 8) % 8) * 18, + y + 18 + ((i - gp.creativeScroll * 8) / 8) * 18); break; } } for (int i = 0; i < 9; i++) { - if (gameProc.player.inventory[i] > 0) - switch (Items.ITEMS.get(gameProc.player.inventory[i]).getType()) { + if (gp.player.inventory[i] > 0) + switch (Items.items.get(gp.player.inventory[i]).getType()) { case 0: - spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], + spriter.draw(Assets.blockTex[Items.items.get(gp.player.inventory[i]).getTex()], x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24); break; case 1: - spriteBatch.draw(Assets.itemTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], + spriter.draw(Assets.itemTex[Items.items.get(gp.player.inventory[i]).getTex()], x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24); break; } @@ -188,61 +208,54 @@ public class GameRenderer extends Renderer { } private void drawGUI() { - if (gameProc.blockDmg > 0) { - spriteBatch.draw(Assets.wreck[ - 10 * gameProc.blockDmg / - Items.BLOCKS.getValueAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)).getHp()], - gameProc.cursorX * 16 - camera.position.x, - gameProc.cursorY * 16 - camera.position.y); - } - if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0 || - gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0 || - gameProc.ctrlMode == 1 || + if (gp.world.getForeMap(gp.curX, gp.curY) > 0 || + gp.world.getBackMap(gp.curX, gp.curY) > 0 || + gp.ctrlMode == 1 || !CaveGame.TOUCH) - spriteBatch.draw(Assets.guiCur, - gameProc.cursorX * 16 - camera.position.x, - gameProc.cursorY * 16 - camera.position.y); - spriteBatch.draw(Assets.invBar, camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2, 0); + spriter.draw(Assets.guiCur, + gp.curX * 16 - getCamX(), + gp.curY * 16 - getCamY()); + spriter.draw(Assets.invBar, getWidth() / 2 - Assets.invBar.getRegionWidth() / 2, 0); for (int i = 0; i < 9; i++) { - if (gameProc.player.inventory[i] > 0) { - switch (Items.ITEMS.get(gameProc.player.inventory[i]).getType()) { + if (gp.player.inventory[i] > 0) { + switch (Items.items.get(gp.player.inventory[i]).getType()) { case 0: - spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], - camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20, + spriter.draw(Assets.blockTex[Items.items.get(gp.player.inventory[i]).getTex()], + getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20, 3); break; case 1: - spriteBatch.draw(Assets.itemTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], - camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20, + spriter.draw(Assets.itemTex[Items.items.get(gp.player.inventory[i]).getTex()], + getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20, 3); break; } } } - spriteBatch.draw(Assets.invBarCur, - camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 - 1 + 20 * gameProc.invSlot, + spriter.draw(Assets.invBarCur, + getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 - 1 + 20 * gp.invSlot, -1); } private void drawTouchGui() { - spriteBatch.draw(Assets.touchArrows[0], 26, camera.viewportHeight - 52); - spriteBatch.draw(Assets.touchArrows[1], 0, camera.viewportHeight - 26); - spriteBatch.draw(Assets.touchArrows[2], 26, camera.viewportHeight - 26); - spriteBatch.draw(Assets.touchArrows[3], 52, camera.viewportHeight - 26); - spriteBatch.draw(Assets.touchLMB, camera.viewportWidth - 52, camera.viewportHeight - 26); - spriteBatch.draw(Assets.touchRMB, camera.viewportWidth - 26, camera.viewportHeight - 26); - spriteBatch.draw(Assets.touchToggleMode, 78, camera.viewportHeight - 26); - if (gameProc.ctrlMode == 1) { - Assets.shade.setPosition(83, camera.viewportHeight - 21); - Assets.shade.draw(spriteBatch); + spriter.draw(Assets.touchArrows[0], 26, getHeight() - 52); + spriter.draw(Assets.touchArrows[1], 0, getHeight() - 26); + spriter.draw(Assets.touchArrows[2], 26, getHeight() - 26); + spriter.draw(Assets.touchArrows[3], 52, getHeight() - 26); + spriter.draw(Assets.touchLMB, getWidth() - 52, getHeight() - 26); + spriter.draw(Assets.touchRMB, getWidth() - 26, getHeight() - 26); + spriter.draw(Assets.touchMode, 78, getHeight() - 26); + if (gp.ctrlMode == 1) { + Assets.shade.setPosition(83, getHeight() - 21); + Assets.shade.draw(spriter); } } private void drawGamePlay() { drawWorldBackground(); - drawPlayer(gameProc.player); - for (Mob mob : gameProc.mobs) drawMob(mob); - for (Drop drop : gameProc.drops) drawDrop(drop); + drawPlayer(gp.player); + for (Mob mob : gp.mobs) drawMob(mob); + for (Drop drop : gp.drops) drawDrop(drop); drawWorldForeground(); drawGUI(); } @@ -251,7 +264,7 @@ public class GameRenderer extends Renderer { public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - spriteBatch.begin(); + spriter.begin(); switch (CaveGame.STATE) { case GAME_PLAY: drawGamePlay(); @@ -266,14 +279,14 @@ public class GameRenderer extends Renderer { if (GameScreen.SHOW_DEBUG) { drawString("FPS: " + GameScreen.FPS, 0, 0); - drawString("X: " + (int) (gameProc.player.position.x / 16), 0, 10); - drawString("Y: " + (int) (gameProc.player.position.y / 16), 0, 20); - drawString("Mobs: " + gameProc.mobs.size(), 0, 30); - drawString("Drops: " + gameProc.drops.size(), 0, 40); - drawString("Block: " + Items.BLOCKS.getKeyAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)), 0, 50); + drawString("X: " + (int) (gp.player.position.x / 16), 0, 10); + drawString("Y: " + (int) (gp.player.position.y / 16), 0, 20); + drawString("Mobs: " + gp.mobs.size(), 0, 30); + drawString("Drops: " + gp.drops.size(), 0, 40); + drawString("Block: " + Items.blocks.getKeyAt(gp.world.getForeMap(gp.curX, gp.curY)), 0, 50); } - spriteBatch.end(); + spriter.end(); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java index a4e314b..c4e13a6 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java @@ -87,17 +87,17 @@ public class GameSaver { return gameProc; } - public static void save(GameProc gameProc) { + public static void save(GameProc gp) { FileHandle file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/"); file.mkdirs(); file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/game.sav"); try { ObjectOutputStream out = new ObjectOutputStream(file.write(false)); out.writeInt(VERSION); - out.writeObject(gameProc); + out.writeObject(gp); out.close(); - saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav"), gameProc.world.getFullForeMap()); - saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"), gameProc.world.getFullBackMap()); + saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav"), gp.world.getFullForeMap()); + saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"), gp.world.getFullBackMap()); } catch (Exception e) { e.printStackTrace(); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java index 62f7274..6adac2d 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java @@ -94,7 +94,7 @@ public class GameWorld { } public void placeToForeground(int x, int y, int value) { - if (getForeMap(x, y) == 0 || value == 0 || !Items.BLOCKS.getValueAt(getForeMap(x, y)).collision) { + if (getForeMap(x, y) == 0 || value == 0 || !Items.blocks.getValueAt(getForeMap(x, y)).coll) { setForeMap(x, y, value); } else if (Items.isSlab(value) && getForeMap(x, y) == value) { placeSlab(x, y, value); @@ -105,8 +105,8 @@ public class GameWorld { } public void placeToBackground(int x, int y, int value) { - if (value == 0 || (getBackMap(x, y) == 0 && Items.BLOCKS.getValueAt(value).collision) && - (!Items.BLOCKS.getValueAt(value).transparent || value == 18)) { + if (value == 0 || (getBackMap(x, y) == 0 && Items.blocks.getValueAt(value).coll) && + (!Items.blocks.getValueAt(value).tp || value == 18)) { setBackMap(x, y, value); } } @@ -115,7 +115,7 @@ public class GameWorld { int x = 0, y = 0; while (true) { y++; - if (getForeMap(x, y) > 0 && Items.BLOCKS.getValueAt(getForeMap(x, y)).collision) break; + if (getForeMap(x, y) > 0 && Items.blocks.getValueAt(getForeMap(x, y)).coll) break; } x = x * 16 + 4; y = y * 16 - 32; diff --git a/core/src/ru/deadsoftware/cavecraft/game/Items.java b/core/src/ru/deadsoftware/cavecraft/game/Items.java index 2121ae0..2853b7b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/Items.java +++ b/core/src/ru/deadsoftware/cavecraft/game/Items.java @@ -8,8 +8,8 @@ import java.util.ArrayList; public class Items { - public static ArrayMap BLOCKS = new ArrayMap(); - public static ArrayList ITEMS = new ArrayList(); + public static ArrayMap blocks = new ArrayMap(); + public static ArrayList items = new ArrayList(); public static boolean isFluid(int bl) { return (bl == 8 || bl == 9 || bl == 60 || bl == 61 || bl == 62 || bl == 63 || bl == 64 || bl == 65 || bl == 66 || bl == 67); @@ -29,275 +29,275 @@ public class Items { public static void loadItems() { //0 - ITEMS.add(null); + items.add(null); //1 - ITEMS.add(new Item("Stone", 0, 0, 1)); + items.add(new Item("Stone", 0, 0, 1)); //2 - ITEMS.add(new Item("Grass", 1, 0, 2)); + items.add(new Item("Grass", 1, 0, 2)); //3 - ITEMS.add(new Item("Dirt", 2, 0, 3)); + items.add(new Item("Dirt", 2, 0, 3)); //4 - ITEMS.add(new Item("Cobblestone", 3, 0, 4)); + items.add(new Item("Cobblestone", 3, 0, 4)); //5 - ITEMS.add(new Item("Planks", 4, 0, 5)); + items.add(new Item("Planks", 4, 0, 5)); //6 - ITEMS.add(new Item("Sapling", 5, 0, 6)); + items.add(new Item("Sapling", 5, 0, 6)); //7 - ITEMS.add(new Item("Bedrock", 6, 0, 7)); + items.add(new Item("Bedrock", 6, 0, 7)); //8 - ITEMS.add(new Item("Sand", 9, 0, 10)); + items.add(new Item("Sand", 9, 0, 10)); //9 - ITEMS.add(new Item("Gravel", 10, 0, 11)); + items.add(new Item("Gravel", 10, 0, 11)); //10 - ITEMS.add(new Item("Golden Ore", 11, 0, 12)); + items.add(new Item("Golden Ore", 11, 0, 12)); //11 - ITEMS.add(new Item("Iron Ore", 12, 0, 13)); + items.add(new Item("Iron Ore", 12, 0, 13)); //12 - ITEMS.add(new Item("Coal Ore", 13, 0, 14)); + items.add(new Item("Coal Ore", 13, 0, 14)); //13 - ITEMS.add(new Item("Wood", 14, 0, 15)); + items.add(new Item("Wood", 14, 0, 15)); //14 - ITEMS.add(new Item("Leaves", 15, 0, 16)); + items.add(new Item("Leaves", 15, 0, 16)); //15 - ITEMS.add(new Item("Glass", 17, 0, 18)); + items.add(new Item("Glass", 17, 0, 18)); //16 - ITEMS.add(new Item("Lapis Ore", 18, 0, 19)); + items.add(new Item("Lapis Ore", 18, 0, 19)); //17 - ITEMS.add(new Item("Lapis Block", 19, 0, 20)); + items.add(new Item("Lapis Block", 19, 0, 20)); //18 - ITEMS.add(new Item("Sandstone", 20, 0, 21)); + items.add(new Item("Sandstone", 20, 0, 21)); //19 - ITEMS.add(new Item("Cobweb", 24, 0, 25)); + items.add(new Item("Cobweb", 24, 0, 25)); //20 - ITEMS.add(new Item("Tall Grass", 25, 0, 26)); + items.add(new Item("Tall Grass", 25, 0, 26)); //21 - ITEMS.add(new Item("Dead Bush", 26, 0, 27)); + items.add(new Item("Dead Bush", 26, 0, 27)); //22 - ITEMS.add(new Item("Bricks", 27, 0, 28)); + items.add(new Item("Bricks", 27, 0, 28)); //23 - ITEMS.add(new Item("Dandelion", 28, 0, 29)); + items.add(new Item("Dandelion", 28, 0, 29)); //24 - ITEMS.add(new Item("Rose", 29, 0, 30)); + items.add(new Item("Rose", 29, 0, 30)); //25 - ITEMS.add(new Item("Mushroom", 30, 0, 31)); + items.add(new Item("Mushroom", 30, 0, 31)); //26 - ITEMS.add(new Item("Mushroom", 31, 0, 32)); + items.add(new Item("Mushroom", 31, 0, 32)); //27 - ITEMS.add(new Item("White Wool", 32, 0, 33)); + items.add(new Item("White Wool", 32, 0, 33)); //28 - ITEMS.add(new Item("Orange Wool", 33, 0, 34)); + items.add(new Item("Orange Wool", 33, 0, 34)); //29 - ITEMS.add(new Item("Magenta Wool", 34, 0, 35)); + items.add(new Item("Magenta Wool", 34, 0, 35)); //30 - ITEMS.add(new Item("Light Blue Wool", 35, 0, 36)); + items.add(new Item("Light Blue Wool", 35, 0, 36)); //31 - ITEMS.add(new Item("Yellow Wool", 36, 0, 37)); + items.add(new Item("Yellow Wool", 36, 0, 37)); //32 - ITEMS.add(new Item("Lime Wool", 37, 0, 38)); + items.add(new Item("Lime Wool", 37, 0, 38)); //33 - ITEMS.add(new Item("Pink Wool", 38, 0, 39)); + items.add(new Item("Pink Wool", 38, 0, 39)); //34 - ITEMS.add(new Item("Gray Wool", 39, 0, 40)); + items.add(new Item("Gray Wool", 39, 0, 40)); //35 - ITEMS.add(new Item("Light Gray Wool", 40, 0, 41)); + items.add(new Item("Light Gray Wool", 40, 0, 41)); //36 - ITEMS.add(new Item("Cyan Wool", 41, 0, 42)); + items.add(new Item("Cyan Wool", 41, 0, 42)); //37 - ITEMS.add(new Item("Purple Wool", 42, 0, 43)); + items.add(new Item("Purple Wool", 42, 0, 43)); //38 - ITEMS.add(new Item("Blue Wool", 43, 0, 44)); + items.add(new Item("Blue Wool", 43, 0, 44)); //39 - ITEMS.add(new Item("Brown Wool", 44, 0, 45)); + items.add(new Item("Brown Wool", 44, 0, 45)); //40 - ITEMS.add(new Item("Green Wool", 45, 0, 46)); + items.add(new Item("Green Wool", 45, 0, 46)); //41 - ITEMS.add(new Item("Red Wool", 46, 0, 47)); + items.add(new Item("Red Wool", 46, 0, 47)); //42 - ITEMS.add(new Item("Black Wool", 47, 0, 48)); + items.add(new Item("Black Wool", 47, 0, 48)); //43 - ITEMS.add(new Item("Golden Block", 48, 0, 49)); + items.add(new Item("Golden Block", 48, 0, 49)); //44 - ITEMS.add(new Item("Iron Block", 49, 0, 50)); + items.add(new Item("Iron Block", 49, 0, 50)); //45 - ITEMS.add(new Item("Stone Slab", 50, 0, 51)); + items.add(new Item("Stone Slab", 50, 0, 51)); //46 - ITEMS.add(new Item("Sandstone Slab", 52, 0, 53)); + items.add(new Item("Sandstone Slab", 52, 0, 53)); //47 - ITEMS.add(new Item("Wooden Slab", 53, 0, 54)); + items.add(new Item("Wooden Slab", 53, 0, 54)); //48 - ITEMS.add(new Item("Cobblestone Slab", 54, 0, 55)); + items.add(new Item("Cobblestone Slab", 54, 0, 55)); //49 - ITEMS.add(new Item("Brick Slab", 55, 0, 56)); + items.add(new Item("Brick Slab", 55, 0, 56)); //50 - ITEMS.add(new Item("Stone Brick", 64, 0, 57)); + items.add(new Item("Stone Brick", 64, 0, 57)); //51 - ITEMS.add(new Item("Stone Brick Slab", 56, 0, 58)); + items.add(new Item("Stone Brick Slab", 56, 0, 58)); //52 - ITEMS.add(new Item("Cactus", 57, 0, 59)); + items.add(new Item("Cactus", 57, 0, 59)); //53 - ITEMS.add(new Item("Obsidian", 65, 0, 68)); + items.add(new Item("Obsidian", 65, 0, 68)); //54 - ITEMS.add(new Item("Wooden Sword", 0, 1)); + items.add(new Item("Wooden Sword", 0, 1)); //55 - ITEMS.add(new Item("Stone Sword", 1, 1)); + items.add(new Item("Stone Sword", 1, 1)); //56 - ITEMS.add(new Item("Iron Sword", 2, 1)); + items.add(new Item("Iron Sword", 2, 1)); //57 - ITEMS.add(new Item("Diamond Sword", 3, 1)); + items.add(new Item("Diamond Sword", 3, 1)); //58 - ITEMS.add(new Item("Golden Sword", 4, 1)); + items.add(new Item("Golden Sword", 4, 1)); //59 - ITEMS.add(new Item("Wooden Shovel", 5, 1)); + items.add(new Item("Wooden Shovel", 5, 1)); //60 - ITEMS.add(new Item("Stone Shovel", 6, 1)); + items.add(new Item("Stone Shovel", 6, 1)); //61 - ITEMS.add(new Item("Iron Shovel", 7, 1)); + items.add(new Item("Iron Shovel", 7, 1)); //62 - ITEMS.add(new Item("Diamond Shovel", 8, 1)); + items.add(new Item("Diamond Shovel", 8, 1)); //63 - ITEMS.add(new Item("Golden Shovel", 9, 1)); + items.add(new Item("Golden Shovel", 9, 1)); } public static void loadBlocks() { //0 - BLOCKS.put("none", null); + blocks.put("none", null); //1 - BLOCKS.put("stone", new Block(0, 450, 4)); + blocks.put("stone", new Block(0, 450, 4)); //2 - BLOCKS.put("grass", new Block(1, 54, 3)); + blocks.put("grass", new Block(1, 54, 3)); //3 - BLOCKS.put("dirt", new Block(2, 45, 3)); + blocks.put("dirt", new Block(2, 45, 3)); //4 - BLOCKS.put("cobblestone", new Block(3, 600, 4)); + blocks.put("cobblestone", new Block(3, 600, 4)); //5 - BLOCKS.put("planks", new Block(4, 180, 5)); + blocks.put("planks", new Block(4, 180, 5)); //6 - BLOCKS.put("sapling", new Block(5, 0, 6, false, false, true)); + blocks.put("sapling", new Block(5, 0, 6, false, false, true)); //7 - BLOCKS.put("bedrock", new Block(6, -1, 7)); + blocks.put("bedrock", new Block(6, -1, 7)); //8 - BLOCKS.put("water", new Block(7, -1, 0, false, false, true)); + blocks.put("water", new Block(7, -1, 0, false, false, true)); //9 - BLOCKS.put("lava", new Block(8, -1, 0, false, false, false)); + blocks.put("lava", new Block(8, -1, 0, false, false, false)); //10 - BLOCKS.put("sand", new Block(9, 45, 8)); + blocks.put("sand", new Block(9, 45, 8)); //11 - BLOCKS.put("gravel", new Block(10, 54, 9)); + blocks.put("gravel", new Block(10, 54, 9)); //12 - BLOCKS.put("gold_ore", new Block(11, 900, 10)); + blocks.put("gold_ore", new Block(11, 900, 10)); //13 - BLOCKS.put("iron_ore", new Block(12, 900, 11)); + blocks.put("iron_ore", new Block(12, 900, 11)); //14 - BLOCKS.put("coal_ore", new Block(13, 900, 0)); + blocks.put("coal_ore", new Block(13, 900, 0)); //15 - BLOCKS.put("log", new Block(14, 180, 13)); + blocks.put("log", new Block(14, 180, 13)); //16 - BLOCKS.put("leaves", new Block(15, 21, 0)); + blocks.put("leaves", new Block(15, 21, 0)); //17 - BLOCKS.put("sponge", new Block(16, 54, 0)); + blocks.put("sponge", new Block(16, 54, 0)); //18 - BLOCKS.put("glass", new Block(17, 27, 0, true, false, true)); + blocks.put("glass", new Block(17, 27, 0, true, false, true)); //19 - BLOCKS.put("lapis_ore", new Block(18, 900, 0)); + blocks.put("lapis_ore", new Block(18, 900, 0)); //20 - BLOCKS.put("lapis_block", new Block(19, 900, 17)); + blocks.put("lapis_block", new Block(19, 900, 17)); //21 - BLOCKS.put("sandstone", new Block(20, 240, 18)); + blocks.put("sandstone", new Block(20, 240, 18)); //22 - BLOCKS.put("noteblock", new Block(21, 75, 0)); + blocks.put("noteblock", new Block(21, 75, 0)); //23 - BLOCKS.put("bed_l", new Block(22, 21, 0, false, true, true)); + blocks.put("bed_l", new Block(22, 21, 0, false, true, true)); //24 - BLOCKS.put("bed_r", new Block(23, 21, 0, false, true, true)); + blocks.put("bed_r", new Block(23, 21, 0, false, true, true)); //25 - BLOCKS.put("cobweb", new Block(24, 1200, 0, false, false, true)); + blocks.put("cobweb", new Block(24, 1200, 0, false, false, true)); //26 - BLOCKS.put("tallgrass", new Block(25, 0, 0, false, false, true)); + blocks.put("tallgrass", new Block(25, 0, 0, false, false, true)); //27 - BLOCKS.put("deadbush", new Block(26, 0, 0, false, false, true)); + blocks.put("deadbush", new Block(26, 0, 0, false, false, true)); //28 - BLOCKS.put("brick_block", new Block(27, 600, 22)); + blocks.put("brick_block", new Block(27, 600, 22)); //29 - BLOCKS.put("dandelion", new Block(28, 0, 23, false, false, true)); + blocks.put("dandelion", new Block(28, 0, 23, false, false, true)); //30 - BLOCKS.put("rose", new Block(29, 0, 24, false, false, true)); + blocks.put("rose", new Block(29, 0, 24, false, false, true)); //31 - BLOCKS.put("brown_mushroom", new Block(30, 0, 25, false, false, true)); + blocks.put("brown_mushroom", new Block(30, 0, 25, false, false, true)); //32 - BLOCKS.put("red_mushroom", new Block(31, 0, 26, false, false, true)); + blocks.put("red_mushroom", new Block(31, 0, 26, false, false, true)); //33 - BLOCKS.put("wool_while", new Block(32, 75, 27, true, false, false)); + blocks.put("wool_while", new Block(32, 75, 27, true, false, false)); //34 - BLOCKS.put("wool_orange", new Block(33, 75, 28, true, false, false)); + blocks.put("wool_orange", new Block(33, 75, 28, true, false, false)); //35 - BLOCKS.put("wool_magenta", new Block(34, 75, 29, true, false, false)); + blocks.put("wool_magenta", new Block(34, 75, 29, true, false, false)); //36 - BLOCKS.put("wool_lightblue", new Block(35, 75, 30, true, false, false)); + blocks.put("wool_lightblue", new Block(35, 75, 30, true, false, false)); //37 - BLOCKS.put("wool_yellow", new Block(36, 75, 31, true, false, false)); + blocks.put("wool_yellow", new Block(36, 75, 31, true, false, false)); //38 - BLOCKS.put("wool_lime", new Block(37, 75, 32, true, false, false)); + blocks.put("wool_lime", new Block(37, 75, 32, true, false, false)); //39 - BLOCKS.put("wool_pink", new Block(38, 75, 33, true, false, false)); + blocks.put("wool_pink", new Block(38, 75, 33, true, false, false)); //40 - BLOCKS.put("wool_gray", new Block(39, 75, 34, true, false, false)); + blocks.put("wool_gray", new Block(39, 75, 34, true, false, false)); //41 - BLOCKS.put("wool_lightgray", new Block(40, 75, 35, true, false, false)); + blocks.put("wool_lightgray", new Block(40, 75, 35, true, false, false)); //42 - BLOCKS.put("wool_cyan", new Block(41, 75, 36, true, false, false)); + blocks.put("wool_cyan", new Block(41, 75, 36, true, false, false)); //43 - BLOCKS.put("wool_purple", new Block(42, 75, 37, true, false, false)); + blocks.put("wool_purple", new Block(42, 75, 37, true, false, false)); //44 - BLOCKS.put("wool_blue", new Block(43, 75, 38, true, false, false)); + blocks.put("wool_blue", new Block(43, 75, 38, true, false, false)); //45 - BLOCKS.put("wool_brown", new Block(44, 75, 39, true, false, false)); + blocks.put("wool_brown", new Block(44, 75, 39, true, false, false)); //46 - BLOCKS.put("wool_green", new Block(45, 75, 40, true, false, false)); + blocks.put("wool_green", new Block(45, 75, 40, true, false, false)); //47 - BLOCKS.put("wool_red", new Block(46, 75, 41, true, false, false)); + blocks.put("wool_red", new Block(46, 75, 41, true, false, false)); //48 - BLOCKS.put("wool_black", new Block(47, 75, 42, true, false, false)); + blocks.put("wool_black", new Block(47, 75, 42, true, false, false)); //49 - BLOCKS.put("gold_block", new Block(48, 900, 43)); + blocks.put("gold_block", new Block(48, 900, 43)); //50 - BLOCKS.put("iron_block", new Block(49, 1500, 44)); + blocks.put("iron_block", new Block(49, 1500, 44)); //51 - BLOCKS.put("stone_slab", new Block(0, 8, 16, 8, 50, 600, 45, true, false, true)); + blocks.put("stone_slab", new Block(0, 8, 16, 8, 50, 600, 45, true, false, true)); //52 - BLOCKS.put("double_stone_slab", new Block(51, 600, 45)); + blocks.put("double_stone_slab", new Block(51, 600, 45)); //53 - BLOCKS.put("sandstone_slab", new Block(0, 8, 16, 8, 52, 600, 46, true, false, true)); + blocks.put("sandstone_slab", new Block(0, 8, 16, 8, 52, 600, 46, true, false, true)); //54 - BLOCKS.put("wooden_slab", new Block(0, 8, 16, 8, 53, 180, 47, true, false, true)); + blocks.put("wooden_slab", new Block(0, 8, 16, 8, 53, 180, 47, true, false, true)); //55 - BLOCKS.put("cobblestone_slab", new Block(0, 8, 16, 8, 54, 600, 48, true, false, true)); + blocks.put("cobblestone_slab", new Block(0, 8, 16, 8, 54, 600, 48, true, false, true)); //56 - BLOCKS.put("brick_slab", new Block(0, 8, 16, 8, 55, 600, 49, true, false, true)); + blocks.put("brick_slab", new Block(0, 8, 16, 8, 55, 600, 49, true, false, true)); //57 - BLOCKS.put("stonebrick", new Block(64, 450, 50)); + blocks.put("stonebrick", new Block(64, 450, 50)); //58 - BLOCKS.put("stone_brick_slab", new Block(0, 8, 16, 8, 56, 450, 51, true, false, true)); + blocks.put("stone_brick_slab", new Block(0, 8, 16, 8, 56, 450, 51, true, false, true)); //59 - BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, 39, 52, true, false, true)); + blocks.put("cactus", new Block(1, 0, 14, 16, 57, 39, 52, true, false, true)); //60 - BLOCKS.put("water_16", new Block(7, -1, 0, false, false, true)); + blocks.put("water_16", new Block(7, -1, 0, false, false, true)); //61 - BLOCKS.put("water_12", new Block(58, -1, 0, false, false, true)); + blocks.put("water_12", new Block(58, -1, 0, false, false, true)); //62 - BLOCKS.put("water_8", new Block(59, -1, 0, false, false, true)); + blocks.put("water_8", new Block(59, -1, 0, false, false, true)); //63 - BLOCKS.put("water_4", new Block(60, -1, 0, false, false, true)); + blocks.put("water_4", new Block(60, -1, 0, false, false, true)); //64 - BLOCKS.put("lava_16", new Block(8, -1, 0, false, false, true)); + blocks.put("lava_16", new Block(8, -1, 0, false, false, true)); //65 - BLOCKS.put("lava_12", new Block(61, -1, 0, false, false, true)); + blocks.put("lava_12", new Block(61, -1, 0, false, false, true)); //66 - BLOCKS.put("lava_8", new Block(62, -1, 0, false, false, true)); + blocks.put("lava_8", new Block(62, -1, 0, false, false, true)); //67 - BLOCKS.put("lava_4", new Block(63, -1, 0, false, false, true)); + blocks.put("lava_4", new Block(63, -1, 0, false, false, true)); //68 - BLOCKS.put("obsidian", new Block(65, 1500, 53)); + blocks.put("obsidian", new Block(65, 1500, 53)); } public static void load() { diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java index 441d75f..de84119 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java @@ -28,7 +28,7 @@ public class FallingGravel extends Mob { @Override public void draw(SpriteBatch spriteBatch, float x, float y) { - spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.get("gravel").getTexture()], x, y); + spriteBatch.draw(Assets.blockTex[Items.blocks.get("gravel").getTex()], x, y); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java index a410eb3..8c76619 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java @@ -28,7 +28,7 @@ public class FallingSand extends Mob { @Override public void draw(SpriteBatch spriteBatch, float x, float y) { - spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.get("sand").getTexture()], x, y); + spriteBatch.draw(Assets.blockTex[Items.blocks.get("sand").getTex()], x, y); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java index dfd8351..839e383 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java @@ -5,34 +5,34 @@ import com.badlogic.gdx.math.Rectangle; public class Block { private int x, y, w, h; - private int texture; + private int tex; private int hp, drop; - public boolean collision, background, transparent; + public boolean coll, bg, tp; - public Block(int texture, int hp, int drop) { - this(0, 0, 16, 16, texture, hp, drop, true, false, false); + public Block(int tex, int hp, int drop) { + this(0, 0, 16, 16, tex, hp, drop, true, false, false); } - public Block(int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) { - this(0, 0, 16, 16, texture, hp, drop, collision, background, transparent); + public Block(int tex, int hp, int drop, boolean coll, boolean bg, boolean tp) { + this(0, 0, 16, 16, tex, hp, drop, coll, bg, tp); } - public Block(int x, int y, int w, int h, int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) { + public Block(int x, int y, int w, int h, int tex, int hp, int drop, boolean coll, boolean bg, boolean tp) { this.x = x; this.y = y; this.w = w; this.h = h; - this.texture = texture; + this.tex = tex; this.hp = hp; this.drop = drop; - this.collision = collision; - this.background = background; - this.transparent = transparent; + this.coll = coll; + this.bg = bg; + this.tp = tp; } - public int getTexture() { - return texture; + public int getTex() { + return tex; } public int getHp() { @@ -50,7 +50,7 @@ public class Block { } public boolean toJump() { - return (y < 8 && collision); + return (y < 8 && coll); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java index 8c13881..b34a917 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java @@ -2,24 +2,24 @@ package ru.deadsoftware.cavecraft.game.objects; public class Item { - private int texture; + private int tex; private int type; // 0 - block, 1 - tool, 2 - other private int block; private String name; - public Item(String name, int texture, int type) { - this(name, texture, type, -1); + public Item(String name, int tex, int type) { + this(name, tex, type, -1); } - public Item(String name, int texture, int type, int block) { + public Item(String name, int tex, int type, int block) { this.name = name; - this.texture = texture; + this.tex = tex; this.type = type; this.block = block; } - public int getTexture() { - return texture; + public int getTex() { + return tex; } public int getType() { diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java index d7da1c5..a1f50e6 100644 --- a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java @@ -13,14 +13,14 @@ import ru.deadsoftware.cavecraft.misc.Renderer; public class MenuRenderer extends Renderer { - public Array