From e5f474791112f95004f7e8f8ec96661884d7373f Mon Sep 17 00:00:00 2001 From: fred-boy Date: Fri, 13 Apr 2018 00:00:14 +0700 Subject: [PATCH] Add creative inventory --- android/assets/allitems.png | Bin 0 -> 2055 bytes .../src/ru/deadsoftware/cavecraft/Assets.java | 10 +++++ .../cavecraft/game/GameInputHandler.java | 35 ++++++++++++++---- .../cavecraft/game/GameRenderer.java | 24 +++++++++++- 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 android/assets/allitems.png diff --git a/android/assets/allitems.png b/android/assets/allitems.png new file mode 100644 index 0000000000000000000000000000000000000000..e1e5d77973f1dc696ecc0df1b784613c90654e2c GIT binary patch literal 2055 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo{p?&#~tz_78O`%fY(0|PTd zfKP}kP~62^QA&dRf`N&DBm;)v@9e6; zXy+{Oh%9Dc;5!Jyj5{V~zXb|PmbgZg1m~xflqVLYG6W=M=9TFAxrQi|8S9zqS(sZl z!~#o{98VX=kczmscMq1WHsEm$WS{i^e@fiRs$8cN0o&Fb{WhU7dtGZy>62}_x1;86 zJlel)tNYxGRvZB@|H^-_V7;YxVDG7jX$7ohjH~wi`|HOb_&~VBj{OOP=LO9N5>J>< zX&m4%bm|GvS1$Q2ll^Y8t*&g?hIjr}&l+z3GL+ltKaXjT{>#b;;RW$RXYRiL>@Ut} z$7tywRKjJ!c3&IDSqh}e#ktK zn8FTG zeg=0rf3XB9?vPPnKfx&PHi!R$f@8-1yc?Xn1c7i0>fvS7HF(MoSQN5n&-VP12%UCKLQ@HJc|4DVa?TCK~xzpPJigTMWM1&94I2LIpvX8HB3!C#{$I=%XmB~zL;+kW{T*~tow ze!Q=4s(j=u@oQ2_Sa)rP%8##?dV&|s7oDg3{5MMt)BSh7CmD+lq|R8NqQS}M*R(nC z;pZx=@a7o_oUB&A8id~0|2%f$k}}h_Z;P|%3g)+LTYI(gZ-x4vw_V$;ly{i#+h6l% z%GR_$f)74QWv@NzzNSq4K`D!#VDPnBk2Mdhf4eU}v|+!%j#Ugw56oFy9M-akZH!vp z5Zu83fZ4*)?!hg)gj!}LLG|plmLD3Tev9sp5)@dUxmMEEVeQ|p__Z7z*SB2jQCe`V z?&$h3mLu6w*=~XX+4~=bYcoAEU2D3SW5w3^kE=x)KhC-~E0E>Nt@S^yb~RM^W}nqy z%6c3AC(G4g&$6v)B8*$VY1eI4Qi!`8W&Dr%)V3`-2c~$ofC_3)S3j3^P6 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); -- 2.29.2