DEADSOFTWARE

Start making survival mode
authorfred-boy <fred-boy@protonmail.com>
Sun, 30 Sep 2018 16:51:44 +0000 (23:51 +0700)
committerfred-boy <fred-boy@protonmail.com>
Sun, 30 Sep 2018 16:51:44 +0000 (23:51 +0700)
core/src/ru/deadsoftware/cavecraft/GameScreen.java
core/src/ru/deadsoftware/cavecraft/game/GameInput.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/objects/Player.java
core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java
core/src/ru/deadsoftware/cavecraft/misc/AppState.java
core/src/ru/deadsoftware/cavecraft/misc/InputHandlerMenu.java

index 545ee3f74f0f500f13481286b2f6a5f284be8006..c77c9e08032e6efe725cb6be42d07f248873464d 100644 (file)
@@ -12,6 +12,7 @@ public class GameScreen implements Screen {
 
     public static int FPS;
     public static boolean SHOW_DEBUG = false;
+    public static int NEW_GAME_MODE = 0;
 
     private GameProc gp;
     private Renderer renderer;
@@ -58,7 +59,7 @@ public class GameScreen implements Screen {
                 break;
 
             case NEW_GAME:
-                gp = new GameProc();
+                gp = new GameProc(NEW_GAME_MODE);
                 renderer = gp.renderer;
                 Gdx.input.setInputProcessor(new InputHandlerGame(gp));
                 CaveGame.STATE = AppState.GAME_PLAY;
@@ -89,6 +90,7 @@ public class GameScreen implements Screen {
     public void resize(int width, int height) {
         switch (CaveGame.STATE) {
             case MENU_MAIN:
+
                 menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
                 renderer = menuRenderer;
                 break;
index 48388ac465995e8a9b618234a7729b08110f1e57..687c6a9e5e6d919f96ab41b7dc0ee5ffbfd1bd06 100644 (file)
@@ -73,10 +73,10 @@ public class GameInput {
                     gp.swim = true;
                 } else if (gp.player.canJump) {
                     gp.player.move.add(0, -7);
-                } else if (!gp.player.flyMode) {
+                } else if (!gp.player.flyMode && gp.player.gameMode == 1) {
                     gp.player.flyMode = true;
                     gp.player.move.y = 0;
-                } else {
+                } else if (gp.player.flyMode) {
                     gp.player.move.y = -GamePhysics.PL_SPEED;
                 }
                 break;
@@ -86,7 +86,14 @@ public class GameInput {
                 break;
 
             case Input.Keys.E:
-                if (CaveGame.STATE == AppState.GAME_PLAY) CaveGame.STATE = AppState.GAME_CREATIVE_INV;
+                if (CaveGame.STATE == AppState.GAME_PLAY) switch (gp.player.gameMode) {
+                    case 0:
+                        //TODO survival inv
+                        break;
+                    case 1:
+                        CaveGame.STATE = AppState.GAME_CREATIVE_INV;
+                        break;
+                }
                 else CaveGame.STATE = AppState.GAME_PLAY;
                 break;
 
index 14b7015c4d0ba5eb4878cbc937be35044e4685b7..da028621decbfd3cd09fde9ec7549744993944f6 100644 (file)
@@ -44,10 +44,10 @@ public class GameProc implements Serializable {
     public int touchDownBtn;
     public long touchDownTime;
 
-    public GameProc() {
+    public GameProc(int gameMode) {
         world = new GameWorld();
         world.generate(1024, 256);
-        player = new Player(world.getSpawnPoint());
+        player = new Player(world.getSpawnPoint(), gameMode);
         drops = new ArrayList<Drop>();
         mobs = new ArrayList<Mob>();
         for (int i = 0; i < 16; i++) {
@@ -411,17 +411,23 @@ public class GameProc implements Serializable {
         if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) {
             if ((world.getForeMap(curX, curY) > 0 && GameItems.getBlock(world.getForeMap(curX, curY)).getHp() >= 0) ||
                     world.getBackMap(curX, curY) > 0 && GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0) {
-                blockDmg++;
-                if (world.getForeMap(curX, curY) > 0) {
-                    if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
-                        world.destroyForeMap(curX, curY, this);
-                        blockDmg = 0;
-                    }
-                } else if (world.getBackMap(curX, curY) > 0) {
-                    if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
-                        world.destroyBackMap(curX, curY, this);
-                        blockDmg = 0;
+                if (player.gameMode == 0) {
+                    blockDmg++;
+                    if (world.getForeMap(curX, curY) > 0) {
+                        if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
+                            world.destroyForeMap(curX, curY, this);
+                            blockDmg = 0;
+                        }
+                    } else if (world.getBackMap(curX, curY) > 0) {
+                        if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
+                            world.destroyBackMap(curX, curY, this);
+                            blockDmg = 0;
+                        }
                     }
+                } else {
+                    if (world.getForeMap(curX, curY) > 0) world.setForeMap(curX, curY, 0);
+                    else if (world.getBackMap(curX, curY) > 0) world.setBackMap(curX, curY, 0);
+                    isTouchDown = false;
                 }
             }
         }
index 162c77b885eb4747dd893530f71fceb8b41e059b..5560bf6853b799b14af11656dcb0e57407507ef6 100644 (file)
@@ -295,6 +295,7 @@ public class GameRenderer extends Renderer {
             drawString("Mobs: " + gp.mobs.size(), 0, 30);
             drawString("Drops: " + gp.drops.size(), 0, 40);
             drawString("Block: " + GameItems.getBlockKey(gp.world.getForeMap(gp.curX, gp.curY)), 0, 50);
+            drawString("Game mode: " + gp.player.gameMode, 0, 60);
         }
         spriter.end();
     }
index 74f7249c751030d1778e03b55b2c11acec8d1337..4c7d962ca37c86d2dae698016bd45b83aa350bdc 100644 (file)
@@ -15,8 +15,10 @@ public class Player implements Serializable {
     public boolean canJump;
     public int[] inv;
     public boolean flyMode = false;
+    public int gameMode;
 
-    public Player(Vector2 spawnPoint) {
+    public Player(Vector2 spawnPoint, int gameMode) {
+        this.gameMode = gameMode;
         pos = spawnPoint.cpy();
         move = new Vector2(0, 0);
         width = 4;
index aab04d9b76dde0f683c87a89e202859a523c92ba..8aaab64c9d97c8a32c2fcf487890495d03b3b0ff 100644 (file)
@@ -14,22 +14,38 @@ import ru.deadsoftware.cavecraft.misc.Renderer;
 public class MenuRenderer extends Renderer {
 
     public Array<Button> menuMainBtns;
+    public Array<Button> menuNGBtns;
 
     public MenuRenderer(int width) {
         super(width, width * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
+        //main menu
         menuMainBtns = new Array<Button>();
         menuMainBtns.add(new Button("New game", getWidth() / 2 - 100, getHeight() / 4));
         menuMainBtns.add(new Button("Load game", getWidth() / 2 - 100, getHeight() / 4 + 30, GameSaver.exists() ? 1 : 0));
         menuMainBtns.add(new Button("Quit", getWidth() / 2 - 100, getHeight() / 4 + 60));
+        //new game menu
+        menuNGBtns = new Array<Button>();
+        menuNGBtns.add(new Button("Survival", getWidth() / 2 - 100, getHeight() / 4, 1));
+        menuNGBtns.add(new Button("Creative", getWidth() / 2 - 100, getHeight() / 4 + 30));
+        menuNGBtns.add(new Button("Back", getWidth() / 2 - 100, getHeight() / 4 + 60));
+
     }
 
     public void buttonClicked(Button button) {
         if (button.getLabel().toLowerCase().equals("new game")) {
-            CaveGame.STATE = AppState.GOTO_NEW_GAME;
+            CaveGame.STATE = AppState.MENU_NEW_GAME;
         } else if (button.getLabel().toLowerCase().equals("load game")) {
             CaveGame.STATE = AppState.GOTO_LOAD_GAME;
         } else if (button.getLabel().toLowerCase().equals("quit")) {
             Gdx.app.exit();
+        } else if (button.getLabel().toLowerCase().equals("survival")) {
+            GameScreen.NEW_GAME_MODE = 0;
+            CaveGame.STATE = AppState.GOTO_NEW_GAME;
+        } else if (button.getLabel().toLowerCase().equals("creative")) {
+            GameScreen.NEW_GAME_MODE = 1;
+            CaveGame.STATE = AppState.GOTO_NEW_GAME;
+        } else if (button.getLabel().toLowerCase().equals("back")) {
+            CaveGame.STATE = AppState.MENU_MAIN;
         }
     }
 
@@ -53,6 +69,18 @@ public class MenuRenderer extends Renderer {
         }
     }
 
+    private void drawMenuNewGame() {
+        for (Button button : menuNGBtns) {
+            if (button.getType() > 0) {
+                if (button.getRect().contains(Gdx.input.getX() * getWidth() / GameScreen.getWidth(),
+                        Gdx.input.getY() * getHeight() / GameScreen.getHeight()))
+                    button.setType(2);
+                else button.setType(1);
+            }
+            drawButton(button);
+        }
+    }
+
     public void drawLabel(String str) {
         drawString(str);
     }
@@ -71,6 +99,9 @@ public class MenuRenderer extends Renderer {
             case MENU_MAIN:
                 drawMenuMain();
                 break;
+            case MENU_NEW_GAME:
+                drawMenuNewGame();
+                break;
             case GOTO_NEW_GAME:
             case GOTO_LOAD_GAME:
                 drawLabel("Generating World...");
index 7a86332c074babdf0f7add72f8673b8de7160637..f80e7f6a8a99fd1426b5ce12d534b86c2344e910 100644 (file)
@@ -10,6 +10,7 @@ public enum AppState {
     SAVE_GAME,
 
     MENU_MAIN,
+    MENU_NEW_GAME,
 
     GAME_PLAY,
     GAME_CREATIVE_INV
index bb6044412570fc3d7b86eb3ce0d769b271df30ef..5b4d9ba333fbd7a028604bae57bb8568a47eabdd 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavecraft.misc;
 
 import com.badlogic.gdx.InputProcessor;
+import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.GameScreen;
 import ru.deadsoftware.cavecraft.menu.MenuRenderer;
 import ru.deadsoftware.cavecraft.menu.objects.Button;
@@ -37,8 +38,19 @@ public class InputHandlerMenu implements InputProcessor {
     public boolean touchUp(int screenX, int screenY, int pointer, int mb) {
         screenX *= menuRenderer.getWidth() / GameScreen.getWidth();
         screenY *= menuRenderer.getHeight() / GameScreen.getHeight();
-        for (Button button : menuRenderer.menuMainBtns) {
-            if (button.getRect().contains(screenX, screenY) && button.getType() > 0) menuRenderer.buttonClicked(button);
+        switch (CaveGame.STATE) {
+            case MENU_MAIN:
+                for (Button button : menuRenderer.menuMainBtns) {
+                    if (button.getRect().contains(screenX, screenY) && button.getType() > 0)
+                        menuRenderer.buttonClicked(button);
+                }
+                break;
+            case MENU_NEW_GAME:
+                for (Button button : menuRenderer.menuNGBtns) {
+                    if (button.getRect().contains(screenX, screenY) && button.getType() > 0)
+                        menuRenderer.buttonClicked(button);
+                }
+                break;
         }
         return false;
     }