diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java
index aa11931410fd72428ff93927d73f2b834e1b24b6..c2fca908a889f7dff2591e2239fee7df1b64b609 100644 (file)
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
+import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils;
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import com.badlogic.gdx.utils.TimeUtils;
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import java.io.Serializable;
import java.util.ArrayList;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Random;
-public class GameProc implements Serializable {
+public class GameProc implements Serializable, Disposable {
static boolean DO_UPD = false;
static int UPD_X = -1, UPD_Y = -1;
static boolean DO_UPD = false;
static int UPD_X = -1, UPD_Y = -1;
+ private transient Thread fluidThread;
+
public transient GameWorld world;
public transient GameRenderer renderer;
public transient GamePhysics physics;
public transient GameWorld world;
public transient GameRenderer renderer;
public transient GamePhysics physics;
world = new GameWorld();
world.generate(1024, 256);
player = new Player(gameMode);
world = new GameWorld();
world.generate(1024, 256);
player = new Player(gameMode);
- drops = new ArrayList<Drop>();
- mobs = new ArrayList<Mob>();
+ 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));
}
480 * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
}
maxCreativeScroll = GameItems.getItemsSize() / 8;
480 * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
}
maxCreativeScroll = GameItems.getItemsSize() / 8;
+
+ fluidThread = new Thread(() -> {
+ while (!fluidThread.isInterrupted()) {
+ fluidUpdater();
+ }
+ });
+
+ fluidThread.start();
+
GameSaver.save(this);
}
GameSaver.save(this);
}
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
world.setForeMap(x, y + 1, 1);
}
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
world.setForeMap(x, y + 1, 1);
}
- return;
}
}
}
}
if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).requiresBlock()) {
if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).requiresBlock()) {
if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
- world.destroyForeMap(x, y, this);
+ world.destroyForeMap(x, y);
updateBlock(x, y - 1);
}
}
updateBlock(x, y - 1);
}
}
}
}
}
}
+ private void fluidUpdater() {
+ for (int y = 0; y < world.getHeight(); y++) {
+ for (int x = (int) renderer.getCamX() / 16 - 1;
+ x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) {
+ updateFluids(x, y);
+ }
+ }
+ }
+
void useItem(int x, int y, int id, boolean bg) {
if (id > 0) {
void useItem(int x, int y, int id, boolean bg) {
if (id > 0) {
- switch (GameItems.getItem(id).getType()) {
- case 0:
- if (!bg) world.placeToForeground(x, y, GameItems.getItem(id).getBlock());
- else world.placeToBackground(x, y, GameItems.getItem(id).getBlock());
- break;
- case 2:
- switch (id) {
- case 65:
- world.placeToForeground(x, y, 8);
- player.inv[player.invSlot] = 64;
- break;
- case 66:
- world.placeToForeground(x, y, 9);
- player.inv[player.invSlot] = 64;
- break;
- }
- break;
+ if (GameItems.getItem(id).isBlock()) {
+ if (!bg) world.placeToForeground(x, y, GameItems.getBlockIdByItemId(id));
+ else world.placeToBackground(x, y, GameItems.getBlockIdByItemId(id));
+ } else {
+ switch (id) {
+ case 65:
+ world.placeToForeground(x, y, 8);
+ player.inv[player.invSlot] = 64;
+ break;
+ case 66:
+ world.placeToForeground(x, y, 9);
+ player.inv[player.invSlot] = 64;
+ break;
+ }
}
}
}
}
}
}
DO_UPD = false;
}
DO_UPD = false;
}
- for (int y = 0; y < world.getHeight(); y++) {
- for (int x = (int) renderer.getCamX() / 16 - 1; x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) {
- updateFluids(x, y);
- }
- }
-
physics.update(delta);
moveCursor();
checkCursorBounds();
physics.update(delta);
moveCursor();
checkCursorBounds();
blockDmg++;
if (world.getForeMap(curX, curY) > 0) {
if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
blockDmg++;
if (world.getForeMap(curX, curY) > 0) {
if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
- world.destroyForeMap(curX, curY, this);
+ world.destroyForeMap(curX, curY);
blockDmg = 0;
}
} else if (world.getBackMap(curX, curY) > 0) {
if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
blockDmg = 0;
}
} else if (world.getBackMap(curX, curY) > 0) {
if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
- world.destroyBackMap(curX, curY, this);
+ world.destroyBackMap(curX, curY);
blockDmg = 0;
}
}
blockDmg = 0;
}
}
useItem(curX, curY, player.inv[player.invSlot], true);
isTouchDown = false;
} else if (touchDownY < Assets.invBar.getRegionHeight() &&
useItem(curX, curY, player.inv[player.invSlot], true);
isTouchDown = false;
} else if (touchDownY < Assets.invBar.getRegionHeight() &&
- touchDownX > renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 &&
- touchDownX < renderer.getWidth() / 2 + Assets.invBar.getRegionWidth() / 2) {
+ touchDownX > renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 &&
+ touchDownX < renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) {
CaveGame.STATE = AppState.GAME_CREATIVE_INV;
isTouchDown = false;
}
}
}
CaveGame.STATE = AppState.GAME_CREATIVE_INV;
isTouchDown = false;
}
}
}
+ @Override
+ public void dispose() {
+ fluidThread.interrupt();
+ }
}
}