summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 976cc57)
raw | patch | inline | side by side (parent: 976cc57)
author | fred-boy <fredboy@protonmail.com> | |
Thu, 26 Sep 2019 17:50:54 +0000 (00:50 +0700) | ||
committer | fred-boy <fredboy@protonmail.com> | |
Sun, 29 Sep 2019 04:39:17 +0000 (11:39 +0700) |
core/src/ru/deadsoftware/cavedroid/GameScreen.java | patch | blob | history | |
core/src/ru/deadsoftware/cavedroid/game/GameProc.java | patch | blob | history |
diff --git a/core/src/ru/deadsoftware/cavedroid/GameScreen.java b/core/src/ru/deadsoftware/cavedroid/GameScreen.java
index d30adba9f7d173279ef9021e1de08576ce9a3317..759cbc0db800c5e8467ad7b18f59578c34565ed0 100644 (file)
break;
case GOTO_MENU:
+ GP.dispose();
menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
renderer = menuRenderer;
Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java
index cd957a0842583ebc6f8fc5ec87bc353a60a6abfa..c2fca908a889f7dff2591e2239fee7df1b64b609 100644 (file)
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 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;
+ private transient Thread fluidThread;
+
public transient GameWorld world;
public transient GameRenderer renderer;
public transient GamePhysics physics;
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));
}
}
maxCreativeScroll = GameItems.getItemsSize() / 8;
- new Thread(new Runnable() {
- @Override
- public void run() {
- while (true) fluidUpdater();
+ fluidThread = new Thread(() -> {
+ while (!fluidThread.isInterrupted()) {
+ fluidUpdater();
}
- }).start();
+ });
+
+ fluidThread.start();
GameSaver.save(this);
}
} else if (GameItems.isWater(world.getForeMap(x, y + 1))) {
world.setForeMap(x, y + 1, 1);
}
- return;
}
}
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++) {
+ for (int x = (int) renderer.getCamX() / 16 - 1;
+ x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) {
updateFluids(x, y);
}
}
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;
- }
+ 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;
+ }
}
}
}
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;
}
}
}
+ @Override
+ public void dispose() {
+ fluidThread.interrupt();
+ }
}