From: fred-boy Date: Fri, 20 Apr 2018 12:26:52 +0000 (+0700) Subject: More convenient controls on desktop X-Git-Tag: alpha0.2~12 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=c6925c7674b71e9b6fe537aaca3aa7330e04e13f;p=cavedroid.git More convenient controls on desktop --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java index e8c31be..89fba69 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java @@ -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: diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 1bedc72..8e12e72 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -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) + 10) 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) diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index e49a405..47b3100 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -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(); - + 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) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 566f072..7eed8a7 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -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(); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index 8b1b699..48c8db8 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -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; x2 && x