DEADSOFTWARE

e3278d1bf4c92eb973439dafe1178e9f2a3e8107
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / GameScreen.java
1 package ru.deadsoftware.cavedroid;
3 import com.badlogic.gdx.Gdx;
4 import com.badlogic.gdx.Screen;
5 import ru.deadsoftware.cavedroid.game.GameItems;
6 import ru.deadsoftware.cavedroid.game.GameProc;
7 import ru.deadsoftware.cavedroid.game.GameSaver;
8 import ru.deadsoftware.cavedroid.menu.MenuProc;
9 import ru.deadsoftware.cavedroid.misc.Assets;
10 import ru.deadsoftware.cavedroid.misc.InputHandlerGame;
11 import ru.deadsoftware.cavedroid.misc.Renderer;
12 import ru.deadsoftware.cavedroid.misc.states.AppState;
13 import ru.deadsoftware.cavedroid.misc.states.GameState;
14 import ru.deadsoftware.cavedroid.misc.states.MenuState;
16 import javax.annotation.Nullable;
18 public class GameScreen implements Screen {
20 public static GameProc GP;
22 public static int FPS;
23 public static boolean SHOW_DEBUG = false;
24 public static boolean SHOW_MAP = false;
26 private Renderer renderer;
27 private MenuProc menuProc;
29 @Nullable private InputHandlerGame inputHandlerGame;
31 public GameScreen() {
32 Assets.load();
33 GameItems.load();
34 menuProc = new MenuProc(CaveGame.TOUCH ? 320 : 480);
35 renderer = menuProc;
36 Gdx.input.setInputProcessor(menuProc);
37 }
39 public static float getWidth() {
40 return Gdx.graphics.getWidth();
41 }
43 public static float getHeight() {
44 return Gdx.graphics.getHeight();
45 }
47 private void game() {
48 GP.update();
49 }
51 private void menu() {
52 }
54 @Override
55 public void show() {
56 }
58 @Override
59 public void render(float delta) {
60 FPS = (int) (1 / delta);
61 switch (CaveGame.APP_STATE) {
62 case GAME:
63 game();
64 break;
66 case MENU:
67 menu();
68 break;
70 case LOAD:
71 renderer = GP.resetRenderer();
72 if (inputHandlerGame == null) {
73 inputHandlerGame = new InputHandlerGame();
74 }
75 Gdx.input.setInputProcessor(inputHandlerGame);
76 CaveGame.APP_STATE = AppState.GAME;
77 CaveGame.GAME_STATE = GameState.PLAY;
78 break;
80 case SAVE:
81 GameSaver.save(GP);
82 CaveGame.APP_STATE = AppState.MENU;
83 CaveGame.MENU_STATE = MenuState.MAIN;
84 GP.dispose();
85 renderer = menuProc;
86 Gdx.input.setInputProcessor(menuProc);
87 break;
88 }
89 renderer.render();
90 }
92 @Override
93 public void resize(int width, int height) {
94 switch (CaveGame.APP_STATE) {
95 case MENU:
96 menuProc = new MenuProc(CaveGame.TOUCH ? 320 : 480);
97 Gdx.input.setInputProcessor(menuProc);
98 renderer = menuProc;
99 break;
100 case GAME:
101 renderer = GP.resetRenderer();
102 break;
106 @Override
107 public void pause() {
111 @Override
112 public void resume() {
116 @Override
117 public void hide() {
121 @Override
122 public void dispose() {