DEADSOFTWARE

Fix bugs
authorfred-boy <fred-boy@protonmail.com>
Tue, 24 Apr 2018 15:43:12 +0000 (22:43 +0700)
committerfred-boy <fred-boy@protonmail.com>
Tue, 24 Apr 2018 15:43:12 +0000 (22:43 +0700)
core/src/ru/deadsoftware/cavecraft/AppState.java
core/src/ru/deadsoftware/cavecraft/GameScreen.java
core/src/ru/deadsoftware/cavecraft/game/GameInput.java
core/src/ru/deadsoftware/cavecraft/game/GameSaver.java
core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java

index 233bbb6da85522744ac53226aad5d71dfaebf18a..be651384954e2e252dc9a0f6eabda09108c5f6a5 100644 (file)
@@ -5,6 +5,10 @@ public enum AppState {
     GOTO_LOAD_GAME,
     GOTO_MENU,
 
+    NEW_GAME,
+    LOAD_GAME,
+    SAVE_GAME,
+
     MENU_MAIN,
 
     GAME_PLAY,
index 682319d184b3e7cbf1a562f8350ff4dead48e7bd..6d4f4d985cb5acc8d735a0283dd1d9edffcb5805 100644 (file)
@@ -53,24 +53,28 @@ public class GameScreen implements Screen {
                 menu();
                 break;
 
-            case GOTO_NEW_GAME:
+            case NEW_GAME:
                 gameProc = new GameProc();
                 renderer = gameProc.renderer;
                 Gdx.input.setInputProcessor(new InputHandlerGame(gameProc));
                 CaveGame.STATE = AppState.GAME_PLAY;
                 break;
 
-            case GOTO_LOAD_GAME:_GAME:
+            case LOAD_GAME:
                 gameProc = GameSaver.load();
                 renderer = gameProc.renderer;
                 Gdx.input.setInputProcessor(new InputHandlerGame(gameProc));
                 CaveGame.STATE = AppState.GAME_PLAY;
                 break;
 
+            case SAVE_GAME:
+                GameSaver.save(gameProc);
+                CaveGame.STATE = AppState.MENU_MAIN;
+                break;
+
             case GOTO_MENU:
                 renderer = menuRenderer;
                 Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
-                CaveGame.STATE = AppState.MENU_MAIN;
                 break;
         }
         renderer.render();
index cddeb4d27158d95eb635e896ecc09ff1db0d14db..2ff2fa3d933e0d2093fd0bfcb24d215c351279d6 100644 (file)
@@ -79,12 +79,7 @@ public class GameInput {
                     else CaveGame.STATE = AppState.GAME_PLAY;
                 break;
 
-            case Input.Keys.N:
-                CaveGame.STATE = AppState.GOTO_NEW_GAME;
-                break;
-
             case Input.Keys.ESCAPE: case Input.Keys.BACK:
-                GameSaver.save(gameProc);
                 CaveGame.STATE = AppState.GOTO_MENU;
                 break;
         }
index 070b5c24009524548980c60dee82cb0a86328930..fccc7bc8a889378d7e1ef89fb9a6cfef53b7d68a 100644 (file)
@@ -27,7 +27,7 @@ public class GameSaver {
         byte[] bytes = ByteBuffer.allocate(4).putInt(i).array();
         file.writeBytes(bytes, append);
     }
-    
+
     private static void saveMap(FileHandle file, int[][] map) {
         int rl,bl;
         int width = map.length;
@@ -43,7 +43,6 @@ public class GameSaver {
                     if (x==map.length-1) rl++;
                     writeInt(file, rl, true);
                     writeInt(file, bl, true);
-                    System.out.printf("%d. Run:%d; Block:%s\n",y, rl, Items.BLOCKS.getKeyAt(bl));
                     rl=0;
                     bl=map[x][y];
                 }
@@ -67,7 +66,6 @@ public class GameSaver {
                 for (int x=0; x<width; x+=rl) {
                     rl = bytesInt(data);
                     bl = bytesInt(data);
-                    System.out.printf("%d. Run:%d; Block:%s\n",y, rl, Items.BLOCKS.getKeyAt(bl));
                     for (int i=x; i<x+rl; i++) map[i][y] = bl;
                 }
             }
index 4f3e3b16e3fd605e61fe0f1e9f274e3b008b61c2..faf1eb3f15ec3d36b11a45a4ff7ed1ec897b4f6c 100644 (file)
@@ -20,14 +20,8 @@ public class MenuRenderer extends Renderer {
 
     public void buttonClicked(Button button) {
         if (button.getLabel().toLowerCase().equals("new game")) {
-            spriteBatch.begin();
-            drawGenWorld();
-            spriteBatch.end();
             CaveGame.STATE = AppState.GOTO_NEW_GAME;
         } else if (button.getLabel().toLowerCase().equals("load game")) {
-            spriteBatch.begin();
-            drawGenWorld();
-            spriteBatch.end();
             CaveGame.STATE = AppState.GOTO_LOAD_GAME;
         } else if (button.getLabel().toLowerCase().equals("quit")) {
             Gdx.app.exit();
@@ -41,7 +35,7 @@ public class MenuRenderer extends Renderer {
                 (button.getX()+button.getWidth()/2)-Assets.getStringWidth(button.getLabel())/2,
                 (button.getY()+button.getHeight()/2)-Assets.getStringHeight(button.getLabel())/2);
     }
-    
+
     private void drawMenuMain() {
         for (Button button : menuMainButtons) {
             if (button.getType()>0) {
@@ -54,15 +48,8 @@ public class MenuRenderer extends Renderer {
         }
     }
 
-    private void drawGenWorld() {
-        for (int x=0; x<=getWidth()/16; x++)
-            for (int y=0; y<=getHeight()/16; y++) {
-                spriteBatch.draw(Items.BLOCKS.get("dirt").getTexture(), x * 16, y * 16);
-                spriteBatch.draw(Assets.shade,x*16,y*16);
-            }
-        spriteBatch.draw(Assets.gameLogo, getWidth()/2-Assets.gameLogo.getWidth()/2, 0);
-        drawString("Generating World...");
-        spriteBatch.flush();
+    public void drawLabel(String str) {
+        drawString(str);
     }
 
     @Override
@@ -77,10 +64,19 @@ public class MenuRenderer extends Renderer {
 
         switch (CaveGame.STATE) {
             case MENU_MAIN: drawMenuMain(); break;
+            case GOTO_NEW_GAME: case GOTO_LOAD_GAME: drawLabel("Generating World..."); break;
+            case GOTO_MENU: drawLabel("Saving Game..."); break;
         }
 
         drawString("CaveCraft "+CaveGame.VERSION,0,
                 getHeight()-Assets.getStringHeight("CaveCraft "+CaveGame.VERSION)*1.5f);
         spriteBatch.end();
+
+        switch (CaveGame.STATE) {
+            case GOTO_NEW_GAME: CaveGame.STATE = AppState.NEW_GAME; break;
+            case GOTO_LOAD_GAME: CaveGame.STATE = AppState.LOAD_GAME; break;
+            case GOTO_MENU: CaveGame.STATE = AppState.SAVE_GAME; break;
+        }
+
     }
 }