DEADSOFTWARE

More convenient controls on desktop
authorfred-boy <fred-boy@protonmail.com>
Fri, 20 Apr 2018 12:26:52 +0000 (19:26 +0700)
committerfred-boy <fred-boy@protonmail.com>
Fri, 20 Apr 2018 12:26:52 +0000 (19:26 +0700)
core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/WorldGen.java

index e8c31be65e7c4eb2f2409a1952cf7aa8a87d0d63..89fba691a916219a10b8c353fdf8122f5dfc90c4 100644 (file)
@@ -14,7 +14,7 @@ public class GameInputHandler {
     }
 
     private void wasdPressed(int keyCode) {
-        if (gameProc.ctrlMode==0) {
+        if (gameProc.ctrlMode==0 || !CaveGame.TOUCH) {
             switch (keyCode) {
                 case Input.Keys.A:
                     gameProc.player.moveX.x = -GamePhysics.PL_SPEED;
@@ -25,7 +25,7 @@ public class GameInputHandler {
                     gameProc.player.dir = 1;
                     break;
             }
-        } else {
+        } else if (CaveGame.TOUCH){
             switch (keyCode) {
                 case Input.Keys.A:
                     gameProc.cursorX--;
@@ -40,10 +40,6 @@ public class GameInputHandler {
                     gameProc.cursorY++;
                     break;
             }
-            if (gameProc.cursorX<(gameProc.player.position.x+gameProc.player.texWidth/2)/16)
-                gameProc.player.dir=0;
-            if (gameProc.cursorX>(gameProc.player.position.x+gameProc.player.texWidth/2)/16)
-                gameProc.player.dir=1;
         }
     }
 
@@ -53,8 +49,10 @@ public class GameInputHandler {
             wasdPressed(keyCode);
         } else switch (keyCode) {
             case Input.Keys.ALT_LEFT:
-                gameProc.ctrlMode++;
-                if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0;
+                if (CaveGame.TOUCH) {
+                    gameProc.ctrlMode++;
+                    if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0;
+                }
                 break;
 
             case Input.Keys.SPACE:
index 1bedc729471a0a022c701bca28c56ebfbb674d04..8e12e7292a3dca7bd37a790a97f27aba9e264576 100644 (file)
@@ -16,7 +16,7 @@ public class GamePhysics {
 
     public GamePhysics(GameProc gameProc) {
         this.gameProc = gameProc;
-        gravity = new Vector2(0,1);
+        gravity = new Vector2(0,.9f);
     }
 
     private boolean checkJump(Rectangle rect, int dir) {
@@ -27,12 +27,14 @@ public class GamePhysics {
                     bl = gameProc.world.getForeMap(
                         (int)((rect.x+(rect.width/2))/16) - 1,
                         (int)(rect.y/16)+1);
+                if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16))>0) bl=0;
                 break;
             case 1:
                 if ((int)((rect.x+(rect.width/2))/16) + 1<gameProc.world.getWidth())
                     bl = gameProc.world.getForeMap(
                         (int)((rect.x+(rect.width/2))/16) + 1,
                         (int)(rect.y/16)+1);
+                if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16))>0) bl=0;
                 break;
             default:
                 bl=0;
@@ -66,17 +68,19 @@ public class GamePhysics {
     private void playerPhy(Player pl) {
         pl.position.add(pl.moveY);
         if (checkColl(pl.getRect())) {
-            pl.flyMode = false;
-            pl.canJump = true;
             int d = -1;
             if (pl.moveY.y<0) d=1; else if (pl.moveY.y>0) d=-1;
+            if (d==-1) {
+                pl.flyMode = false;
+                pl.canJump = true;
+            }
             pl.position.y = MathUtils.round(pl.position.y);
             while (checkColl(pl.getRect())) pl.position.y+=d;
             pl.moveY.setZero();
         } else {
             pl.canJump = false;
         }
-        if (!pl.flyMode) pl.moveY.add(gravity);
+        if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity);
         pl.position.add(pl.moveX);
         if (pl.position.x<0 ||
                 pl.position.x+pl.texWidth>=gameProc.world.getWidth()*16)
index e49a40588fd47641eadeea136b65354a9929d5e9..47b3100aa9164e3f5d4cd22060d46deebc0331b1 100644 (file)
@@ -1,13 +1,11 @@
 package ru.deadsoftware.cavecraft.game;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.math.RandomXS128;
 import com.badlogic.gdx.utils.Array;
 import com.badlogic.gdx.utils.TimeUtils;
-import ru.deadsoftware.cavecraft.Assets;
-import ru.deadsoftware.cavecraft.CaveGame;
-import ru.deadsoftware.cavecraft.GameState;
-import ru.deadsoftware.cavecraft.Items;
+import ru.deadsoftware.cavecraft.*;
 import ru.deadsoftware.cavecraft.game.mobs.Human;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
 import ru.deadsoftware.cavecraft.game.objects.Player;
@@ -39,7 +37,7 @@ public class GameProc {
         physics = new GamePhysics(this);
         player = new Player(world.getSpawnPoint());
         mobs = new Array<Mob>();
-
+        if (!CaveGame.TOUCH) ctrlMode = 1;
     }
 
     public void resetRenderer() {
@@ -52,24 +50,31 @@ public class GameProc {
     }
 
     private void moveCursor() {
-        if (player.canJump) {
-            cursorX = (int) (player.position.x + player.texWidth / 2) / 16;
-            if (player.dir == 0) cursorX--;
-            else cursorX++;
-            cursorY = (int) (player.position.y + player.texWidth) / 16;
-            if (!isAutoselectable(cursorX, cursorY)) {
-                cursorY++;
-            }
-            if (!isAutoselectable(cursorX, cursorY)) {
-                cursorY++;
-            }
-            if (!isAutoselectable(cursorX, cursorY)) {
-                if (player.dir == 0) cursorX++;
-                else cursorX--;
+        if (ctrlMode==0) {
+            if (player.canJump) {
+                cursorX = (int) (player.position.x + player.texWidth / 2) / 16;
+                if (player.dir == 0) cursorX--;
+                else cursorX++;
+                cursorY = (int) (player.position.y + player.texWidth) / 16;
+                if (!isAutoselectable(cursorX, cursorY)) {
+                    cursorY++;
+                }
+                if (!isAutoselectable(cursorX, cursorY)) {
+                    cursorY++;
+                }
+                if (!isAutoselectable(cursorX, cursorY)) {
+                    if (player.dir == 0) cursorX++;
+                    else cursorX--;
+                }
+            } else {
+                cursorX = (int) (player.position.x + player.texWidth / 2) / 16;
+                cursorY = (int) (player.position.y + player.height+8)/16;
             }
-        } else {
-            cursorX = (int) (player.position.x + player.texWidth / 2) / 16;
-            cursorY = (int) (player.position.y + player.height+8)/16;
+        } else if (!CaveGame.TOUCH){
+            cursorX = (int)(Gdx.input.getX()*
+                    (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)/16;
+            cursorY = (int)(Gdx.input.getY()*
+                    (renderer.camera.viewportHeight/GameScreen.getHeight())+renderer.camera.position.y)/16;
         }
     }
 
@@ -78,13 +83,17 @@ public class GameProc {
         if (cursorX >= world.getWidth()) cursorX = world.getWidth()-1;
         if (cursorY < 0) cursorY = 0;
         if (cursorY >= world.getHeight()) cursorY = world.getHeight()-1;
+        if (cursorX<(player.position.x+player.texWidth/2)/16)
+            player.dir=0;
+        if (cursorX>(player.position.x+player.texWidth/2)/16)
+            player.dir=1;
     }
 
     public void update(float delta) {
         RUN_TIME += delta;
 
         physics.update(delta);
-        if (ctrlMode==0) moveCursor();
+        moveCursor();
         checkCursorBounds();
 
         if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) {
index 566f072739d4b32c05c9afd278711110fa31ae8f..7eed8a7d85884890c8cbc87eb8b11ebd90646707 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.GL20;
 import com.badlogic.gdx.graphics.OrthographicCamera;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@@ -219,6 +220,12 @@ public class GameRenderer {
         }
         spriteBatch.end();
 
+        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
+        shapeRenderer.setColor(Color.ORANGE);
+        shapeRenderer.line(0-camera.position.x, 128*16-camera.position.y,
+                gameProc.world.getWidth()*16-camera.position.x, 128*16-camera.position.y);
+        shapeRenderer.end();
+
         if (CaveGame.TOUCH) {
             spriteBatch.begin();
             drawTouchGui();
@@ -231,6 +238,7 @@ public class GameRenderer {
         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("Seed: "+WorldGen.getSeed(), 0, 80);
         fontBatch.end();
     }
 
index 8b1b69960a1ac95589a1fb8abaee393302d9f510..48c8db8d1d84542b60627b0e41db0aadf456eb15 100644 (file)
@@ -1,5 +1,6 @@
 package ru.deadsoftware.cavecraft.game;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.math.RandomXS128;
 import com.badlogic.gdx.utils.ArrayMap;
 import com.badlogic.gdx.utils.TimeUtils;
@@ -59,7 +60,7 @@ public class WorldGen {
         rand = new RandomXS128(seed);
         foreMap = new int[width][height];
         backMap = new int[width][height];
-        hMap = genLandscape(width, height/2, height/4, height/4*3);
+        hMap = genLandscape(width, height/4, height/8, height/2);
         for (int x=0; x<width; x++) {
             for (int y=0; y<height; y++) {
             }
@@ -79,10 +80,10 @@ public class WorldGen {
                     backMap[x][y] = 7;
                 }
             }
-            for (int y = height/4*3; y<height- hMap[x]; y++) {
-                if (foreMap[x][y]==0){
-                    foreMap[x][y] = 8;
-                    backMap[x][y] = 8;
+            for (int y = height-64; y<height-1; y++) {
+                if (foreMap[x][height-y]==0){
+                    foreMap[x][height-y] = 8;
+                    backMap[x][height-y] = 8;
                 }
             }
             if (x>2 && x<width-2 && rand.nextInt(100)<5){