From: fred-boy Date: Mon, 23 Dec 2019 08:37:41 +0000 (+0700) Subject: Fix codestyle X-Git-Tag: alpha0.4~21 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=59d48c1b28c570755327a8fb0827fa57e7fd3914;p=cavedroid.git Fix codestyle --- diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java b/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java index 1f0302c..d069a40 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java @@ -34,7 +34,9 @@ class GameFluidsThread extends Thread { private int getNextBlockStateId(int id) { int nextState = getNextBlockState(id); - if (nextState == -1) return 0; + if (nextState == -1) { + return 0; + } if (isWater(id)) { return WATER_IDS[nextState]; } @@ -100,8 +102,12 @@ class GameFluidsThread extends Thread { } private void updateFluids(int x, int y) { - if (!isFluid(id(x, y))) return; - if (drainFluid(x, y)) return; + if (!isFluid(id(x, y))) { + return; + } + if (drainFluid(x, y)) { + return; + } flowFluid(x, y); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index 379f930..bef9b55 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -61,12 +61,16 @@ public class GameInput { case Input.Keys.A: GP.player.getMove().x = -GamePhysics.PL_SPEED; GP.player.setDir(Mob.Direction.LEFT); - if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true; + if (CaveGame.TOUCH && checkSwim()) { + GP.player.swim = true; + } break; case Input.Keys.D: GP.player.getMove().x = GamePhysics.PL_SPEED; GP.player.setDir(Mob.Direction.RIGHT); - if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true; + if (CaveGame.TOUCH && checkSwim()) { + GP.player.swim = true; + } break; case Input.Keys.W: case Input.Keys.SPACE: @@ -130,9 +134,14 @@ public class GameInput { curX += GP.player.looksLeft() ? 1 : -1; } } else if (!CaveGame.TOUCH) { - curX = (int) (Gdx.input.getX() * (GP.renderer.getWidth() / GameScreen.getWidth()) + GP.renderer.getCamX()) / 16; - curY = (int) (Gdx.input.getY() * (GP.renderer.getHeight() / GameScreen.getHeight()) + GP.renderer.getCamY()) / 16; - if (curX < 0) curX--; + curX = (int) (Gdx.input.getX() * (GP.renderer.getWidth() / + GameScreen.getWidth()) + GP.renderer.getCamX()) / 16; + + curY = (int) (Gdx.input.getY() * (GP.renderer.getHeight() / + GameScreen.getHeight()) + GP.renderer.getCamY()) / 16; + if (curX < 0) { + curX--; + } } if (pastX != curX || pastY != curY) { @@ -276,15 +285,21 @@ public class GameInput { case Input.Keys.A: case Input.Keys.D: GP.player.getMove().x = 0; - if (CaveGame.TOUCH && GP.player.swim) GP.player.swim = false; + if (CaveGame.TOUCH && GP.player.swim) { + GP.player.swim = false; + } break; case Input.Keys.W: case Input.Keys.S: case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: - if (GP.player.isFlyMode()) GP.player.getMove().y = 0; - if (GP.player.swim) GP.player.swim = false; + if (GP.player.isFlyMode()) { + GP.player.getMove().y = 0; + } + if (GP.player.swim) { + GP.player.swim = false; + } break; } } @@ -309,7 +324,9 @@ public class GameInput { int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - creative.getRegionWidth() / 2 + 8)) / 18; int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - creative.getRegionHeight() / 2 + 18)) / 18; int item = creativeScroll * 8 + (ix + iy * 8); - if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1; + if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) { + item = -1; + } if (item >= 0 && item < GameItems.getItemsSize()) { System.arraycopy(GP.player.inventory, 0, GP.player.inventory, 1, 8); GP.player.inventory[0] = item; @@ -336,9 +353,12 @@ public class GameInput { creativeScroll -= (screenY - touchDownY) / 16; touchDownX = screenX; touchDownY = screenY; - if (creativeScroll < 0) creativeScroll = 0; - if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL) + if (creativeScroll < 0) { + creativeScroll = 0; + } + if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL) { creativeScroll = GameProc.MAX_CREATIVE_SCROLL; + } } } } @@ -347,14 +367,21 @@ public class GameInput { switch (CaveGame.GAME_STATE) { case PLAY: GP.player.slot += amount; - if (GP.player.slot < 0) GP.player.slot = 8; - if (GP.player.slot > 8) GP.player.slot = 0; + if (GP.player.slot < 0) { + GP.player.slot = 8; + } + if (GP.player.slot > 8) { + GP.player.slot = 0; + } break; case CREATIVE_INV: creativeScroll += amount; - if (creativeScroll < 0) creativeScroll = 0; - if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL) + if (creativeScroll < 0) { + creativeScroll = 0; + } + if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL) { creativeScroll = GameProc.MAX_CREATIVE_SCROLL; + } break; } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameItems.java b/core/src/ru/deadsoftware/cavedroid/game/GameItems.java index b6f84ec..625938f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameItems.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameItems.java @@ -90,8 +90,11 @@ public class GameItems { } static Sprite getItemTex(int id) { - if (items.getValueAt(id).getType().equals("block")) return getBlockTex(id); - else return getItem(id).getTex(); + if (items.getValueAt(id).getType().equals("block")) { + return getBlockTex(id); + } else { + return getItem(id).getTex(); + } } public static void load() { diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index 8ebb260..d753b66 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java @@ -194,7 +194,9 @@ class GamePhysics { } } - player.x += player.getMove().x * (player.isFlyMode() ? 1.5f : 1) * (GameItems.isFluid(getBlock(player)) && !player.isFlyMode() ? .8f : 1); + player.x += player.getMove().x * (player.isFlyMode() ? 1.5f : 1) * + (GameItems.isFluid(getBlock(player)) && !player.isFlyMode() ? .8f : 1); + mobXColl(player); if (CaveGame.TOUCH && !player.isFlyMode() && player.canJump() && player.getMove().x != 0 && checkJump(player)) { diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java index ff6d174..afd9134 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java @@ -23,22 +23,15 @@ public class GameProc implements Serializable, Disposable { static boolean DO_UPD = false; static int UPD_X = -1, UPD_Y = -1; - - private transient GameFluidsThread fluidThread; + public final Player player; + public final LinkedList mobs; + final LinkedList drops; public transient GameWorld world; public transient GameRenderer renderer; public transient GameInput input; - transient GamePhysics physics; - public ControlMode controlMode; - public final Player player; - public final LinkedList mobs; - final LinkedList drops; - - public void resetRenderer() { - int scale = CaveGame.TOUCH ? 320 : 480; - renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth()); - } + transient GamePhysics physics; + private transient GameFluidsThread fluidThread; public GameProc(int gameMode) { world = new GameWorld(WORLD_WIDTH, WORLD_HEIGHT); @@ -52,6 +45,11 @@ public class GameProc implements Serializable, Disposable { startFluidThread(); } + public void resetRenderer() { + int scale = CaveGame.TOUCH ? 320 : 480; + renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth()); + } + private void startFluidThread() { fluidThread = new GameFluidsThread(); fluidThread.start(); @@ -104,7 +102,9 @@ public class GameProc implements Serializable, Disposable { physics.update(); input.update(); blockUpdater(); - if (fluidThread == null || !fluidThread.isAlive()) startFluidThread(); + if (fluidThread == null || !fluidThread.isAlive()) { + startFluidThread(); + } } @Override diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java index 28e93bb..76d806f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java @@ -46,14 +46,16 @@ public class GameRenderer extends Renderer { if ((!GP.world.hasForeAt(x, y) || GP.world.getForeMapBlock(x, y).isTransparent()) && GP.world.hasBackAt(x, y)) { spriter.draw(GP.world.getBackMapBlock(x, y).getTex(), drawX(x), drawY(y)); - if (!GP.world.hasForeAt(x, y) && x == GP.input.getCurX() && y == GP.input.getCurY()) + if (!GP.world.hasForeAt(x, y) && x == GP.input.getCurX() && y == GP.input.getCurY()) { drawWreck(GP.world.getBackMap(GP.input.getCurX(), GP.input.getCurY())); + } } } if (GP.world.hasForeAt(x, y) && GP.world.getForeMapBlock(x, y).isBackground() == drawBG) { spriter.draw(GP.world.getForeMapBlock(x, y).getTex(), drawX(x), drawY(y)); - if (x == GP.input.getCurX() && y == GP.input.getCurY()) + if (x == GP.input.getCurX() && y == GP.input.getCurY()) { drawWreck(GP.world.getForeMap(GP.input.getCurX(), GP.input.getCurY())); + } } } @@ -62,8 +64,12 @@ public class GameRenderer extends Renderer { 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 > GP.world.getHeight()) maxY = GP.world.getHeight(); + if (minY < 0) { + minY = 0; + } + if (maxY > GP.world.getHeight()) { + maxY = GP.world.getHeight(); + } for (int y = minY; y < maxY; y++) { for (int x = minX; x < maxX; x++) { drawBlock(x, y, bg); @@ -78,8 +84,9 @@ public class GameRenderer extends Renderer { for (int y = minY; y < maxY; y++) { for (int x = minX; x < maxX; x++) { if ((!GP.world.hasForeAt(x, y) || GP.world.getForeMapBlock(x, y).isTransparent()) - && GP.world.hasBackAt(x, y)) + && GP.world.hasBackAt(x, y)) { shaper.rect(drawX(x), drawY(y), 16, 16); + } } } shaper.end(); @@ -115,7 +122,7 @@ public class GameRenderer extends Renderer { spriter.draw(textureRegions.get("handle"), x + 156, y + 18 + (GP.input.getCreativeScroll() * (72f / GameProc.MAX_CREATIVE_SCROLL))); for (int i = GP.input.getCreativeScroll() * 8; i < GP.input.getCreativeScroll() * 8 + 40; i++) { - if (i > 0 && i < GameItems.getItemsSize()) + if (i > 0 && i < GameItems.getItemsSize()) { if (GameItems.getItem(i).isBlock()) { spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(i)).getTex(), x + 8 + ((i - GP.input.getCreativeScroll() * 8) % 8) * 18, @@ -125,9 +132,10 @@ public class GameRenderer extends Renderer { x + 8 + ((i - GP.input.getCreativeScroll() * 8) % 8) * 18, y + 18 + ((i - GP.input.getCreativeScroll() * 8) / 8) * 18); } + } } for (int i = 0; i < 9; i++) { - if (GP.player.inventory[i] > 0) + if (GP.player.inventory[i] > 0) { if (GameItems.getItem(GP.player.inventory[i]).isBlock()) { spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inventory[i])).getTex(), x + 8 + i * 18, y + creative.getRegionHeight() - 24); @@ -135,6 +143,7 @@ public class GameRenderer extends Renderer { spriter.draw(GameItems.getItem(GP.player.inventory[i]).getTex(), x + 8 + i * 18, y + creative.getRegionHeight() - 24); } + } } } @@ -147,10 +156,11 @@ public class GameRenderer extends Renderer { if (GP.world.hasForeAt(GP.input.getCurX(), GP.input.getCurY()) || GP.world.hasBackAt(GP.input.getCurX(), GP.input.getCurY()) || GP.controlMode == ControlMode.CURSOR || - !CaveGame.TOUCH) + !CaveGame.TOUCH) { spriter.draw(cursor, GP.input.getCurX() * 16 - getCamX(), GP.input.getCurY() * 16 - getCamY()); + } spriter.draw(hotbar, getWidth() / 2 - (float) hotbar.getRegionWidth() / 2, 0); for (int i = 0; i < 9; i++) { if (GP.player.inventory[i] > 0) { @@ -205,7 +215,9 @@ public class GameRenderer extends Renderer { break; } - if (CaveGame.TOUCH) drawTouchGui(); + if (CaveGame.TOUCH) { + drawTouchGui(); + } spriter.end(); diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java index 38e2959..0788561 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java @@ -58,11 +58,15 @@ public class GameSaver { for (int x = 0; x < width; x += rl) { rl = in.readInt(); bl = in.readInt(); - for (int i = x; i < x + rl; i++) map[i][y] = bl; + for (int i = x; i < x + rl; i++) { + map[i][y] = bl; + } } } in.close(); - } else throw new Exception("version mismatch"); + } else { + throw new Exception("version mismatch"); + } return map; } @@ -72,8 +76,11 @@ public class GameSaver { try { ObjectInputStream in = new ObjectInputStream(file.read()); int ver = in.readInt(); - if (VERSION == ver) gameProc = (GameProc) in.readObject(); - else throw new Exception("version mismatch"); + if (VERSION == ver) { + gameProc = (GameProc) in.readObject(); + } else { + throw new Exception("version mismatch"); + } in.close(); gameProc.world = new GameWorld( loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")), diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java index 01ddee9..c5e7d46 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameWorld.java @@ -55,7 +55,9 @@ public class GameWorld { private int transformX(int x) { x = x % getWidth(); - if (x < 0) x = getWidth() - Math.abs(x); + if (x < 0) { + x = getWidth() - Math.abs(x); + } return x; } @@ -72,8 +74,11 @@ public class GameWorld { private void setMap(int x, int y, int layer, int value) { try { x = transformX(x); - if (layer == 0) foreMap[x][y] = value; - else backMap[x][y] = value; + if (layer == 0) { + foreMap[x][y] = value; + } else { + backMap[x][y] = value; + } } catch (ArrayIndexOutOfBoundsException ignored) { } } @@ -152,16 +157,18 @@ public class GameWorld { } public void destroyForeMap(int x, int y) { - if (GameItems.getBlock(getForeMap(x, y)).hasDrop()) + if (GameItems.getBlock(getForeMap(x, y)).hasDrop()) { GP.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4, GameItems.getItemId(GameItems.getBlock(getForeMap(x, y)).getDrop()))); + } placeToForeground(x, y, 0); } public void destroyBackMap(int x, int y) { - if (GameItems.getBlock(getBackMap(x, y)).hasDrop()) + if (GameItems.getBlock(getBackMap(x, y)).hasDrop()) { GP.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4, GameItems.getItemId(GameItems.getBlock(getBackMap(x, y)).getDrop()))); + } placeToBackground(x, y, 0); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java b/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java index f820190..4c9b9b2 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavedroid/game/WorldGen.java @@ -23,15 +23,25 @@ class WorldGen { res[0] = mid; 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 (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); + 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] < min) res[i] = min; - if (res[i] > max) res[i] = max; + if (res[i] < min) { + res[i] = min; + } + if (res[i] > max) { + res[i] = max; + } bMap[i] = 0; // if (i >= width / 2) { // bMap[i] = 1; @@ -40,7 +50,9 @@ class WorldGen { // bMap[i] = 0; // } } - if (res[0] < res[width - 1]) res[width - 1] = res[0]; + if (res[0] < res[width - 1]) { + res[width - 1] = res[0]; + } return res; } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java index c46def3..3eb10eb 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java @@ -14,6 +14,7 @@ public class FallingGravel extends Mob { /** * Creates a FallingGravel mob at coordinates + * * @param x X in pixels * @param y Y in pixels */ diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java index ee310e4..89b20e1 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java @@ -14,6 +14,7 @@ public class FallingSand extends Mob { /** * Creates a FallingSand mob at coordinates + * * @param x X in pixels * @param y Y in pixels */ diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java index 723a929..5f73a6b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java @@ -16,8 +16,11 @@ public abstract class Mob extends Rectangle implements Serializable { protected Vector2 move; protected Type type; + protected int animDelta = 6; + protected int anim; private Direction dir; - + private boolean dead; + private boolean canJump, flyMode; /** * @param x in pixels * @param y in pixels @@ -34,12 +37,6 @@ public abstract class Mob extends Rectangle implements Serializable { this.type = type; } - private boolean dead; - - private boolean canJump, flyMode; - protected int animDelta = 6; - protected int anim; - protected static Direction randomDir() { return MathUtils.randomBoolean(.5f) ? Direction.LEFT : Direction.RIGHT; } @@ -59,7 +56,6 @@ public abstract class Mob extends Rectangle implements Serializable { } /** - * * @return The Y coordinate if mob's vertical center in blocks */ public final int getMiddleMapY() { @@ -67,7 +63,6 @@ public abstract class Mob extends Rectangle implements Serializable { } /** - * * @return The Y coordinate of mob's legs in blocks */ public final int getLowerMapY() { @@ -161,6 +156,12 @@ public abstract class Mob extends Rectangle implements Serializable { } } + public abstract void draw(SpriteBatch spriteBatch, float x, float y); + + public abstract void ai(); + + public abstract void changeDir(); + public enum Type { MOB, SAND, @@ -171,10 +172,4 @@ public abstract class Mob extends Rectangle implements Serializable { LEFT, RIGHT } - - public abstract void draw(SpriteBatch spriteBatch, float x, float y); - - public abstract void ai(); - - public abstract void changeDir(); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java index e687a02..cfa1cd8 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java @@ -9,8 +9,8 @@ import static ru.deadsoftware.cavedroid.GameScreen.GP; public class Player extends Mob { public final int[] inventory; - public int slot; public final int gameMode; + public int slot; public boolean swim; public Player(int gameMode) { @@ -69,8 +69,9 @@ public class Player extends Mob { 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) { animDelta = -animDelta; + } //back hand Assets.playerSprite[1][2].setPosition(x - 6, y); diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java index c99f505..b6628cb 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java @@ -3,6 +3,8 @@ package ru.deadsoftware.cavedroid.game.objects; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Rectangle; +import javax.annotation.CheckForNull; + public class Block { private final int x; @@ -21,23 +23,22 @@ public class Block { private final boolean fluid; /** - * - * @param left margin from left edge - * @param top margin from top edge - * @param right margin from right edge + * @param left margin from left edge + * @param top margin from top edge + * @param right margin from right edge * @param bottom margin from bottom edge - * @param hp hit points - * @param drop id of an item the block will drop when destroyed - * @param coll true if block has collision - * @param bg true if block should be drawn behind player - * @param tp true if block is transparent and renderer should draw a block behind it - * @param rb true if block should break when there is no block with collision under it - * @param fluid true if fluid - * @param meta extra info for storing - * @param tex block's texture + * @param hp hit points + * @param drop id of an item the block will drop when destroyed + * @param coll true if block has collision + * @param bg true if block should be drawn behind player + * @param tp true if block is transparent and renderer should draw a block behind it + * @param rb true if block should break when there is no block with collision under it + * @param fluid true if fluid + * @param meta extra info for storing + * @param tex block's texture */ - public Block(int left, int top, int right, int bottom, int hp, - String drop, boolean coll, boolean bg, boolean tp, boolean rb, boolean fluid, String meta, Sprite tex) { + public Block(int left, int top, int right, int bottom, int hp, String drop, boolean coll, boolean bg, boolean tp, + boolean rb, boolean fluid, String meta, @CheckForNull Sprite tex) { this.x = left; this.y = top; this.w = 16 - right - left; @@ -51,7 +52,9 @@ public class Block { this.fluid = fluid; this.meta = meta; this.tex = tex; - if (this.tex != null) this.tex.flip(false, true); + if (this.tex != null) { + this.tex.flip(false, true); + } } public boolean hasCollision() { diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java index 0083001..9868a96 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java @@ -2,17 +2,21 @@ package ru.deadsoftware.cavedroid.game.objects; import com.badlogic.gdx.graphics.g2d.Sprite; +import javax.annotation.CheckForNull; + public class Item { private final String name; private final String type; private final Sprite tex; - public Item(String name, String type, Sprite tex) { + public Item(String name, String type, @CheckForNull Sprite tex) { this.name = name; this.type = type; this.tex = tex; - if (this.tex != null) this.tex.flip(false, true); + if (this.tex != null) { + this.tex.flip(false, true); + } } public Sprite getTex() { diff --git a/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java b/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java index fa24eb7..bc78f21 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java @@ -11,11 +11,9 @@ public class Button { DISABLED = 0, NORMAL = 1, SELECTED = 2; - - private ButtonEventListener listener; - private final Rectangle rect; private final String label; + private ButtonEventListener listener; private int type; /** diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java index 17367d8..dcb06d3 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java @@ -9,8 +9,8 @@ import com.badlogic.gdx.utils.JsonValue; import ru.deadsoftware.cavedroid.CaveGame; import ru.deadsoftware.cavedroid.GameScreen; import ru.deadsoftware.cavedroid.menu.objects.Button; -import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer; import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener; +import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer; import ru.deadsoftware.cavedroid.misc.Assets; import java.util.HashMap; @@ -28,8 +28,8 @@ public abstract class Menu { private ArrayMap buttons; /** - * @param width Viewport width - * @param height Viewport height + * @param width Viewport width + * @param height Viewport height * @param buttonRenderer {@link ButtonRenderer} that will draw the buttons of this menu */ Menu(float width, float height, ButtonRenderer buttonRenderer) { @@ -56,7 +56,9 @@ public abstract class Menu { * @param jsonFile A {@link FileHandle} to json file */ void loadButtonsFromJson(FileHandle jsonFile) { - if (buttons == null) buttons = new ArrayMap<>(); + if (buttons == null) { + buttons = new ArrayMap<>(); + } HashMap eventListeners = getButtonEventListeners(); JsonValue json = Assets.jsonReader.parse(jsonFile); int y = (int) height / 4; @@ -64,7 +66,8 @@ public abstract class Menu { buttons.put(key.name(), new Button(Assets.getStringFromJson(key, "label", ""), (int) width / 2 - Button.WIDTH / 2, - Assets.getIntFromJson(key, "y", y), Assets.getIntFromJson(key, "type", Button.NORMAL), + Assets.getIntFromJson(key, "y", y), + Assets.getIntFromJson(key, "type", Button.NORMAL), eventListeners.containsKey(key.name()) ? eventListeners.get(key.name()) : () -> { })); } diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java index 5abb5f1..10db012 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java @@ -3,8 +3,8 @@ package ru.deadsoftware.cavedroid.menu.submenus; import com.badlogic.gdx.Gdx; import ru.deadsoftware.cavedroid.game.GameSaver; import ru.deadsoftware.cavedroid.menu.objects.Button; -import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer; import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener; +import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer; import java.util.HashMap; diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java index 8fc025c..6e6b666 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java @@ -1,8 +1,8 @@ package ru.deadsoftware.cavedroid.menu.submenus; import com.badlogic.gdx.Gdx; -import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer; import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener; +import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer; import java.util.HashMap; diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java index 0dd1cf7..1e53141 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.ArrayMap; import com.badlogic.gdx.utils.JsonReader; import com.badlogic.gdx.utils.JsonValue; @@ -17,16 +16,14 @@ import java.util.HashMap; public class Assets { public static final JsonReader jsonReader = new JsonReader(); - - private static final GlyphLayout glyphLayout = new GlyphLayout(); - static BitmapFont minecraftFont; - public static final Sprite[][] playerSprite = new Sprite[2][4]; public static final Sprite[][] pigSprite = new Sprite[2][2]; public static final HashMap textureRegions = new HashMap<>(); public static final ArrayMap guiMap = new ArrayMap<>(); + private static final GlyphLayout glyphLayout = new GlyphLayout(); public static Sprite sandSprite; public static Sprite gravelSprite; + static BitmapFont minecraftFont; private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) { return new TextureRegion(texture, x, y + height, width, -height); @@ -83,7 +80,8 @@ public class Assets { for (JsonValue file = json.child(); file != null; file = file.next()) { Texture texture = new Texture(Gdx.files.internal(file.name() + ".png")); if (file.size == 0) { - textureRegions.put(file.name(), flippedRegion(texture, 0, 0, texture.getWidth(), texture.getHeight())); + textureRegions.put(file.name(), + flippedRegion(texture, 0, 0, texture.getWidth(), texture.getHeight())); } else { for (JsonValue key = file.child(); key != null; key = key.next()) { int x = getIntFromJson(key, "x", 0); diff --git a/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java b/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java index 359ac98..6a7e4d3 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java @@ -47,8 +47,12 @@ public class InputHandlerGame extends InputAdapter { boolean mouse = Assets.getBooleanFromJson(key, "mouse", false); String name = key.getString("key"); int code = mouse ? getMouseKey(name) : Input.Keys.valueOf(name); - if (x < 0) x = GP.renderer.getWidth() + x; - if (y < 0) y = GP.renderer.getHeight() + y; + if (x < 0) { + x = GP.renderer.getWidth() + x; + } + if (y < 0) { + y = GP.renderer.getHeight() + y; + } Assets.guiMap.put(key.name(), new TouchButton(new Rectangle(x, y, w, h), code, mouse)); } diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Renderer.java b/core/src/ru/deadsoftware/cavedroid/misc/Renderer.java index 179b76a..a6154ee 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/Renderer.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/Renderer.java @@ -8,10 +8,9 @@ import ru.deadsoftware.cavedroid.GameScreen; public abstract class Renderer implements InputProcessor { - private final OrthographicCamera camera; - protected final ShapeRenderer shaper; protected final SpriteBatch spriter; + private final OrthographicCamera camera; protected Renderer() { this(GameScreen.getWidth(), GameScreen.getHeight());