X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2Fworld%2FGameWorld.java;h=43fc1641033616ec6645795ead6daed286dc82e3;hb=546c7c80eb7884183a3df1db7bb5627a18396dca;hp=18afcd4b3eec1c725a4675c5b8b429c317256da4;hpb=2aa65a4cdb47df8014f28342d460fc6639bed885;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java index 18afcd4..43fc164 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java @@ -1,13 +1,14 @@ package ru.deadsoftware.cavedroid.game.world; import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.utils.TimeUtils; +import com.badlogic.gdx.utils.Timer; 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.world.generator.WorldGeneratorConfig; import ru.deadsoftware.cavedroid.game.objects.Block; import ru.deadsoftware.cavedroid.game.objects.DropController; @@ -17,12 +18,12 @@ import javax.inject.Inject; @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; private final DropController mDropController; private final MobsController mMobsController; + + private final Timer mGameFluidsTimer; private final GameFluidsThread mGameFluidsThread; private final int mWidth; @@ -45,9 +46,10 @@ public class GameWorld implements Disposable { boolean isNewGame = foreMap == null || backMap == null; if (isNewGame) { - mWidth = DEFAULT_WIDTH; - mHeight = DEFAULT_HEIGHT; - Pair maps = GameWorldGenerator.INSTANCE.generate(mWidth, mHeight, TimeUtils.millis()); + final WorldGeneratorConfig config = WorldGeneratorConfig.Companion.getDefault(); + mWidth = config.getWidth(); + mHeight = config.getHeight(); + Pair maps = new GameWorldGenerator(config).generate(); mForeMap = maps.getFirst(); mBackMap = maps.getSecond(); mMobsController.getPlayer().respawn(this); @@ -58,7 +60,10 @@ public class GameWorld implements Disposable { mHeight = mForeMap[0].length; } - mGameFluidsThread = new GameFluidsThread(this, mMobsController, Thread.currentThread()); + mGameFluidsThread = new GameFluidsThread(this, mMobsController); + + mGameFluidsTimer = new Timer(); + mGameFluidsTimer.scheduleTask(mGameFluidsThread, 0, GameFluidsThread.FLUID_UPDATE_INTERVAL_SEC); } public int getWidth() { @@ -208,15 +213,15 @@ public class GameWorld implements Disposable { 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); + mMobsController.addMob(new FallingSand(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); + mMobsController.addMob(new FallingGravel(x * 16, y * 16)); updateBlock(x, y - 1); } } @@ -245,18 +250,10 @@ public class GameWorld implements Disposable { } mShouldUpdate = false; } - - if (!mGameFluidsThread.isAlive()) { - mGameFluidsThread.start(); - } - } - - public void startFluidsThread() { - mGameFluidsThread.start(); } @Override public void dispose() { - mGameFluidsThread.interrupt(); + mGameFluidsThread.cancel(); } } \ No newline at end of file