diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
index a908971baef7191e0f105a1dd7589978de3816a3..d4a66bcb8ad622ca43193d9df7f9cdb95d24d020 100644 (file)
package ru.deadsoftware.cavedroid.game.world;
-import com.badlogic.gdx.utils.Disposable;
-import com.badlogic.gdx.utils.TimeUtils;
import kotlin.Pair;
import ru.deadsoftware.cavedroid.game.GameItems;
import ru.deadsoftware.cavedroid.game.GameScope;
-import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
-import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
import ru.deadsoftware.cavedroid.game.mobs.MobsController;
+import ru.deadsoftware.cavedroid.game.model.block.Block;
import ru.deadsoftware.cavedroid.game.model.world.generator.WorldGeneratorConfig;
-import ru.deadsoftware.cavedroid.game.objects.Block;
import ru.deadsoftware.cavedroid.game.objects.DropController;
import javax.annotation.CheckForNull;
import javax.inject.Inject;
-import java.sql.Time;
-import java.util.Timer;
@GameScope
-public class GameWorld implements Disposable {
-
- private static final int DEFAULT_WIDTH = 1024;
- private static final int DEFAULT_HEIGHT = 256;
- private static final int UPDATE_RANGE = 16;
+public class GameWorld {
private final DropController mDropController;
private final MobsController mMobsController;
- private final Timer mGameFluidsTimer;
- private final GameFluidsThread mGameFluidsThread;
-
private final int mWidth;
private final int mHeight;
private final int[][] mForeMap;
private final int[][] mBackMap;
- private boolean mShouldUpdate;
- private int mUpdateX;
- private int mUpdateY;
-
@Inject
public GameWorld(DropController dropController,
MobsController mobsController,
boolean isNewGame = foreMap == null || backMap == null;
if (isNewGame) {
- mWidth = DEFAULT_WIDTH;
- mHeight = DEFAULT_HEIGHT;
- Pair<int[][], int[][]> maps = new GameWorldGenerator(WorldGeneratorConfig.Companion.getDefaultWithSeed(TimeUtils.millis())).generate();
+ final WorldGeneratorConfig config = WorldGeneratorConfig.Companion.getDefault();
+ mWidth = config.getWidth();
+ mHeight = config.getHeight();
+ Pair<int[][], int[][]> maps = new GameWorldGenerator(config).generate();
mForeMap = maps.getFirst();
mBackMap = maps.getSecond();
mMobsController.getPlayer().respawn(this);
mWidth = mForeMap.length;
mHeight = mForeMap[0].length;
}
-
- mGameFluidsThread = new GameFluidsThread(this, mMobsController);
-
- mGameFluidsTimer = new Timer();
- mGameFluidsTimer.scheduleAtFixedRate(mGameFluidsThread, 0, GameFluidsThread.FLUID_UPDATE_INTERVAL_MS);
}
public int getWidth() {
setMap(x, y, 1, id);
}
- private void placeSlab(int x, int y, int value) {
- switch (value) {
- case 51:
- setForeMap(x, y, 52);
- break;
- case 53:
- setForeMap(x, y, 21);
- break;
- case 54:
- setForeMap(x, y, 5);
- break;
- case 55:
- setForeMap(x, y, 4);
- break;
- case 56:
- setForeMap(x, y, 28);
- break;
- case 58:
- setForeMap(x, y, 57);
- break;
- }
- }
-
public void placeToForeground(int x, int y, int value) {
if (!hasForeAt(x, y) || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
setForeMap(x, y, value);
} else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
- placeSlab(x, y, value);
+ final Block block = GameItems.getBlock(value);
+ if (block instanceof Block.Slab) {
+ setForeMap(x, y, GameItems.getBlockId(((Block.Slab) block).getFullBlockKey()));
+ }
}
- mUpdateX = x - 8;
- mUpdateY = y - 8;
- mShouldUpdate = true;
}
public void placeToBackground(int x, int y, int value) {
}
placeToBackground(x, y, 0);
}
-
- private void updateBlock(int x, int y) {
- if (getForeMap(x, y) == 10) {
- if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
- setForeMap(x, y, 0);
- mMobsController.addMob(FallingSand.class, x * 16, y * 16);
- updateBlock(x, y - 1);
- }
- }
-
- if (getForeMap(x, y) == 11) {
- if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
- setForeMap(x, y, 0);
- mMobsController.addMob(FallingGravel.class, x * 16, y * 16);
- updateBlock(x, y - 1);
- }
- }
-
- if (hasForeAt(x, y) && getForeMapBlock(x, y).requiresBlock()) {
- if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
- destroyForeMap(x, y);
- updateBlock(x, y - 1);
- }
- }
-
- if (getForeMap(x, y) == 2) {
- if (hasForeAt(x, y - 1) && (getForeMapBlock(x, y - 1).hasCollision() ||
- GameItems.isFluid(getForeMap(x, y - 1)))) {
- setForeMap(x, y, 3);
- }
- }
- }
-
- public void update() {
- if (mShouldUpdate) {
- for (int y = mUpdateY; y < mUpdateY + UPDATE_RANGE; y++) {
- for (int x = mUpdateX; x < mUpdateX + UPDATE_RANGE; x++) {
- updateBlock(x, y);
- }
- }
- mShouldUpdate = false;
- }
- }
-
- @Override
- public void dispose() {
- mGameFluidsTimer.cancel();
- }
}
\ No newline at end of file