summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c0aa4c7)
raw | patch | inline | side by side (parent: c0aa4c7)
author | fred-boy <fredboy@protonmail.com> | |
Mon, 23 Dec 2019 08:37:41 +0000 (15:37 +0700) | ||
committer | fred-boy <fredboy@protonmail.com> | |
Mon, 23 Dec 2019 08:44:44 +0000 (15:44 +0700) |
22 files changed:
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java b/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java
index 1f0302c93e578dc7ab830446c42f2221f5a428a9..d069a4058b171a259f57ab6e8a0de86266424c5b 100644 (file)
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];
}
}
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 379f9301b782a07aa4eba9398093c3394338a2f8..bef9b558bb2471f848033ddd884f1834c4cdd9b0 100644 (file)
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:
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) {
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;
}
}
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;
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;
+ }
}
}
}
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 b6f84ecd42be2c7f20ee76e654e6088c67e14cdb..625938fd5fb76c07ce2cd1c56b24deca3cbe640c 100644 (file)
}
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 8ebb260cb8c3d39c227de71339babd835e7f910b..d753b668bc969e6410ba801fe173a594e0d510a7 100644 (file)
}
}
- 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 ff6d1740534b89923916c4a91c1307fbcba96646..afd91343eeda6c06ce04cd02c0a3c4ed68830956 100644 (file)
static boolean DO_UPD = false;
static int UPD_X = -1, UPD_Y = -1;
-
- private transient GameFluidsThread fluidThread;
+ public final Player player;
+ public final LinkedList<Mob> mobs;
+ final LinkedList<Drop> 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<Mob> mobs;
- final LinkedList<Drop> 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);
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();
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 28e93bb743438aaa45c49b511bfccc2f1d60a498..76d806f40f4c8ef977b8cac409819b22f9cde1ad 100644 (file)
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()));
+ }
}
}
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);
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();
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,
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);
spriter.draw(GameItems.getItem(GP.player.inventory[i]).getTex(),
x + 8 + i * 18, y + creative.getRegionHeight() - 24);
}
+ }
}
}
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) {
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 38e295931f27b864ed98fa94ecad05698e323e94..0788561d8edf39e8a4151278b41abd7a5398c8e3 100644 (file)
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;
}
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 01ddee9c111de4c81be866d4293cb7497d77b503..c5e7d46ecd99eb7b33f9b07eb0c762d6fdda914b 100644 (file)
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;
}
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) {
}
}
}
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 f820190320d4b5bbec7108af4da0f37a03f24813..4c9b9b23f68a1bfb823e44a1baffb087084a4b1b 100644 (file)
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;
// 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 c46def34abd58598d3655979ed25fbd6e2c6c32f..3eb10ebcda3a8474ded187c409ad933a2027088b 100644 (file)
/**
* 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 ee310e44179f1c557c512a0cd720a8dc4d41f384..89b20e1add566962fd19a873e0549ed9e3161a69 100644 (file)
/**
* 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 723a9298acc5d066dd5ada8b3dc01a99ad1a5bcf..5f73a6b4720af3ad3f185a81d6ec47fb65ac06de 100644 (file)
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
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;
}
}
/**
- *
* @return The Y coordinate if mob's vertical center in blocks
*/
public final int getMiddleMapY() {
}
/**
- *
* @return The Y coordinate of mob's legs in blocks
*/
public final int getLowerMapY() {
}
}
+ public abstract void draw(SpriteBatch spriteBatch, float x, float y);
+
+ public abstract void ai();
+
+ public abstract void changeDir();
+
public enum Type {
MOB,
SAND,
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 e687a025686d24fa834e4ae90604e1d0a2a193e8..cfa1cd8bb8c0650a4264eebd9be8aff8a534aa24 100644 (file)
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) {
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 c99f5055ff4b896c57db62224bb0256337f217a4..b6628cb20a1f283ab17f63a61e833a79461e9032 100644 (file)
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;
+import javax.annotation.CheckForNull;
+
public class Block {
private final int x;
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;
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 0083001d05d844a3744146e3e0d0cd544d7c89c8..9868a96b18d0d0dfe4a2c502cf29c50f7193f96a 100644 (file)
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 fa24eb7370797d757512691b5e2902fabd03d20d..bc78f21250e4084b0e0c63ab3c770e6903eb9a8e 100644 (file)
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 17367d8f98884ecf513f3a182f6adcd668d5af7a..dcb06d3d937877a2cf3aa8ea4dd8daf05ad119f9 100644 (file)
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;
private ArrayMap<String, Button> 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) {
* @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<String, ButtonEventListener> eventListeners = getButtonEventListeners();
JsonValue json = Assets.jsonReader.parse(jsonFile);
int y = (int) height / 4;
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 5abb5f17ecce6ba0f1de7b48c3d780462d979466..10db012c8efe278812fd3765f8e9be47acc0a7fe 100644 (file)
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 8fc025c2cafe7b630939eb5997d0043883e31f89..6e6b66656519dff6449b1aaac54ec616c4349d38 100644 (file)
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 0dd1cf7673063a33a8f89af113f6f460c9a48fb4..1e531415c63baaefd9a04111ec9e663f5cda544a 100644 (file)
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;
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<String, TextureRegion> textureRegions = new HashMap<>();
public static final ArrayMap<String, TouchButton> 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);
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 359ac98f311aa00a36297cecf1803f58e875a9e6..6a7e4d388f9dce5c22a137331361039887d7422f 100644 (file)
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 179b76acabb8bd97a7280b16410ab094b0a98089..a6154eed85952aa8889028b8b942e96987d403e6 100644 (file)
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());