DEADSOFTWARE

Add inventory bar
authorfred-boy <fred-boy@protonmail.com>
Fri, 6 Apr 2018 13:28:08 +0000 (20:28 +0700)
committerfred-boy <fred-boy@protonmail.com>
Fri, 6 Apr 2018 13:28:08 +0000 (20:28 +0700)
android/assets/gui.png [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/Assets.java
core/src/ru/deadsoftware/cavecraft/GameScreen.java
core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/objects/Player.java

diff --git a/android/assets/gui.png b/android/assets/gui.png
new file mode 100644 (file)
index 0000000..ef76dc0
Binary files /dev/null and b/android/assets/gui.png differ
index fcbfe7a1a1ee8fd345216999555c06c710d0d53e..45634ebfa449f2ed7fd4ec1357570d6f3e3d9562 100644 (file)
@@ -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<BLOCK_TEXTURES; i++) {
             blockTextures[i] = new TextureRegion(terrain,
index 02d07e212a615d3314ea4cfe283e6fc78e70106c..efdce0440b8bb2a74d179fdd6188ee211ff59671 100644 (file)
@@ -117,6 +117,7 @@ public class GameScreen implements Screen {
 
         @Override
         public boolean scrolled(int amount) {
+            gameInput.scrolled(amount);
             return false;
         }
     }
index ff8fa2e89438cec46984e53333740fcc9e72521b..d63568cb1dad36a1cfd5bd16d310e6fe43297657 100644 (file)
@@ -54,7 +54,8 @@ public class GameInputHandler {
     public void touchUp(int screenX, int screenY, int button) {
         if (gameProc.isTouchDown) {
             if (button == Input.Buttons.RIGHT){
-                gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 1);
+                gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY,
+                        gameProc.player.inventory[gameProc.invSlot]);
             } else if (button == Input.Buttons.LEFT) {
                 if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 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;
+    }
+
 }
index 61c64ffebf940ab81233bce72fb7da74977c4e2a..cf70144d75948eeac988b7c517b12a8247d11d0a 100644 (file)
@@ -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;
         }
     }
index 09a433a81e2f8d9d31702e0f910d66ac670c4e0e..54ec384e040cf91cf688cce9b31ba7bcd9ad357f 100644 (file)
@@ -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);
index 0c5581a7ee2711999f526e52bbc77cafa4385a2e..2953d940989febecabc83467aff77e0de7c98623 100644 (file)
@@ -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() {