From: fred-boy Date: Fri, 6 Apr 2018 13:28:08 +0000 (+0700) Subject: Add inventory bar X-Git-Tag: alpha0.1~22 X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=commitdiff_plain;h=7115b8cce5cc8469c03ea1fa1fc24506a1e2765e Add inventory bar --- diff --git a/android/assets/gui.png b/android/assets/gui.png new file mode 100644 index 0000000..ef76dc0 Binary files /dev/null and b/android/assets/gui.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index fcbfe7a..45634eb 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -17,6 +17,10 @@ public class Assets { public static Texture terrain; public static TextureRegion[] blockTextures = new TextureRegion[BLOCK_TEXTURES]; + public static Texture gui; + public static TextureRegion invBar; + public static TextureRegion invCur; + public static void load() { charTexture = new Texture(Gdx.files.internal("char.png")); playerSprite[0] = new Sprite(new TextureRegion(charTexture, 0,0,8,30)); @@ -26,6 +30,10 @@ public class Assets { shade = new Sprite(new Texture(Gdx.files.internal("shade.png"))); + gui = new Texture(Gdx.files.internal("gui.png")); + invBar = new TextureRegion(gui,0,0,182,22); + invCur = new TextureRegion(gui,0,22,24,24); + terrain = new Texture(Gdx.files.internal("terrain.png")); for (int i=0; i 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() {