DEADSOFTWARE

Fix bugs
authorfred-boy <fred-boy@protonmail.com>
Sat, 21 Apr 2018 12:08:04 +0000 (19:08 +0700)
committerfred-boy <fred-boy@protonmail.com>
Sat, 21 Apr 2018 12:08:04 +0000 (19:08 +0700)
core/src/ru/deadsoftware/cavecraft/GameScreen.java
core/src/ru/deadsoftware/cavecraft/GameState.java
core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
core/src/ru/deadsoftware/cavecraft/game/WorldGen.java

index e1eea188e0d7ab2335260d776f7a573ad819a8b8..2a2c262a6f4fe3cb0a36feb45f33f996080cc091 100644 (file)
@@ -35,6 +35,11 @@ public class GameScreen implements Screen {
 
     @Override
     public void render(float delta) {
+        if (CaveGame.STATE == GameState.RESTART) {
+            gameProc = new GameProc();
+            Gdx.input.setInputProcessor(new InputHandler(gameProc));
+            CaveGame.STATE = GameState.GAME_PLAY;
+        }
         FPS = (int)(1/delta);
         gameProc.update(delta);
         gameProc.renderer.render();
index 9de340d4a858105e2a95efe589003bf1c3a8dc5b..dd6b021ee1894055516d61e78db7a7190e5e3fde 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavecraft;
 
 public enum GameState {
+    RESTART,
     GAME_PLAY,
     GAME_CREATIVE_INV
 }
index 89fba691a916219a10b8c353fdf8122f5dfc90c4..dc19afdb0f42a6bd207fe3fc04956f274e85fb54 100644 (file)
@@ -13,9 +13,9 @@ public class GameInputHandler {
         this.gameProc = gameProc;
     }
 
-    private void wasdPressed(int keyCode) {
+    private void wasdPressed(int keycode) {
         if (gameProc.ctrlMode==0 || !CaveGame.TOUCH) {
-            switch (keyCode) {
+            switch (keycode) {
                 case Input.Keys.A:
                     gameProc.player.moveX.x = -GamePhysics.PL_SPEED;
                     gameProc.player.dir = 0;
@@ -26,7 +26,7 @@ public class GameInputHandler {
                     break;
             }
         } else if (CaveGame.TOUCH){
-            switch (keyCode) {
+            switch (keycode) {
                 case Input.Keys.A:
                     gameProc.cursorX--;
                     break;
@@ -43,11 +43,13 @@ public class GameInputHandler {
         }
     }
 
-    public void  keyDown(int keyCode) {
-        if (keyCode == Input.Keys.W || keyCode == Input.Keys.A ||
-                keyCode == Input.Keys.S || keyCode == Input.Keys.D) {
-            wasdPressed(keyCode);
-        } else switch (keyCode) {
+    public void  keyDown(int keycode) {
+        gameProc.isKeyDown = true;
+        gameProc.keyDownCode = keycode;
+        if (keycode == Input.Keys.W || keycode == Input.Keys.A ||
+                keycode == Input.Keys.S || keycode == Input.Keys.D) {
+            wasdPressed(keycode);
+        } else switch (keycode) {
             case Input.Keys.ALT_LEFT:
                 if (CaveGame.TOUCH) {
                     gameProc.ctrlMode++;
@@ -74,11 +76,14 @@ public class GameInputHandler {
                 if (CaveGame.STATE == GameState.GAME_PLAY) CaveGame.STATE = GameState.GAME_CREATIVE_INV;
                     else CaveGame.STATE = GameState.GAME_PLAY;
                 break;
+
+            case Input.Keys.N:
+                CaveGame.STATE = GameState.RESTART;
         }
     }
 
-    public void keyUp(int keyCode) {
-        switch (keyCode) {
+    public void keyUp(int keycode) {
+        switch (keycode) {
             case Input.Keys.A: case Input.Keys.D:
                 gameProc.player.moveX.x = 0;
                 break;
@@ -98,16 +103,14 @@ public class GameInputHandler {
                 screenX<gameProc.renderer.camera.viewportWidth/2+Assets.creativeInv.getRegionWidth()/2 &&
                 screenY>gameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 &&
                 screenY<gameProc.renderer.camera.viewportHeight/2+Assets.creativeInv.getRegionHeight()/2) {
-            try {
-                int ix = (int) (screenX - (gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
-                int iy = (int) (screenY - (gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
-                int item = ix + iy * 8;
+            int ix = (int) (screenX - (gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
+            int iy = (int) (screenY - (gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
+            int item = ix + iy * 8;
+            if (item >= 0 && item < Items.BLOCKS.size) {
                 for (int i = 8; i > 0; i--) {
                     gameProc.player.inventory[i] = gameProc.player.inventory[i - 1];
                 }
-                if (item >= 0 && item < Items.BLOCKS.size) gameProc.player.inventory[0] = item;
-            } catch (Exception e) {
-                Gdx.app.error("GameInputHandler", e.toString());
+                gameProc.player.inventory[0] = item;
             }
         } else if (CaveGame.STATE == GameState.GAME_CREATIVE_INV) {
             CaveGame.STATE = GameState.GAME_PLAY;
@@ -121,6 +124,10 @@ public class GameInputHandler {
     }
 
     public void touchUp(int screenX, int screenY, int button) {
+        if (gameProc.isKeyDown) {
+            keyUp(gameProc.keyDownCode);
+            gameProc.isKeyDown = false;
+        }
         if (gameProc.isTouchDown) {
             if (button == Input.Buttons.RIGHT){
                 gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY,
index 7ded79faf697495940d013d2092fb44857ad2dde..6a2bf046b8c52061885a680e7454d42f1cbd6418 100644 (file)
@@ -26,8 +26,8 @@ public class GameProc {
     public int invSlot;
     public int ctrlMode;
 
-    public boolean isTouchDown = false;
-    public int touchDownX, touchDownY;
+    public boolean isTouchDown, isKeyDown;
+    public int touchDownX, touchDownY, keyDownCode;
     public int touchDownButton;
     public long touchDownTime;
 
index 5a82102a3fafaaa00fcd0dd6a30ec2522e913f1e..b8b53249be9296363957889c991ae7bf377f5a80 100644 (file)
@@ -231,7 +231,7 @@ public class GameRenderer {
         drawString("CaveCraft "+CaveGame.VERSION, 0, 0);
         drawString("FPS: "+GameScreen.FPS, 0, 20);
         drawString("X: "+(int)(gameProc.player.position.x/16), 0, 40);
-        drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60);
+        drawString("Y: "+(gameProc.world.getHeight()-(int)(gameProc.player.position.y/16)), 0, 60);
         drawString("Seed: "+WorldGen.getSeed(), 0, 80);
         drawString("Mobs: "+gameProc.mobs.size, 0, 100);
         fontBatch.end();
index c4655bf157c732368ec685c085af2be42ba9f819..e6b0b006b36460b590c02199df2fb14144c5a7b5 100644 (file)
@@ -3,6 +3,8 @@ package ru.deadsoftware.cavecraft.game;
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.math.Vector2;
 import com.badlogic.gdx.utils.ArrayMap;
+import ru.deadsoftware.cavecraft.CaveGame;
+import ru.deadsoftware.cavecraft.GameState;
 import ru.deadsoftware.cavecraft.Items;
 
 public class GameWorld {
@@ -84,13 +86,22 @@ public class GameWorld {
         while (!found) {
             for (int i = 0; i < getHeight(); i++) {
                 if (getForeMap((int)x, i)>0 &&
-                        Items.BLOCKS.getValueAt(getForeMap((int)x, i)).collision) {
-                    y = i-3;
+                        Items.BLOCKS.getValueAt(getForeMap((int)x, i)).collision &&
+                        getForeMap((int)x, i-1)==0 && getForeMap((int)x, i-1)==0) {
+                    y = i-2;
                     found = true;
                     break;
                 }
             }
-            if (!found) x--;
+            if (!found) {
+                x--;
+                if (x<0) x=getWidth()-1;
+                if ((int)x == getWidth()/2+1) {
+                    x--;
+                    y=0;
+                    break;
+                }
+            }
         }
         x = x*16 + 4;
         y *= 16;
index 32cb8f94a0f28db677a4045a177f3aec0cfbaf4a..954bdffd799366b314056582e8043d4949d9de3a 100644 (file)
@@ -54,16 +54,14 @@ public class WorldGen {
         genWorld(width, height, TimeUtils.millis());
     }
 
-    static void genWorld(int width, int height, long s) {
+    static void genWorld(int width, int height, long worldseed) {
         int dirtH;
-        seed = s;
+        seed = worldseed;
         rand = new RandomXS128(seed);
         foreMap = new int[width][height];
         backMap = new int[width][height];
         hMap = genLandscape(width, height/4, height/8, height/2);
         for (int x=0; x<width; x++) {
-            for (int y=0; y<height; y++) {
-            }
             dirtH = 4+rand.nextInt(2);
             for (int y = height- hMap[x]; y<height; y++) {
                 if (y==height- hMap[x]) {
@@ -84,10 +82,13 @@ public class WorldGen {
                 if (foreMap[x][y]==0){
                     foreMap[x][y] = 8;
                     backMap[x][y] = 8;
+                    if (y==height-hMap[x]-1) {
+                        foreMap[x][y+1] = 3;
+                    }
                 }
             }
             if (x>2 && x<width-2 && rand.nextInt(100)<5){
-                genOak(x,height-hMap[x]-1);
+                if (foreMap[x][height-hMap[x]]-1==0) genOak(x,height-hMap[x]-1);
             }
         }
     }