DEADSOFTWARE

Fix saves
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameProc.java
1 package ru.deadsoftware.cavedroid.game;
3 import com.badlogic.gdx.utils.Disposable;
4 import com.badlogic.gdx.utils.Timer;
5 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
6 import ru.deadsoftware.cavedroid.game.world.GameWorldBlocksLogicControllerTask;
7 import ru.deadsoftware.cavedroid.game.world.GameWorldFluidsLogicControllerTask;
8 import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
10 import javax.inject.Inject;
12 @GameScope
13 public class GameProc implements Disposable {
15 private final GamePhysics mGamePhysics;
16 private final GameInput mGameInput;
17 private final GameRenderer mGameRenderer;
18 private final MobsController mMobsController;
19 private final GameWorldFluidsLogicControllerTask mGameWorldFluidsLogicControllerTask;
20 private final GameWorldBlocksLogicControllerTask mGameWorldBlocksLogicControllerTask;
21 private final GameItemsHolder mGameItemsHolder;
23 private final Timer mWorldLogicTimer = new Timer();
25 @Inject
26 public GameProc(GamePhysics gamePhysics,
27 GameInput gameInput,
28 GameRenderer gameRenderer,
29 MobsController mobsController,
30 GameWorldFluidsLogicControllerTask gameWorldFluidsLogicControllerTask,
31 GameWorldBlocksLogicControllerTask gameWorldBlocksLogicControllerTask,
32 GameItemsHolder gameItemsHolder
33 ) {
34 mGamePhysics = gamePhysics;
35 mGameInput = gameInput;
36 mGameRenderer = gameRenderer;
37 mMobsController = mobsController;
38 mGameWorldFluidsLogicControllerTask = gameWorldFluidsLogicControllerTask;
39 mGameWorldBlocksLogicControllerTask = gameWorldBlocksLogicControllerTask;
40 mGameItemsHolder = gameItemsHolder;
42 mGameItemsHolder.initialize();
44 mWorldLogicTimer.scheduleTask(gameWorldFluidsLogicControllerTask, 0,
45 GameWorldFluidsLogicControllerTask.FLUID_UPDATE_INTERVAL_SEC);
46 mWorldLogicTimer.scheduleTask(gameWorldBlocksLogicControllerTask, 0,
47 GameWorldBlocksLogicControllerTask.WORLD_BLOCKS_LOGIC_UPDATE_INTERVAL_SEC);
48 }
50 public void setPlayerGameMode(int gameMode) {
51 mMobsController.getPlayer().gameMode = gameMode;
52 }
54 public void update(float delta) {
55 mGamePhysics.update(delta);
56 mGameInput.update();
57 mGameRenderer.render(delta);
58 }
60 @Override
61 public void dispose() {
62 mWorldLogicTimer.stop();
63 mGameWorldFluidsLogicControllerTask.cancel();
64 mGameWorldBlocksLogicControllerTask.cancel();
65 }
66 }