From 7115b8cce5cc8469c03ea1fa1fc24506a1e2765e Mon Sep 17 00:00:00 2001 From: fred-boy Date: Fri, 6 Apr 2018 20:28:08 +0700 Subject: [PATCH] Add inventory bar --- android/assets/gui.png | Bin 0 -> 5061 bytes core/src/ru/deadsoftware/cavecraft/Assets.java | 8 ++++++++ .../ru/deadsoftware/cavecraft/GameScreen.java | 1 + .../cavecraft/game/GameInputHandler.java | 9 ++++++++- .../deadsoftware/cavecraft/game/GameProc.java | 4 +++- .../cavecraft/game/GameRenderer.java | 16 ++++++++++++++++ .../cavecraft/game/objects/Player.java | 5 +++++ 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 android/assets/gui.png diff --git a/android/assets/gui.png b/android/assets/gui.png new file mode 100644 index 0000000000000000000000000000000000000000..ef76dc04938b993da01fec7e5c2771c7cf56e607 GIT binary patch literal 5061 zcmV;$6FTgPP)6QMm*`$#fkY4lf+8d=JEO=+6daFd=FB;#zv_cU)mvTNea1lSj3Mf0 zGc)IOSH16B?{`)AFaQoSX8gn;0pPRGJ_7(ee*72!@ZERc0RV2^ycvI=G2{OO9zJ}C z`}gmA#eV$wF+TqILh>**Z1MWhX8`drpZ6};Db+I#8{RAT?YsW7(M;|-FM%;ON<#~ z@X<#feWG%pZC*6$h>$ z@Zdsz)3GkXy?giW9v>gWT8pA6@ZpCaUN~M+0!@AKm_*-;_+<>p3!t8^|IRhJckkZa zM~@!i=FOWBLQKY^^}GmU84$lIeHUGOk&dL_|LJ@8?j9W-K`8~T^<+JEtwELn)(zJ- zrH_7>fKNTzwgmuOI|K^F007(CVNo!^0VEQJpb6|`?Nr6@y)U87%83gagin54<4{50DdNQ7|0B4?tLNS-nDyAFjzWiB=mljrVxg+UR|6 z-0*UD&cV8V4Fn4`xSpO|DKu@1JX2`8b}$zQd@fC)j+7bz7KJAg3|={zpU}bK%7PCD zqJ^fgL4>wiM}|`7df_k#Apr*znV);91U8M0#+C|lTMzH=EWAej(ne+^?S(wOIYTnD0WqSOwMoMY2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!%%%$RYR;J~Z%)-z`OUjYa3%JOT%xTig1#$|&8{^ZrGQbr*J>bl-}Jaop4%K`_& z6V>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 0) { gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0); @@ -74,4 +75,10 @@ public class GameInputHandler { gameProc.isTouchDown = false;*/ } + public void scrolled(int amount) { + gameProc.invSlot += amount; + if (gameProc.invSlot < 0) gameProc.invSlot = 8; + if (gameProc.invSlot > 8) gameProc.invSlot = 0; + } + } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 61c64ff..cf70144 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -14,6 +14,7 @@ public class GameProc { public GamePhysics physics; public int cursorX, cursorY; + public int invSlot; public boolean isTouchDown = false; public int touchDownX, touchDownY; @@ -36,7 +37,8 @@ public class GameProc { physics.update(delta); if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { - world.placeToBackground(cursorX,cursorY,1); + world.placeToBackground(cursorX,cursorY, + player.inventory[invSlot]); isTouchDown = false; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 09a433a..54ec384 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -84,11 +84,27 @@ public class GameRenderer { Assets.playerSprite[pl.dir].draw(spriteBatch); } + private void drawGUI() { + spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, + camera.viewportHeight - Assets.invBar.getRegionHeight()); + for (int i=0; i<8; i++) { + if (gameProc.player.inventory[i]>0) { + spriteBatch.draw(BlocksLoader.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(), + camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20, + camera.viewportHeight-19); + } + } + spriteBatch.draw(Assets.invCur, + camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot, + camera.viewportHeight - Assets.invBar.getRegionHeight() - 2); + } + public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); drawWorld(); drawPlayer(gameProc.player); + drawGUI(); spriteBatch.end(); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.setColor(Color.ORANGE); diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 0c5581a..2953d94 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -9,6 +9,7 @@ public class Player { public Vector2 moveX, moveY; public int width, height, dir; public boolean canJump; + public int[] inventory; public Player() { position = new Vector2(0, 0); @@ -16,6 +17,10 @@ public class Player { moveY = new Vector2(0, 0); width = 8; height = 30; + inventory = new int[9]; + inventory[0] = 1; + inventory[1] = 2; + inventory[2] = 3; } public Rectangle getRect() { -- 2.29.2