DEADSOFTWARE

Add creative inventory
authorfred-boy <fred-boy@protonmail.com>
Thu, 12 Apr 2018 17:00:14 +0000 (00:00 +0700)
committerfred-boy <fred-boy@protonmail.com>
Thu, 12 Apr 2018 17:00:14 +0000 (00:00 +0700)
android/assets/allitems.png [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/Assets.java
core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java

diff --git a/android/assets/allitems.png b/android/assets/allitems.png
new file mode 100644 (file)
index 0000000..e1e5d77
Binary files /dev/null and b/android/assets/allitems.png differ
index 6a99f1d3a60a34fab05ad670b5caf81418193115..e1fd5c94a1c44923c39ad4fb0ff97462453ad1d4 100644 (file)
@@ -25,6 +25,10 @@ public class Assets {
     public static TextureRegion invBar;
     public static TextureRegion invCur;
 
+    public static Texture creativeTexture;
+    public static TextureRegion creativeInv;
+    public static TextureRegion creativeScroll;
+
     public static Texture touchGui;
     public static TextureRegion[] touchArrows = new TextureRegion[4];
     public static TextureRegion touchLMB, touchRMB;
@@ -68,6 +72,12 @@ public class Assets {
         invBar = new TextureRegion(gui,0,0,182,22);
         invCur = new TextureRegion(gui,0,22,24,24);
 
+        creativeTexture = new Texture(Gdx.files.internal("allitems.png"));
+        creativeInv = new TextureRegion(creativeTexture, 0, 0, 176, 208);
+        creativeInv.flip(false,true);
+        creativeScroll = new TextureRegion(creativeTexture, 2, 209, 12, 15);
+        creativeScroll.flip(false, true);
+
         touchGui = new Texture(Gdx.files.internal("touch_gui.png"));
         for (int i=0; i<4; i++) {
             touchArrows[i] = new TextureRegion(touchGui, i*26, 0, 26,26);
index 0b714ddd43eda90fa210a60108f592d79ece325e..c288afface0331516b5feb2969414f3fecfd1c46 100644 (file)
@@ -1,8 +1,11 @@
 package ru.deadsoftware.cavecraft.game;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.utils.TimeUtils;
+import ru.deadsoftware.cavecraft.Assets;
 import ru.deadsoftware.cavecraft.GameScreen;
+import ru.deadsoftware.cavecraft.Items;
 
 public class GameInputHandler {
 
@@ -51,18 +54,21 @@ public class GameInputHandler {
             if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0;
         }
         if (keyCode == Input.Keys.SPACE) {
-             if (gameProc.player.canJump) {
-                 gameProc.player.moveY.add(0, -7);
-             } else if (!gameProc.player.flyMode) {
-                 gameProc.player.flyMode = true;
-                 gameProc.player.moveY.setZero();
-             } else {
-                 gameProc.player.moveY.y = -GamePhysics.PL_SPEED;
-             }
+            if (gameProc.player.canJump) {
+                gameProc.player.moveY.add(0, -7);
+            } else if (!gameProc.player.flyMode) {
+                gameProc.player.flyMode = true;
+                gameProc.player.moveY.setZero();
+            } else {
+                gameProc.player.moveY.y = -GamePhysics.PL_SPEED;
+            }
         }
         if (keyCode == Input.Keys.CONTROL_LEFT) {
             gameProc.player.moveY.y = GamePhysics.PL_SPEED;
         }
+        if (keyCode == Input.Keys.E) {
+            gameProc.renderer.showCreative = !gameProc.renderer.showCreative;
+        }
     }
 
     public void keyUp(int keyCode) {
@@ -85,6 +91,19 @@ public class GameInputHandler {
         gameProc.touchDownY = screenY;
         gameProc.touchDownTime = TimeUtils.millis();
         gameProc.isTouchDown = true;
+        if (gameProc.renderer.showCreative) {
+            try {
+                int ix = (int)(screenX-(gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2+8))/18;
+                int iy = (int)(screenY-(gameProc.renderer.camera.viewportHeight/2 - Assets.creativeInv.getRegionHeight()/2+18))/18;
+                int item = ix+iy*8;
+                for (int i=8; i>0; i--) {
+                    gameProc.player.inventory[i] = gameProc.player.inventory[i-1];
+                }
+                if (item>=0 && item<Items.BLOCKS.size) gameProc.player.inventory[0] = item;
+            } catch (Exception e) {
+                Gdx.app.error("GameInputHandler", e.toString());
+            }
+        }
     }
 
     public void touchUp(int screenX, int screenY, int button) {
index 9183c677e3ee90c1c7ba09d52ff5abd2efcd69c3..00508b2b74e153bdeb219000c0bb5c9cc99b6274 100644 (file)
@@ -19,6 +19,8 @@ public class GameRenderer {
 
     private GameProc gameProc;
 
+    public boolean showCreative = false;
+
     public OrthographicCamera camera, fontCam;
     ShapeRenderer shapeRenderer;
     SpriteBatch spriteBatch, fontBatch;
@@ -27,8 +29,8 @@ public class GameRenderer {
         Gdx.gl.glClearColor(0f,.6f,.6f,1f);
         this.gameProc = gameProc;
         camera = new OrthographicCamera();
-        camera.setToOrtho(true, 360,
-                360*((float)GameScreen.getHeight()/GameScreen.getWidth()));
+        camera.setToOrtho(true, 480,
+                480*((float)GameScreen.getHeight()/GameScreen.getWidth()));
 
         shapeRenderer = new ShapeRenderer();
         shapeRenderer.setProjectionMatrix(camera.combined);
@@ -141,6 +143,22 @@ public class GameRenderer {
         Assets.playerSkin[0][2].draw(spriteBatch);
     }
 
+    private void drawCreative() {
+        float x = camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2;
+        float y = camera.viewportHeight/2 - Assets.creativeInv.getRegionHeight()/2;
+        spriteBatch.draw(Assets.creativeInv, x, y);
+        spriteBatch.draw(Assets.creativeScroll, x+156, y+18);
+        for (int i=1; i<Items.BLOCKS.size; i++) {
+            spriteBatch.draw(Items.BLOCKS.getValueAt(i).getTexture(),x+8+(i%8)*18,
+                    y+18+(i/8)*18);
+        }
+        for (int i=0; i<9; i++) {
+            if (gameProc.player.inventory[i]>0)
+                spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
+                        x+8+i*18, y+184);
+        }
+    }
+
     private void drawGUI() {
         spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
         for (int i=0; i<9; i++) {
@@ -154,6 +172,8 @@ public class GameRenderer {
                 camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot,
                 -1);
 
+        if (showCreative) drawCreative();
+
         if (CaveGame.TOUCH) {
             spriteBatch.draw(Assets.touchArrows[0],26,camera.viewportHeight-52);
             spriteBatch.draw(Assets.touchArrows[1],0,camera.viewportHeight-26);