From 103459785743a8485af69863d65ad1b1a2410ab0 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Thu, 19 Apr 2018 18:33:32 +0700 Subject: [PATCH] Gameplay enhancements --- android/assets/gui.png | Bin 5061 -> 5091 bytes .../src/ru/deadsoftware/cavecraft/Assets.java | 9 +- .../ru/deadsoftware/cavecraft/CaveGame.java | 3 + .../ru/deadsoftware/cavecraft/GameState.java | 6 ++ .../cavecraft/game/GameInputHandler.java | 60 ++++++------- .../deadsoftware/cavecraft/game/GameProc.java | 43 +++++++++- .../cavecraft/game/GameRenderer.java | 80 ++++++++++-------- .../cavecraft/game/GameWorld.java | 11 ++- .../deadsoftware/cavecraft/game/WorldGen.java | 8 +- 9 files changed, 139 insertions(+), 81 deletions(-) create mode 100644 core/src/ru/deadsoftware/cavecraft/GameState.java diff --git a/android/assets/gui.png b/android/assets/gui.png index ef76dc04938b993da01fec7e5c2771c7cf56e607..6542140a28333c67aa397c6bfea79ba760122510 100644 GIT binary patch literal 5091 zcmV<96CCV`P)pOv#ObM?oaR>!WjDvk|g<&2~Q?Sl7O8gNdk6~Bnj9_k|ba!Ns@q_Bmp}~k_7A| zNfNM=BuT(dk|Y5;Nsl((Ga9u28{Yb`o0+{Gk*ERAyAB;=m zz468yxOeZ~z&7!GPEJk+pN+4fG0)R4)`hN#Wln!uN9P=_UAu>y~c8$ ze&3}BtvlVr7z3pglv3F3cDQ--CZ0Tb60k8|hdj>#AYd}K*;v1O_wMx(n{NK@yYGJV zZ4=8fpltym0i&nCfAh^ZZ_~t#F?j#|_dilO(A3}G<7jNgfOp>cyW6qyckkZ)h%vyq z;kAKRjeciM|1)F2FMjd%?bvvC@7_IkzVTS+$=h$gef#+M7}i=8MS=I;d+*%wiV~=+ z^T#CpzHPpY0eJybyYuZf*6;rP`?!AnI)o6D@n}82uMKFvbM_lwdmcvO-~Y{9Z{I#T zI)YLPTIysDdpt)>wmzeMgoI@ z^VI?yj$OAvCK)UM&N;T*Ev&WSnpdwgIOo6^gO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V>5$0xt_X1$TIO_)5l`G2@4T1O2JCUC*=qZ$X}Vd~$BajLQTE{4q_=`77;YjNi#N zW5#8I1Aa5bT05r?Gk!AQK>v_t`ZV~DxBOhHo@yYuyAGiF>CB+$Q{=8ymE=Xme^KXLJGq(a2k1kk%FE_zBh%QD>F`)xSqqM^)~ z@wy;^{)p-4|MG8GEEYI9ISDUq3@^;7YaAXPV!Pc=-g7bhr>6f9{uj&q^vsOc3kmoK zZ-4X2-vH=0R_K2O#($%h=l-43qpf%69Ezeq(=@np= gameProc.world.getWidth()) - gameProc.cursorX = gameProc.world.getWidth()-1; - if (gameProc.cursorY < 0) - gameProc.cursorY = 0; - if (gameProc.cursorY >= gameProc.world.getHeight()) - gameProc.cursorY = gameProc.world.getHeight()-1; + 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; } } @@ -60,8 +54,6 @@ public class GameInputHandler { } else switch (keyCode) { case Input.Keys.ALT_LEFT: gameProc.ctrlMode++; - gameProc.cursorX = (int)(gameProc.player.position.x/16); - gameProc.cursorY = (int)(gameProc.player.position.y/16); if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0; break; @@ -81,7 +73,8 @@ public class GameInputHandler { break; case Input.Keys.E: - gameProc.renderer.showCreative = !gameProc.renderer.showCreative; + if (CaveGame.STATE == GameState.GAME_PLAY) CaveGame.STATE = GameState.GAME_CREATIVE_INV; + else CaveGame.STATE = GameState.GAME_PLAY; break; } } @@ -102,7 +95,7 @@ public class GameInputHandler { } public void touchDown(int screenX, int screenY, int button) { - if (gameProc.renderer.showCreative && + if (CaveGame.STATE == GameState.GAME_CREATIVE_INV && screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 && screenXgameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 && @@ -118,8 +111,12 @@ public class GameInputHandler { } catch (Exception e) { Gdx.app.error("GameInputHandler", e.toString()); } - } else if (gameProc.renderer.showCreative) { - gameProc.renderer.showCreative = !gameProc.renderer.showCreative; + } else if (CaveGame.STATE == GameState.GAME_CREATIVE_INV) { + CaveGame.STATE = GameState.GAME_PLAY; + } else if (button == Input.Buttons.RIGHT && + !gameProc.player.canJump && !gameProc.player.flyMode) { + gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, + gameProc.player.inventory[gameProc.invSlot]); } else { gameProc.touchDownX = screenX; gameProc.touchDownY = screenY; @@ -132,24 +129,19 @@ public class GameInputHandler { public void touchUp(int screenX, int screenY, int button) { if (gameProc.isTouchDown) { if (button == Input.Buttons.RIGHT){ - if (gameProc.ctrlMode==1) { - gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, + gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, gameProc.player.inventory[gameProc.invSlot]); - } } else if (button == Input.Buttons.LEFT) { - if (gameProc.ctrlMode==1) { - if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) { - gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0); - } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) { - gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0); - } - } else { - if (screenYgameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && - screenXgameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && + screenX 0) { + gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0); + } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) { + gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0); } + } } gameProc.isTouchDown = false; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index d6378d3..e49a405 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -5,6 +5,9 @@ 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.game.mobs.Human; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -31,7 +34,7 @@ public class GameProc { public long touchDownTime; public GameProc() { - world = new GameWorld(4096,256); + world = new GameWorld(1024,256); renderer = new GameRenderer(this); physics = new GamePhysics(this); player = new Player(world.getSpawnPoint()); @@ -43,10 +46,46 @@ public class GameProc { renderer = new GameRenderer(this); } + private boolean isAutoselectable(int x, int y) { + return (world.getForeMap(x,y)>0 && + Items.BLOCKS.getValueAt(world.getForeMap(x,y)).collision); + } + + 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--; + } + } else { + cursorX = (int) (player.position.x + player.texWidth / 2) / 16; + cursorY = (int) (player.position.y + player.height+8)/16; + } + } + + private void checkCursorBounds() { + if (cursorX < 0) cursorX = 0; + if (cursorX >= world.getWidth()) cursorX = world.getWidth()-1; + if (cursorY < 0) cursorY = 0; + if (cursorY >= world.getHeight()) cursorY = world.getHeight()-1; + } + public void update(float delta) { RUN_TIME += delta; physics.update(delta); + if (ctrlMode==0) moveCursor(); + checkCursorBounds(); if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { if (touchDownButton== Input.Buttons.RIGHT) { @@ -56,7 +95,7 @@ public class GameProc { touchDownY< Assets.invBar.getRegionHeight() && touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && touchDownXgameProc.world.getHeight()) maxY = gameProc.world.getHeight(); for (int y=minY; y0 && + if (gameProc.world.getForeMap(x,y)>0){/* && !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) { spriteBatch.draw( Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(), - x * 16 - camera.position.x,y * 16 - camera.position.y); + x * 16 - camera.position.x,y * 16 - camera.position.y);*/ } else if (gameProc.world.getBackMap(x,y)>0) { spriteBatch.draw( Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture(), @@ -95,8 +96,8 @@ public class GameRenderer { if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); for (int y=minY; y0 && - Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) { + if (gameProc.world.getForeMap(x,y)>0) { /*&& + Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {*/ spriteBatch.draw( Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(), x * 16 - camera.position.x,y * 16 - camera.position.y); @@ -124,24 +125,30 @@ public class GameRenderer { } if (Assets.playerSkin[0][2].getRotation()>=60 || Assets.playerSkin[0][2].getRotation()<=-60) Mob.ANIM_SPEED = -Mob.ANIM_SPEED; + + //back hand Assets.playerSkin[1][2].setPosition( pl.position.x - camera.position.x - 6, pl.position.y - camera.position.y); Assets.playerSkin[1][2].draw(spriteBatch); + //back leg Assets.playerSkin[1][3].setPosition( pl.position.x - camera.position.x - 6, pl.position.y - camera.position.y + 10); Assets.playerSkin[1][3].draw(spriteBatch); + //front leg Assets.playerSkin[0][3].setPosition( pl.position.x - camera.position.x - 6, pl.position.y - camera.position.y + 10); Assets.playerSkin[0][3].draw(spriteBatch); - + //head spriteBatch.draw(Assets.playerSkin[pl.dir][0], - pl.position.x - camera.position.x - 2, pl.position.y - camera.position.y - 2); + pl.position.x - camera.position.x - 2, + pl.position.y - camera.position.y - 2); + //body spriteBatch.draw(Assets.playerSkin[pl.dir][1], pl.position.x - camera.position.x - 2, pl.position.y - camera.position.y + 8); - + //front hand Assets.playerSkin[0][2].setPosition( pl.position.x - camera.position.x - 6, pl.position.y - camera.position.y); @@ -165,6 +172,12 @@ public class GameRenderer { } private void drawGUI() { + if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)>0 || + gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY)>0 || + gameProc.ctrlMode==1) + spriteBatch.draw(Assets.guiCur, + gameProc.cursorX*16-camera.position.x, + gameProc.cursorY*16-camera.position.y); spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0); for (int i=0; i<9; i++) { if (gameProc.player.inventory[i]>0) { @@ -173,11 +186,9 @@ public class GameRenderer { 3); } } - spriteBatch.draw(Assets.invCur, + spriteBatch.draw(Assets.invBarCur, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot, -1); - - if (showCreative) drawCreative(); } private void drawTouchGui() { @@ -185,21 +196,32 @@ public class GameRenderer { touchBatch.draw(Assets.touchArrows[1],0,touchCam.viewportHeight-26); touchBatch.draw(Assets.touchArrows[2],26,touchCam.viewportHeight-26); touchBatch.draw(Assets.touchArrows[3],52,touchCam.viewportHeight-26); - //touchBatch.draw(Assets.touchSpace, touchCam.viewportWidth/2-52, touchCam.viewportHeight-26); touchBatch.draw(Assets.touchLMB, touchCam.viewportWidth-52, touchCam.viewportHeight-26); touchBatch.draw(Assets.touchRMB, touchCam.viewportWidth-26, touchCam.viewportHeight-26); touchBatch.draw(Assets.touchToggleMode, 78, touchCam.viewportHeight-26); } - public void render() { - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - - spriteBatch.begin(); + private void drawGamePlay() { drawWorld(); for (Mob mob : gameProc.mobs) drawMob(mob); drawPlayer(gameProc.player); drawWorldForeground(); drawGUI(); + } + + public void render() { + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + spriteBatch.begin(); + switch (CaveGame.STATE) { + case GAME_PLAY: + drawGamePlay(); + break; + case GAME_CREATIVE_INV: + drawGamePlay(); + drawCreative(); + break; + } spriteBatch.end(); if (CaveGame.TOUCH) { @@ -208,26 +230,12 @@ public class GameRenderer { touchBatch.end(); } - if (gameProc.ctrlMode==1) { - shapeRenderer.begin(ShapeRenderer.ShapeType.Line); - shapeRenderer.setColor(Color.ORANGE); - shapeRenderer.set(ShapeRenderer.ShapeType.Line); - shapeRenderer.rect(gameProc.cursorX * 16 - camera.position.x, - gameProc.cursorY * 16 - camera.position.y, 16, 16); - shapeRenderer.end(); - } - fontBatch.begin(); setFontColor(255,255,255); 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("Block: "+ - Items.BLOCKS.keys().toArray().get(gameProc.world.getForeMap( - (int)((gameProc.player.position.x+gameProc.player.texWidth/2)/16), - (int)(gameProc.player.position.y/16+2))), - 0, 80); fontBatch.end(); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java index 97d05cb..c4655bf 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java @@ -2,11 +2,13 @@ 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.Items; public class GameWorld { private final int WIDTH, HEIGHT; + private int[][] foreMap; private int[][] backMap; @@ -64,12 +66,15 @@ public class GameWorld { } public void placeToForeground(int x, int y, int value) { - if (getForeMap(x,y) == 0 || value == 0) setForeMap(x,y,value); + if (getForeMap(x,y) == 0 || value == 0) { + setForeMap(x,y,value); + } } public void placeToBackground(int x, int y, int value) { - if (value==0 || (getBackMap(x,y) == 0 && !Items.BLOCKS.getValueAt(value).foreground)) - setBackMap(x,y,value); + if (value==0 || (getBackMap(x,y) == 0 && !Items.BLOCKS.getValueAt(value).foreground)) { + setBackMap(x,y,value); + } } public Vector2 getSpawnPoint() { diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index d4635fd..8b1b699 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -1,7 +1,7 @@ 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; public class WorldGen { @@ -61,6 +61,8 @@ public class WorldGen { backMap = new int[width][height]; hMap = genLandscape(width, height/2, height/4, height/4*3); for (int x=0; x2 && x2 && x