From bea2a3c5b967bcd90ccd83e08e833d58449e963a Mon Sep 17 00:00:00 2001 From: fred-boy Date: Sun, 30 Sep 2018 14:11:19 +0700 Subject: [PATCH] Fix code style --- android/build.gradle | 2 +- build.gradle | 2 +- .../ru/deadsoftware/cavecraft/CaveGame.java | 64 +-- .../ru/deadsoftware/cavecraft/GameScreen.java | 14 +- .../cavecraft/game/GameInput.java | 66 +-- .../cavecraft/game/GamePhysics.java | 98 ++-- .../deadsoftware/cavecraft/game/GameProc.java | 444 +++++++++--------- .../cavecraft/game/GameRenderer.java | 176 ++++--- .../cavecraft/game/GameSaver.java | 46 +- .../cavecraft/game/GameWorld.java | 27 +- .../ru/deadsoftware/cavecraft/game/Items.java | 126 ++--- .../deadsoftware/cavecraft/game/WorldGen.java | 112 ++--- .../cavecraft/game/mobs/FallingGravel.java | 4 +- .../cavecraft/game/mobs/FallingSand.java | 3 +- .../deadsoftware/cavecraft/game/mobs/Mob.java | 8 +- .../deadsoftware/cavecraft/game/mobs/Pig.java | 25 +- .../cavecraft/game/objects/Block.java | 14 +- .../cavecraft/game/objects/Item.java | 3 + .../cavecraft/game/objects/Player.java | 2 +- .../cavecraft/menu/MenuRenderer.java | 60 ++- .../deadsoftware/cavecraft/misc/Assets.java | 80 ++-- .../cavecraft/misc/InputHandlerGame.java | 40 +- .../cavecraft/misc/InputHandlerMenu.java | 8 +- .../deadsoftware/cavecraft/misc/Renderer.java | 11 +- 24 files changed, 729 insertions(+), 706 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 23d84e2..e917a5f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -24,7 +24,7 @@ android { minSdkVersion 9 targetSdkVersion 20 versionCode 5 - versionName "alpha0.4-dev" + versionName "alpha0.4" } buildTypes { release { diff --git a/build.gradle b/build.gradle index 76faca8..c413ee9 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ allprojects { apply plugin: "eclipse" apply plugin: "idea" - version = 'alpha0.4-dev' + version = 'alpha0.4' ext { appName = "CaveCraft" gdxVersion = '1.9.7' diff --git a/core/src/ru/deadsoftware/cavecraft/CaveGame.java b/core/src/ru/deadsoftware/cavecraft/CaveGame.java index d95c477..37fd2e1 100644 --- a/core/src/ru/deadsoftware/cavecraft/CaveGame.java +++ b/core/src/ru/deadsoftware/cavecraft/CaveGame.java @@ -6,37 +6,37 @@ import ru.deadsoftware.cavecraft.misc.AppState; public class CaveGame extends Game { - public static final String VERSION = "alpha 0.4-dev"; - public static String GAME_FOLDER; - - public static AppState STATE; - - public static boolean TOUCH; - - public CaveGame() { - this(false); - } - - public CaveGame(boolean touch) { - TOUCH = touch; - STATE = AppState.MENU_MAIN; - } - - @Override - public void create () { - switch (Gdx.app.getType()) { - case Desktop: - GAME_FOLDER = System.getProperty("user.home")+"/.cavecraft"; - break; - case Android: - GAME_FOLDER = "/sdcard/cavecraft"; - break; - default: - Gdx.app.exit(); - } - Gdx.app.log("CaveGame", GAME_FOLDER); - Gdx.files.absolute(GAME_FOLDER).mkdirs(); - setScreen(new GameScreen()); - } + public static final String VERSION = "alpha 0.4"; + public static String GAME_FOLDER; + + public static AppState STATE; + + public static boolean TOUCH; + + public CaveGame() { + this(false); + } + + public CaveGame(boolean touch) { + TOUCH = touch; + STATE = AppState.MENU_MAIN; + } + + @Override + public void create() { + switch (Gdx.app.getType()) { + case Desktop: + GAME_FOLDER = System.getProperty("user.home") + "/.cavecraft"; + break; + case Android: + GAME_FOLDER = "/sdcard/cavecraft"; + break; + default: + Gdx.app.exit(); + } + Gdx.app.log("CaveGame", GAME_FOLDER); + Gdx.files.absolute(GAME_FOLDER).mkdirs(); + setScreen(new GameScreen()); + } } diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java index dc7bb60..2704dbc 100644 --- a/core/src/ru/deadsoftware/cavecraft/GameScreen.java +++ b/core/src/ru/deadsoftware/cavecraft/GameScreen.java @@ -20,7 +20,7 @@ public class GameScreen implements Screen { public GameScreen() { Assets.load(); Items.load(); - menuRenderer = new MenuRenderer(CaveGame.TOUCH?320:480); + menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480); renderer = menuRenderer; Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer)); } @@ -46,9 +46,10 @@ public class GameScreen implements Screen { @Override public void render(float delta) { - FPS = (int)(1/delta); + FPS = (int) (1 / delta); switch (CaveGame.STATE) { - case GAME_PLAY: case GAME_CREATIVE_INV: + case GAME_PLAY: + case GAME_CREATIVE_INV: game(delta); break; @@ -76,7 +77,7 @@ public class GameScreen implements Screen { break; case GOTO_MENU: - menuRenderer = new MenuRenderer(CaveGame.TOUCH?320:480); + menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480); renderer = menuRenderer; Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer)); break; @@ -88,10 +89,11 @@ public class GameScreen implements Screen { public void resize(int width, int height) { switch (CaveGame.STATE) { case MENU_MAIN: - menuRenderer = new MenuRenderer(CaveGame.TOUCH?320:480); + menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480); renderer = menuRenderer; break; - case GAME_PLAY: case GAME_CREATIVE_INV: + case GAME_PLAY: + case GAME_CREATIVE_INV: gameProc.resetRenderer(); renderer = gameProc.renderer; break; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index 0f6c399..63cf93d 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.utils.TimeUtils; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.GameScreen; -import ru.deadsoftware.cavecraft.game.mobs.FallingSand; import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.misc.AppState; import ru.deadsoftware.cavecraft.misc.Assets; @@ -18,12 +17,12 @@ public class GameInput { } 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(gameProc.world.getForeMap((int) (gameProc.player.position.x + gameProc.player.width / 2) / 16, + (int) (gameProc.player.position.y + gameProc.player.height / 4 * 3) / 16))); } private void wasdPressed(int keycode) { - if (gameProc.ctrlMode==0 || !CaveGame.TOUCH) { + if (gameProc.ctrlMode == 0 || !CaveGame.TOUCH) { switch (keycode) { case Input.Keys.A: gameProc.player.moveX.x = -GamePhysics.PL_SPEED; @@ -36,7 +35,7 @@ public class GameInput { if (CaveGame.TOUCH && checkSwim()) gameProc.swim = true; break; } - } else if (CaveGame.TOUCH){ + } else if (CaveGame.TOUCH) { switch (keycode) { case Input.Keys.A: gameProc.cursorX--; @@ -55,7 +54,7 @@ public class GameInput { } } - public void keyDown(int keycode) { + public void keyDown(int keycode) { gameProc.isKeyDown = true; gameProc.keyDownCode = keycode; if (keycode == Input.Keys.W || keycode == Input.Keys.A || @@ -88,14 +87,15 @@ public class GameInput { case Input.Keys.E: if (CaveGame.STATE == AppState.GAME_PLAY) CaveGame.STATE = AppState.GAME_CREATIVE_INV; - else CaveGame.STATE = AppState.GAME_PLAY; + else CaveGame.STATE = AppState.GAME_PLAY; break; case Input.Keys.G: - gameProc.mobs.add(new Pig(gameProc.cursorX*16, gameProc.cursorY*16)); + gameProc.mobs.add(new Pig(gameProc.cursorX * 16, gameProc.cursorY * 16)); break; - case Input.Keys.ESCAPE: case Input.Keys.BACK: + case Input.Keys.ESCAPE: + case Input.Keys.BACK: CaveGame.STATE = AppState.GOTO_MENU; break; @@ -107,12 +107,14 @@ public class GameInput { public void keyUp(int keycode) { switch (keycode) { - case Input.Keys.A: case Input.Keys.D: + case Input.Keys.A: + case Input.Keys.D: gameProc.player.moveX.x = 0; if (CaveGame.TOUCH && gameProc.swim) gameProc.swim = false; break; - case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: + case Input.Keys.SPACE: + case Input.Keys.CONTROL_LEFT: if (gameProc.player.flyMode) gameProc.player.moveY.setZero(); if (gameProc.swim) gameProc.swim = false; break; @@ -137,14 +139,14 @@ public class GameInput { } if (gameProc.isTouchDown) { if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && - screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 && - screenXgameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 && - screenY 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); - if (ix>=8 || ix<0 || iy<0 || iy>=5) item=-1; + int item = gameProc.creativeScroll * 8 + (ix + iy * 8); + if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1; if (item >= 0 && item < Items.ITEMS.size()) { for (int i = 8; i > 0; i--) { gameProc.player.inventory[i] = gameProc.player.inventory[i - 1]; @@ -153,13 +155,13 @@ public class GameInput { } } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) { CaveGame.STATE = AppState.GAME_PLAY; - } else if (screenYgameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && - 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); + } else if (button == Input.Buttons.RIGHT) { gameProc.useItem(gameProc.cursorX, gameProc.cursorY, - gameProc.player.inventory[gameProc.invSlot], false); + gameProc.player.inventory[gameProc.invSlot], false); } else if (button == Input.Buttons.LEFT) { gameProc.blockDmg = 0; } @@ -168,11 +170,11 @@ public class GameInput { } 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 && - screenXgameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 && - screenY 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; @@ -191,10 +193,10 @@ public class GameInput { if (gameProc.invSlot > 8) gameProc.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; + gameProc.creativeScroll += amount; + if (gameProc.creativeScroll < 0) gameProc.creativeScroll = 0; + if (gameProc.creativeScroll > gameProc.maxCreativeScroll) + gameProc.creativeScroll = gameProc.maxCreativeScroll; break; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index e38e3b0..66f4236 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -21,40 +21,40 @@ public class GamePhysics { public GamePhysics(GameProc gameProc) { this.gameProc = gameProc; - gravity = new Vector2(0,.9f); + gravity = new Vector2(0, .9f); } private boolean checkJump(Rectangle rect, int dir) { int bl; switch (dir) { case 0: - bl = gameProc.world.getForeMap((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16)); - if (checkColl(new Rectangle(rect.x-8, rect.y-18, rect.width, rect.height))) bl=0; + bl = gameProc.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)); - if (checkColl(new Rectangle(rect.x+rect.width+8, rect.y-18, rect.width, rect.height))) bl=0; + bl = gameProc.world.getForeMap((int) ((rect.x + rect.width + 8) / 16), (int) ((rect.y + rect.height - 8) / 16)); + if (checkColl(new Rectangle(rect.x + rect.width + 8, rect.y - 18, rect.width, rect.height))) bl = 0; break; default: - bl=0; + 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) { int bl; - int minX = (int) ((rect.x+rect.width/2)/16)-4; - int minY = (int) ((rect.y+rect.height/2)/16)-4; - 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(); - for (int y=minY; y0 && Items.BLOCKS.getValueAt(bl).collision){ - if (Intersector.overlaps(rect, Items.BLOCKS.getValueAt(bl).getRect(x,y))){ + int minX = (int) ((rect.x + rect.width / 2) / 16) - 4; + int minY = (int) ((rect.y + rect.height / 2) / 16) - 4; + 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(); + 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))) { return true; } } @@ -64,11 +64,11 @@ 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 gameProc.world.getForeMap((int) (rect.x + rect.width / 2) / 16, (int) (rect.y + rect.height / 8 * 7) / 16); } private void dropPhy(Drop drop) { - if (drop.move.y < 9) drop.move.y += gravity.y/4; + if (drop.move.y < 9) drop.move.y += gravity.y / 4; drop.position.add(drop.move); drop.position.y = MathUtils.round(drop.position.y); while (checkColl(drop.getRect())) { @@ -81,36 +81,36 @@ public class GamePhysics { pl.position.add(pl.moveY); if (checkColl(pl.getRect())) { int d = -1; - if (pl.moveY.y<0) d=1; - if (d==-1) { + if (pl.moveY.y < 0) d = 1; + if (d == -1) { pl.flyMode = false; pl.canJump = true; } pl.position.y = MathUtils.round(pl.position.y); - while (checkColl(pl.getRect())) pl.position.y+=d; + while (checkColl(pl.getRect())) pl.position.y += d; pl.moveY.setZero(); } else { pl.canJump = false; } if (Items.isFluid(getBlock(pl.getRect()))) { - if (CaveGame.TOUCH && pl.moveX.x!=0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; + if (CaveGame.TOUCH && pl.moveX.x != 0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; if (!gameProc.swim) { if (!pl.flyMode && pl.moveY.y < 4.5f) pl.moveY.add(gravity.x / 4, gravity.y / 4); if (!pl.flyMode && pl.moveY.y > 4.5f) pl.moveY.add(0, -1f); } else { pl.moveY.add(0, -.5f); - if (pl.moveY.y<-3) pl.moveY.y = -3; + if (pl.moveY.y < -3) pl.moveY.y = -3; } } else { - if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity); + if (!pl.flyMode && pl.moveY.y < 18) pl.moveY.add(gravity); } pl.position.add(pl.moveX); if (checkColl(pl.getRect())) { - if (pl.canJump && !pl.flyMode) pl.position.y-=8; + if (pl.canJump && !pl.flyMode) pl.position.y -= 8; if (checkColl(pl.getRect())) { - if (pl.canJump && !pl.flyMode) pl.position.y+=8; + if (pl.canJump && !pl.flyMode) pl.position.y += 8; int d = 0; if (pl.moveX.x < 0) d = 1; else if (pl.moveX.x > 0) d = -1; @@ -118,9 +118,10 @@ 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) { + 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 (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && !pl.moveX.equals(Vector2.Zero)) { @@ -133,13 +134,13 @@ public class GamePhysics { mob.position.add(mob.moveY); if (checkColl(mob.getRect())) { int d = -1; - if (mob.moveY.y<0) d=1; - if (d==-1) mob.canJump = true; + if (mob.moveY.y < 0) d = 1; + if (d == -1) mob.canJump = true; mob.position.y = MathUtils.round(mob.position.y); - while (checkColl(mob.getRect())) mob.position.y+=d; + while (checkColl(mob.getRect())) mob.position.y += d; mob.moveY.setZero(); if (mob.getType() > 0) { - gameProc.world.setForeMap((int)mob.position.x/16, (int)mob.position.y/16, mob.getType()); + gameProc.world.setForeMap((int) mob.position.x / 16, (int) mob.position.y / 16, mob.getType()); mob.position.y = -1; mob.dead = true; } @@ -147,19 +148,19 @@ public class GamePhysics { mob.canJump = false; } - if (mob.getType()==0 && Items.isFluid(getBlock(mob.getRect()))) { + if (mob.getType() == 0 && Items.isFluid(getBlock(mob.getRect()))) { if (mob.moveY.y > 9) mob.moveY.add(0, -.9f); mob.moveY.add(0, -.5f); - if (mob.moveY.y<-3) mob.moveY.y = -3; - } else if (mob.moveY.y<18) mob.moveY.add(gravity); + if (mob.moveY.y < -3) mob.moveY.y = -3; + } else if (mob.moveY.y < 18) mob.moveY.add(gravity); mob.position.add(mob.moveX); if (checkColl(mob.getRect())) { if (mob.canJump) { - mob.position.y-=8; + mob.position.y -= 8; } if (checkColl(mob.getRect())) { - if (mob.canJump) mob.position.y+=8; + if (mob.canJump) mob.position.y += 8; int d = 0; if (mob.moveX.x < 0) d = 1; else if (mob.moveX.x > 0) d = -1; @@ -168,16 +169,17 @@ 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 += 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) { mob.position.y = 0; } if (checkJump(mob.getRect(), mob.dir) && mob.canJump && !mob.moveX.equals(Vector2.Zero)) { mob.moveY.add(0, -8); mob.canJump = false; } -} + } public void update(float delta) { for (Iterator it = gameProc.drops.iterator(); it.hasNext(); ) { @@ -188,7 +190,7 @@ public class GamePhysics { if (drop.pickedUp) it.remove(); } - for (Iterator it = gameProc.mobs.iterator(); it.hasNext();) { + for (Iterator it = gameProc.mobs.iterator(); it.hasNext(); ) { Mob mob = it.next(); mob.ai(); mobPhy(mob); @@ -199,8 +201,8 @@ public class GamePhysics { playerPhy(gameProc.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, + 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 ); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 25658c1..e4d12b2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -17,7 +17,7 @@ import ru.deadsoftware.cavecraft.misc.Assets; import java.io.Serializable; import java.util.ArrayList; -public class GameProc implements Serializable{ +public class GameProc implements Serializable { public static double RUN_TIME = 0; @@ -46,39 +46,39 @@ public class GameProc implements Serializable{ public GameProc() { world = new GameWorld(); - world.generate(1024,256); + world.generate(1024, 256); player = new Player(world.getSpawnPoint()); drops = new ArrayList(); mobs = new ArrayList(); - for (int i=0; i<16; i++) { - mobs.add(new Pig(i*256, 196*16)); + for (int i = 0; i < 16; i++) { + mobs.add(new Pig(i * 256, 196 * 16)); } physics = new GamePhysics(this); if (CaveGame.TOUCH) { - renderer = new GameRenderer(this,320, - 320*((float)GameScreen.getHeight()/GameScreen.getWidth())); + renderer = new GameRenderer(this, 320, + 320 * ((float) GameScreen.getHeight() / GameScreen.getWidth())); } else { ctrlMode = 1; - renderer = new GameRenderer(this,480, - 480*((float)GameScreen.getHeight()/GameScreen.getWidth())); + renderer = new GameRenderer(this, 480, + 480 * ((float) GameScreen.getHeight() / GameScreen.getWidth())); } - maxCreativeScroll = Items.ITEMS.size()/8; + maxCreativeScroll = Items.ITEMS.size() / 8; GameSaver.save(this); } public void resetRenderer() { if (CaveGame.TOUCH) { - renderer = new GameRenderer(this,320, - 320*((float)GameScreen.getHeight()/GameScreen.getWidth())); + renderer = new GameRenderer(this, 320, + 320 * ((float) GameScreen.getHeight() / GameScreen.getWidth())); } else { - renderer = new GameRenderer(this,480, - 480*((float)GameScreen.getHeight()/GameScreen.getWidth())); + renderer = new GameRenderer(this, 480, + 480 * ((float) GameScreen.getHeight() / GameScreen.getWidth())); } } private boolean isAutoselectable(int x, int y) { - return (world.getForeMap(x,y)>0 && - Items.BLOCKS.getValueAt(world.getForeMap(x,y)).collision); + return (world.getForeMap(x, y) > 0 && + Items.BLOCKS.getValueAt(world.getForeMap(x, y)).collision); } private void moveCursor() { @@ -86,7 +86,7 @@ public class GameProc implements Serializable{ if (ctrlMode == 0 && CaveGame.TOUCH) { cursorX = (int) (player.position.x + player.texWidth / 2) / 16; if (player.dir == 0) cursorX--; - else cursorX++; + else cursorX++; cursorY = (int) (player.position.y + player.texWidth) / 16; if (!isAutoselectable(cursorX, cursorY)) { cursorY++; @@ -98,249 +98,251 @@ public class GameProc implements Serializable{ if (player.dir == 0) cursorX++; else cursorX--; } - } 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; - if ((Gdx.input.getX()* - (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)<0) + } 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; + if ((Gdx.input.getX() * + (renderer.camera.viewportWidth / GameScreen.getWidth()) + renderer.camera.position.x) < 0) cursorX--; } - if (pastX!=cursorX || pastY!=cursorY) blockDmg = 0; + if (pastX != cursorX || pastY != cursorY) blockDmg = 0; } private void checkCursorBounds() { if (cursorY < 0) cursorY = 0; - if (cursorY >= world.getHeight()) cursorY = world.getHeight()-1; - if (ctrlMode==1) { - if (cursorX*16+8player.position.x+player.texWidth/2) - player.dir=1; + if (cursorY >= world.getHeight()) cursorY = world.getHeight() - 1; + if (ctrlMode == 1) { + if (cursorX * 16 + 8 < player.position.x + player.texWidth / 2) + player.dir = 0; + if (cursorX * 16 + 8 > player.position.x + player.texWidth / 2) + player.dir = 1; } } private void updateFluids(int x, int y) { - if (Items.isWater(world.getForeMap(x, y)) && world.getForeMap(x, y)!=8) { - if (world.getForeMap(x, y)==60) { + if (Items.isWater(world.getForeMap(x, y)) && world.getForeMap(x, y) != 8) { + if (world.getForeMap(x, y) == 60) { if (!Items.isWater(world.getForeMap(x, y - 1))) world.setForeMap(x, y, world.getForeMap(x, y) + 1); - } else if ((!Items.isWater(world.getForeMap(x-1,y)) || - (Items.isWater(world.getForeMap(x,y)) && world.getForeMap(x-1, y)>=world.getForeMap(x, y))) && - (!Items.isWater(world.getForeMap(x+1,y)) || - (Items.isWater(world.getForeMap(x,y)) && world.getForeMap(x+1, y)>=world.getForeMap(x, y)))){ - world.setForeMap(x, y, world.getForeMap(x, y)+1); + } else if ((!Items.isWater(world.getForeMap(x - 1, y)) || + (Items.isWater(world.getForeMap(x, y)) && world.getForeMap(x - 1, y) >= world.getForeMap(x, y))) && + (!Items.isWater(world.getForeMap(x + 1, y)) || + (Items.isWater(world.getForeMap(x, y)) && world.getForeMap(x + 1, y) >= world.getForeMap(x, y)))) { + world.setForeMap(x, y, world.getForeMap(x, y) + 1); } - if (world.getForeMap(x, y)>63) world.setForeMap(x, y, 0); + if (world.getForeMap(x, y) > 63) world.setForeMap(x, y, 0); } 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)))) { - 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) { - if (world.getForeMap(x+1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || - (Items.isWater(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>61)) { - world.setForeMap(x+1,y,61); - updateBlock(x+1, y+1); - } else if (Items.isLava(world.getForeMap(x+1, y))) { - if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4); - else world.setForeMap(x+1, y, 68); - } else if (world.getForeMap(x+1, y)==61 && (world.getForeMap(x+2, y)==8 || world.getForeMap(x+2, y)==60)) world.setForeMap(x+1, y, 8); - - if (world.getForeMap(x-1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || - (Items.isWater(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>61)) { - world.setForeMap(x-1,y,61); - updateBlock(x-1, y+1); - } else if (Items.isLava(world.getForeMap(x-1, y))) { - if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4); - else world.setForeMap(x-1, y, 68); - } else if (world.getForeMap(x-1, y)==61 && (world.getForeMap(x-2, y)==8 || world.getForeMap(x-2, y)==60)) world.setForeMap(x-1, y, 8); + 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)))) { + 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) { + if (world.getForeMap(x + 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (Items.isWater(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 61)) { + world.setForeMap(x + 1, y, 61); + updateBlock(x + 1, y + 1); + } else if (Items.isLava(world.getForeMap(x + 1, y))) { + if (world.getForeMap(x + 1, y) > 9) world.setForeMap(x + 1, y, 4); + else world.setForeMap(x + 1, y, 68); + } else if (world.getForeMap(x + 1, y) == 61 && (world.getForeMap(x + 2, y) == 8 || world.getForeMap(x + 2, y) == 60)) + world.setForeMap(x + 1, y, 8); + + if (world.getForeMap(x - 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (Items.isWater(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 61)) { + world.setForeMap(x - 1, y, 61); + updateBlock(x - 1, y + 1); + } else if (Items.isLava(world.getForeMap(x - 1, y))) { + if (world.getForeMap(x - 1, y) > 9) world.setForeMap(x - 1, y, 4); + else world.setForeMap(x - 1, y, 68); + } else if (world.getForeMap(x - 1, y) == 61 && (world.getForeMap(x - 2, y) == 8 || world.getForeMap(x - 2, y) == 60)) + world.setForeMap(x - 1, y, 8); } return; } 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)))) { - 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) { - if (world.getForeMap(x+1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || - (Items.isWater(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>62)){ - world.setForeMap(x+1,y,62); - updateBlock(x+1, y+1); - } else if (Items.isLava(world.getForeMap(x+1, y))) { - if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4); - else world.setForeMap(x+1, y, 68); + 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)))) { + 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) { + if (world.getForeMap(x + 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (Items.isWater(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 62)) { + world.setForeMap(x + 1, y, 62); + updateBlock(x + 1, y + 1); + } else if (Items.isLava(world.getForeMap(x + 1, y))) { + if (world.getForeMap(x + 1, y) > 9) world.setForeMap(x + 1, y, 4); + else world.setForeMap(x + 1, y, 68); } - if (world.getForeMap(x-1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || - (Items.isWater(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>62)){ - world.setForeMap(x-1,y,62); - updateBlock(x-1, y+1); - } else if (Items.isLava(world.getForeMap(x-1, y))) { - if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4); - else world.setForeMap(x-1, y, 68); + if (world.getForeMap(x - 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (Items.isWater(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 62)) { + world.setForeMap(x - 1, y, 62); + updateBlock(x - 1, y + 1); + } else if (Items.isLava(world.getForeMap(x - 1, y))) { + if (world.getForeMap(x - 1, y) > 9) world.setForeMap(x - 1, y, 4); + else world.setForeMap(x - 1, y, 68); } } return; } 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)))) { - 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) { - if (world.getForeMap(x+1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ){ - world.setForeMap(x+1,y,63); - updateBlock(x+1, y+1); - } else if (Items.isLava(world.getForeMap(x+1, y))) { - if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4); - else world.setForeMap(x+1, y, 68); + 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)))) { + 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) { + if (world.getForeMap(x + 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y)))) { + world.setForeMap(x + 1, y, 63); + updateBlock(x + 1, y + 1); + } else if (Items.isLava(world.getForeMap(x + 1, y))) { + if (world.getForeMap(x + 1, y) > 9) world.setForeMap(x + 1, y, 4); + else world.setForeMap(x + 1, y, 68); } - if (world.getForeMap(x-1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ){ - world.setForeMap(x-1,y,63); - updateBlock(x-1, y+1); - } else if (Items.isLava(world.getForeMap(x-1, y))) { - if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4); - else world.setForeMap(x-1, y, 68); + if (world.getForeMap(x - 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y)))) { + world.setForeMap(x - 1, y, 63); + updateBlock(x - 1, y + 1); + } else if (Items.isLava(world.getForeMap(x - 1, y))) { + if (world.getForeMap(x - 1, y) > 9) world.setForeMap(x - 1, y, 4); + else world.setForeMap(x - 1, y, 68); } } return; } 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)))) { - 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); + 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)))) { + 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); } return; } - if (Items.isLava(world.getForeMap(x, y)) && world.getForeMap(x, y)!=9) { - if (world.getForeMap(x, y)==64) { + if (Items.isLava(world.getForeMap(x, y)) && world.getForeMap(x, y) != 9) { + if (world.getForeMap(x, y) == 64) { if (!Items.isLava(world.getForeMap(x, y - 1))) world.setForeMap(x, y, world.getForeMap(x, y) + 1); - } else if ((!Items.isLava(world.getForeMap(x,y-1))) && - (!Items.isLava(world.getForeMap(x-1,y)) || - (Items.isLava(world.getForeMap(x,y)) && world.getForeMap(x-1, y)>=world.getForeMap(x, y))) && - (!Items.isLava(world.getForeMap(x+1,y)) || - (Items.isLava(world.getForeMap(x,y)) && world.getForeMap(x+1, y)>=world.getForeMap(x, y)))){ - world.setForeMap(x, y, world.getForeMap(x, y)+1); + } else if ((!Items.isLava(world.getForeMap(x, y - 1))) && + (!Items.isLava(world.getForeMap(x - 1, y)) || + (Items.isLava(world.getForeMap(x, y)) && world.getForeMap(x - 1, y) >= world.getForeMap(x, y))) && + (!Items.isLava(world.getForeMap(x + 1, y)) || + (Items.isLava(world.getForeMap(x, y)) && world.getForeMap(x + 1, y) >= world.getForeMap(x, y)))) { + world.setForeMap(x, y, world.getForeMap(x, y) + 1); } - if (world.getForeMap(x, y)>67) world.setForeMap(x, y, 0); + if (world.getForeMap(x, y) > 67) world.setForeMap(x, y, 0); } 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)))) { - 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) { - if (world.getForeMap(x+1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || - (Items.isLava(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>65)) { - world.setForeMap(x+1,y,65); - updateBlock(x+1, y+1); - } else if (Items.isWater(world.getForeMap(x+1, y))) { - world.setForeMap(x+1, y, 1); + if (world.getForeMap(x, 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)))) { + 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) { + if (world.getForeMap(x + 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (Items.isLava(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 65)) { + world.setForeMap(x + 1, y, 65); + updateBlock(x + 1, y + 1); + } else if (Items.isWater(world.getForeMap(x + 1, y))) { + world.setForeMap(x + 1, y, 1); } - if (world.getForeMap(x-1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || - (Items.isLava(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>65)) { - world.setForeMap(x-1,y,65); - updateBlock(x-1, y+1); - } else if (Items.isWater(world.getForeMap(x-1, y))) { - world.setForeMap(x-1, y, 1); + if (world.getForeMap(x - 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (Items.isLava(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 65)) { + world.setForeMap(x - 1, y, 65); + updateBlock(x - 1, y + 1); + } else if (Items.isWater(world.getForeMap(x - 1, y))) { + world.setForeMap(x - 1, y, 1); } } return; } if (world.getForeMap(x, y) == 65) { - if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=65 && world.getForeMap(x, y+1)<=67) || - (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !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) { - if (world.getForeMap(x+1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) || - (Items.isLava(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>66)){ - world.setForeMap(x+1,y,66); - updateBlock(x+1, y+1); - } else if (Items.isWater(world.getForeMap(x+1, y))) { - world.setForeMap(x+1, y, 1); + 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)))) { + 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) { + if (world.getForeMap(x + 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y))) || + (Items.isLava(world.getForeMap(x + 1, y)) && world.getForeMap(x + 1, y) > 66)) { + world.setForeMap(x + 1, y, 66); + updateBlock(x + 1, y + 1); + } else if (Items.isWater(world.getForeMap(x + 1, y))) { + world.setForeMap(x + 1, y, 1); } - if (world.getForeMap(x-1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) || - (Items.isLava(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>66)){ - world.setForeMap(x-1,y,66); - updateBlock(x-1, y+1); - } else if (Items.isWater(world.getForeMap(x-1, y))) { - world.setForeMap(x-1, y, 1); + if (world.getForeMap(x - 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y))) || + (Items.isLava(world.getForeMap(x - 1, y)) && world.getForeMap(x - 1, y) > 66)) { + world.setForeMap(x - 1, y, 66); + updateBlock(x - 1, y + 1); + } else if (Items.isWater(world.getForeMap(x - 1, y))) { + world.setForeMap(x - 1, y, 1); } } return; } if (world.getForeMap(x, y) == 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)))) { - 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) { - if (world.getForeMap(x+1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ){ - world.setForeMap(x+1,y,67); - updateBlock(x+1, y+1); - } else if (Items.isWater(world.getForeMap(x+1, y))) { - world.setForeMap(x+1, y, 1); + 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)))) { + 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) { + if (world.getForeMap(x + 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x + 1, y)).collision && !Items.isFluid(world.getForeMap(x + 1, y)))) { + world.setForeMap(x + 1, y, 67); + updateBlock(x + 1, y + 1); + } else if (Items.isWater(world.getForeMap(x + 1, y))) { + world.setForeMap(x + 1, y, 1); } - if (world.getForeMap(x-1, y)==0 || - (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ){ - world.setForeMap(x-1,y,67); - updateBlock(x-1, y+1); - } else if (Items.isWater(world.getForeMap(x-1, y))) { - world.setForeMap(x-1, y, 1); + if (world.getForeMap(x - 1, y) == 0 || + (!Items.BLOCKS.getValueAt(world.getForeMap(x - 1, y)).collision && !Items.isFluid(world.getForeMap(x - 1, y)))) { + world.setForeMap(x - 1, y, 67); + updateBlock(x - 1, y + 1); + } else if (Items.isWater(world.getForeMap(x - 1, y))) { + world.setForeMap(x - 1, y, 1); } } return; } if (world.getForeMap(x, y) == 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)))) { - 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); + 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)))) { + 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); } return; } @@ -348,40 +350,40 @@ 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)).collision) { world.setForeMap(x, y, 0); - mobs.add(new FallingSand(x*16, y*16)); - updateBlock(x, y-1); + mobs.add(new FallingSand(x * 16, y * 16)); + updateBlock(x, y - 1); } } if (world.getForeMap(x, y) == 11) { - if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x,y+1)).collision) { + if (world.getForeMap(x, y + 1) == 0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { world.setForeMap(x, y, 0); - mobs.add(new FallingGravel(x*16, y*16)); - updateBlock(x, y-1); + mobs.add(new FallingGravel(x * 16, y * 16)); + updateBlock(x, y - 1); } } if (world.getForeMap(x, y) == 59) { - if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) { - world.setForeMap(x,y,0); - updateBlock(x, y-1); + if (world.getForeMap(x, y + 1) == 0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y + 1)).collision) { + world.setForeMap(x, y, 0); + updateBlock(x, y - 1); } } if (world.getForeMap(x, y) == 2) { - if (world.getForeMap(x, y-1)>0 && (Items.BLOCKS.getValueAt(world.getForeMap(x, y-1)).collision || - Items.isFluid(world.getForeMap(x, y-1)))) { + if (world.getForeMap(x, y - 1) > 0 && (Items.BLOCKS.getValueAt(world.getForeMap(x, y - 1)).collision || + Items.isFluid(world.getForeMap(x, y - 1)))) { world.setForeMap(x, y, 3); } } } public void useItem(int x, int y, int id, boolean bg) { - if (id>0 && Items.ITEMS.get(id).getType()==0) { + 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()); + else world.placeToBackground(x, y, Items.ITEMS.get(id).getBlock()); } } @@ -389,15 +391,15 @@ public class GameProc implements Serializable{ RUN_TIME += delta; if (DO_UPD) { - for (int y=UPD_Y; y 0 && - Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp()>=0){// || world.getBackMap(cursorX, cursorY) > 0) { + Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp() >= 0) {// || world.getBackMap(cursorX, cursorY) > 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())); + 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); - blockDmg=0; + blockDmg = 0; } } } if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { - if (touchDownButton== Input.Buttons.RIGHT) { + if (touchDownButton == Input.Buttons.RIGHT) { useItem(cursorX, cursorY, 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.camera.viewportWidth / 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 3d3a8f6..5a8ab94 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -1,9 +1,7 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.CaveGame; @@ -18,51 +16,51 @@ public class GameRenderer extends Renderer { private GameProc gameProc; - public GameRenderer(GameProc gameProc,float width, float heigth) { - super(width,heigth); - Gdx.gl.glClearColor(0f,.6f,.6f,1f); + public GameRenderer(GameProc gameProc, float width, float heigth) { + super(width, heigth); + Gdx.gl.glClearColor(0f, .6f, .6f, 1f); this.gameProc = gameProc; } 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; - if (minY<0) minY=0; - if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); - for (int y=minY; y0) { + 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; + if (minY < 0) minY = 0; + if (maxY > gameProc.world.getHeight()) maxY = gameProc.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.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 (gameProc.world.getForeMap(x,y)>0 && Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).background) { + 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); + Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).getTexture()], + x * 16 - camera.position.x, y * 16 - camera.position.y); } } } } - 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; - if (minY<0) minY=0; - if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); - for (int y=minY; y0 && !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).background) { + 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; + if (minY < 0) minY = 0; + if (maxY > gameProc.world.getHeight()) maxY = gameProc.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); + Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x, y)).getTexture()], + x * 16 - camera.position.x, y * 16 - camera.position.y); } } } @@ -70,27 +68,27 @@ public class GameRenderer extends Renderer { 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.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.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.position.x - camera.position.x + gameProc.world.getWidth() * 16, mob.position.y - camera.position.y); } private void drawDrop(Drop drop) { 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()].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()].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()].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); } } private void drawPlayer(Player pl) { - if (!pl.moveX.equals(Vector2.Zero) || Assets.playerSprite[0][2].getRotation()!=0) { + if (!pl.moveX.equals(Vector2.Zero) || 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); @@ -101,7 +99,7 @@ public class GameRenderer extends Renderer { Assets.playerSprite[0][3].setRotation(0); Assets.playerSprite[1][3].setRotation(0); } - if (Assets.playerSprite[0][2].getRotation()>=60 || Assets.playerSprite[0][2].getRotation()<=-60) + if (Assets.playerSprite[0][2].getRotation() >= 60 || Assets.playerSprite[0][2].getRotation() <= -60) Player.ANIM_SPEED = -Player.ANIM_SPEED; //back hand @@ -127,23 +125,23 @@ public class GameRenderer extends Renderer { spriteBatch.draw(Assets.playerSprite[pl.dir][1], pl.position.x - camera.position.x - 2, pl.position.y - camera.position.y + 8); //item in hand - if (pl.inventory[gameProc.invSlot]>0) + if (pl.inventory[gameProc.invSlot] > 0) switch (Items.ITEMS.get(pl.inventory[gameProc.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())); + 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); 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()].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()); + -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())); + 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.itemTextures[Items.ITEMS.get(pl.inventory[gameProc.invSlot]).getTexture()].flip((pl.dir == 0), false); break; } //front hand @@ -154,18 +152,18 @@ public class GameRenderer extends Renderer { } private void drawCreative() { - float x = camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2; - float y = camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2; + 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; i0 && 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); + x + 8 + ((i - gameProc.creativeScroll * 8) % 8) * 18, + y + 18 + ((i - gameProc.creativeScroll * 8) / 8) * 18); break; case 1: spriteBatch.draw(Assets.itemTextures[Items.ITEMS.get(i).getTexture()], @@ -174,12 +172,12 @@ public class GameRenderer extends Renderer { break; } } - for (int i=0; i<9; i++) { - if (gameProc.player.inventory[i]>0) + for (int i = 0; i < 9; i++) { + if (gameProc.player.inventory[i] > 0) switch (Items.ITEMS.get(gameProc.player.inventory[i]).getType()) { case 0: spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], - x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24); + x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24); break; case 1: spriteBatch.draw(Assets.itemTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], @@ -192,26 +190,26 @@ public class GameRenderer extends Renderer { private void drawGUI() { if (gameProc.blockDmg > 0) { spriteBatch.draw(Assets.wreck[ - 10*gameProc.blockDmg/ + 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); + 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 (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0 || + gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0 || + gameProc.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); - for (int i=0; i<9; i++) { - if (gameProc.player.inventory[i]>0) { + gameProc.cursorX * 16 - camera.position.x, + gameProc.cursorY * 16 - camera.position.y); + spriteBatch.draw(Assets.invBar, camera.viewportWidth / 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()) { case 0: spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], - camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20, - 3); + camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20, + 3); break; case 1: spriteBatch.draw(Assets.itemTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()], @@ -222,20 +220,20 @@ public class GameRenderer extends Renderer { } } spriteBatch.draw(Assets.invBarCur, - camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot, + camera.viewportWidth / 2 - Assets.invBar.getRegionWidth() / 2 - 1 + 20 * gameProc.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); + 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); } } @@ -267,12 +265,12 @@ public class GameRenderer extends Renderer { if (CaveGame.TOUCH) drawTouchGui(); 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("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); } spriteBatch.end(); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java index aab81f5..a4e314b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java @@ -15,23 +15,23 @@ public class GameSaver { return ByteBuffer.allocate(4).putInt(i).array(); } - private static void saveMap(FileHandle file, int[][] map) throws IOException{ - int rl,bl; + private static void saveMap(FileHandle file, int[][] map) throws IOException { + int rl, bl; int width = map.length; int height = map[0].length; BufferedOutputStream out = new BufferedOutputStream(file.write(false)); out.write(intToBytes(VERSION)); out.write(intToBytes(width)); out.write(intToBytes(height)); - for (int y=0; y0 && Items.BLOCKS.getValueAt(getForeMap(x,y)).collision) break; + if (getForeMap(x, y) > 0 && Items.BLOCKS.getValueAt(getForeMap(x, y)).collision) break; } - x = x*16 + 4; - y = y*16 - 32; - return new Vector2(x,y); + x = x * 16 + 4; + y = y * 16 - 32; + return new Vector2(x, y); } public void generate(int w, int h) { WIDTH = w; HEIGHT = h; - WorldGen.genWorld(WIDTH,HEIGHT); + WorldGen.genWorld(WIDTH, HEIGHT); foreMap = WorldGen.getForeMap(); backMap = WorldGen.getBackMap(); WorldGen.clear(); diff --git a/core/src/ru/deadsoftware/cavecraft/game/Items.java b/core/src/ru/deadsoftware/cavecraft/game/Items.java index 690d5ac..2121ae0 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/Items.java +++ b/core/src/ru/deadsoftware/cavecraft/game/Items.java @@ -173,131 +173,131 @@ public class Items { //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/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index bf9eadf..974cef4 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -1,6 +1,5 @@ package ru.deadsoftware.cavecraft.game; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.RandomXS128; import com.badlogic.gdx.utils.TimeUtils; @@ -22,51 +21,52 @@ public class WorldGen { bMap = new int[width]; int t; res[0] = mid; - for (int i=1; i-3 && t<3) t=0; else t/=Math.abs(t); - if (i>width-(max-min)) { - if (res[i-1]+tres[0]) t=-Math.abs(t); + for (int i = 1; i < width; i++) { + t = rand.nextInt(7) - 3; + if (t > -3 && t < 3) t = 0; + else t /= Math.abs(t); + if (i > width - (max - min)) { + if (res[i - 1] + t < res[0]) t = Math.abs(t); + else if (res[i - 1] + t > res[0]) t = -Math.abs(t); } - res[i] = res[i-1] + t; - if (res[i]max) res[i] = max; - if (i>=width/2) { - bMap [i] = 1; + res[i] = res[i - 1] + t; + if (res[i] < min) res[i] = min; + if (res[i] > max) res[i] = max; + if (i >= width / 2) { + bMap[i] = 1; if (res[i] < 60) res[i] = 60; } else { bMap[i] = 0; } } - if (res[0]2 && x 2 && x < width - 2) { + if (foreMap[x][height - hMap[x] - 1] == 0 && foreMap[x][height - hMap[x]] == 2) { switch (rand.nextInt(50)) { case 0: genOak(x, height - hMap[x] - 1); break; case 1: - foreMap[x][height-hMap[x]-1] = 26; + foreMap[x][height - hMap[x] - 1] = 26; break; case 2: - foreMap[x][height-hMap[x]-1] = 29; + foreMap[x][height - hMap[x] - 1] = 29; break; case 3: - foreMap[x][height-hMap[x]-1] = 30; + foreMap[x][height - hMap[x] - 1] = 30; break; case 4: - foreMap[x][height-hMap[x]-1] = 31; + foreMap[x][height - hMap[x] - 1] = 31; break; case 5: - foreMap[x][height-hMap[x]-1] = 32; + foreMap[x][height - hMap[x] - 1] = 32; break; } } - if (foreMap[x][height-hMap[x]-1]==0 && foreMap[x][height-hMap[x]]==10) { - switch(rand.nextInt(20)) { + if (foreMap[x][height - hMap[x] - 1] == 0 && foreMap[x][height - hMap[x]] == 10) { + switch (rand.nextInt(20)) { case 0: - genCactus(x,height-hMap[x]-1); + genCactus(x, height - hMap[x] - 1); break; case 1: - foreMap[x][height-hMap[x]-1] = 27; + foreMap[x][height - hMap[x] - 1] = 27; break; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java index 0cfa261..11d02d2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.game.Items; import ru.deadsoftware.cavecraft.misc.Assets; -public class FallingGravel extends Mob{ +public class FallingGravel extends Mob { public FallingGravel(int x, int y) { dir = 0; @@ -29,7 +29,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.blockTextures[Items.BLOCKS.get("gravel").getTexture()], 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 1d6a78e..37f8a59 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java @@ -3,7 +3,6 @@ package ru.deadsoftware.cavecraft.game.mobs; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; -import ru.deadsoftware.cavecraft.game.GameProc; import ru.deadsoftware.cavecraft.game.Items; import ru.deadsoftware.cavecraft.misc.Assets; @@ -30,7 +29,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.blockTextures[Items.BLOCKS.get("sand").getTexture()], x, y); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index 180c4d1..fbab397 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -3,12 +3,10 @@ package ru.deadsoftware.cavecraft.game.mobs; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; -import ru.deadsoftware.cavecraft.game.GameProc; -import ru.deadsoftware.cavecraft.misc.Assets; import java.io.Serializable; -public abstract class Mob implements Serializable{ +public abstract class Mob implements Serializable { public int ANIM_SPEED = 6; public Vector2 position; @@ -18,8 +16,12 @@ public abstract class Mob implements Serializable{ public boolean dead; public abstract void ai(); + public abstract void changeDir(); + public abstract void draw(SpriteBatch spriteBatch, float x, float y); + public abstract Rectangle getRect(); + public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel } diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java index 04a96f6..0fa08bd 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -4,16 +4,14 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; -import ru.deadsoftware.cavecraft.game.GameWorld; import ru.deadsoftware.cavecraft.misc.Assets; -import ru.deadsoftware.cavecraft.game.GameProc; -public class Pig extends Mob{ +public class Pig extends Mob { public Pig(int x, int y) { dir = MathUtils.random(1); position = new Vector2(x, y); - moveX = new Vector2(-1+dir*2, 0); + moveX = new Vector2(-1 + dir * 2, 0); moveY = new Vector2(0, 0); width = 25; height = 18; @@ -23,8 +21,8 @@ public class Pig extends Mob{ @Override public void changeDir() { - dir=-dir+1; - moveX.set(-1+2*dir,0); + dir = -dir + 1; + moveX.set(-1 + 2 * dir, 0); } @Override @@ -32,10 +30,11 @@ public class Pig extends Mob{ if (MathUtils.randomBoolean(.0025f)) changeDir(); else if (MathUtils.randomBoolean(.0025f)) { if (moveX.x != 0f) moveX.setZero(); - else moveX.set(-1+2*dir, 0); + else moveX.set(-1 + 2 * dir, 0); } - if (moveX.x != 0f) animation+=ANIM_SPEED; else animation=0; - if (animation>=60 || animation<=-60) { + if (moveX.x != 0f) animation += ANIM_SPEED; + else animation = 0; + if (animation >= 60 || animation <= -60) { ANIM_SPEED = -ANIM_SPEED; } } @@ -45,14 +44,14 @@ public class Pig extends Mob{ Assets.pigSprite[0][1].setRotation(animation); Assets.pigSprite[1][1].setRotation(-animation); //back legs - Assets.pigSprite[1][1].setPosition(x-4+(9-dir*9),y+6); + Assets.pigSprite[1][1].setPosition(x - 4 + (9 - dir * 9), y + 6); Assets.pigSprite[1][1].draw(spriteBatch); - Assets.pigSprite[1][1].setPosition(x+17-(9*dir),y+6); + Assets.pigSprite[1][1].setPosition(x + 17 - (9 * dir), y + 6); Assets.pigSprite[1][1].draw(spriteBatch); //front legs - Assets.pigSprite[0][1].setPosition(x-4+(9-dir*9),y+6); + Assets.pigSprite[0][1].setPosition(x - 4 + (9 - dir * 9), y + 6); Assets.pigSprite[0][1].draw(spriteBatch); - Assets.pigSprite[0][1].setPosition(x+17-(9*dir),y+6); + Assets.pigSprite[0][1].setPosition(x + 17 - (9 * dir), y + 6); Assets.pigSprite[0][1].draw(spriteBatch); //head & body spriteBatch.draw(Assets.pigSprite[dir][0], x, y); diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java index 5d2814e..dfd8351 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java @@ -4,18 +4,18 @@ import com.badlogic.gdx.math.Rectangle; public class Block { - private int x,y,w,h; + private int x, y, w, h; private int texture; private int hp, drop; public boolean collision, background, transparent; public Block(int texture, int hp, int drop) { - this(0,0,16,16,texture, hp, drop, true, false, false); + this(0, 0, 16, 16, texture, 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); + this(0, 0, 16, 16, texture, hp, drop, collision, background, transparent); } public Block(int x, int y, int w, int h, int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) { @@ -44,13 +44,13 @@ public class Block { } public Rectangle getRect(int x, int y) { - x*=16; - y*=16; - return new Rectangle(x+this.x, y+this.y, w, h); + x *= 16; + y *= 16; + return new Rectangle(x + this.x, y + this.y, w, h); } public boolean toJump() { - return (y<8 && collision); + return (y < 8 && collision); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java index bc2ed8f..8c13881 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java @@ -21,12 +21,15 @@ public class Item { public int getTexture() { return texture; } + public int getType() { return type; } + public int getBlock() { return block; } + public String getName() { return name; } diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 2d5ffe8..546fb6e 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -27,7 +27,7 @@ public class Player implements Serializable { } public Rectangle getRect() { - return new Rectangle(position.x+2, position.y, width, height); + return new Rectangle(position.x + 2, position.y, width, height); } } diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java index da04d46..d7da1c5 100644 --- a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java @@ -2,7 +2,8 @@ package ru.deadsoftware.cavecraft.menu; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.Array; -import ru.deadsoftware.cavecraft.*; +import ru.deadsoftware.cavecraft.CaveGame; +import ru.deadsoftware.cavecraft.GameScreen; import ru.deadsoftware.cavecraft.game.GameSaver; import ru.deadsoftware.cavecraft.game.Items; import ru.deadsoftware.cavecraft.menu.objects.Button; @@ -15,11 +16,11 @@ public class MenuRenderer extends Renderer { public Array