From: fred-boy Date: Thu, 12 Apr 2018 17:00:14 +0000 (+0700) Subject: Add creative inventory X-Git-Tag: alpha0.1~7 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=e5f474791112f95004f7e8f8ec96661884d7373f;p=cavedroid.git Add creative inventory --- diff --git a/android/assets/allitems.png b/android/assets/allitems.png new file mode 100644 index 0000000..e1e5d77 Binary files /dev/null and b/android/assets/allitems.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index 6a99f1d..e1fd5c9 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -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); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java index 0b714dd..c288aff 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java @@ -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 && item0) + 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);