From 0b8922bfbb2bbec067b532ecb7912f6afe02c4ef Mon Sep 17 00:00:00 2001 From: fred-boy Date: Fri, 28 Sep 2018 18:49:59 +0700 Subject: [PATCH] Add drop and block breaking --- android/assets/break.png | Bin 0 -> 750 bytes android/assets/items.png | Bin 1349 -> 1704 bytes .../cavecraft/game/GameInput.java | 8 +- .../cavecraft/game/GamePhysics.java | 12 ++ .../deadsoftware/cavecraft/game/GameProc.java | 33 ++-- .../cavecraft/game/GameRenderer.java | 24 ++- .../ru/deadsoftware/cavecraft/game/Items.java | 146 ++++++++++-------- .../cavecraft/game/objects/Block.java | 22 ++- .../cavecraft/game/objects/Drop.java | 35 +++++ .../deadsoftware/cavecraft/misc/Assets.java | 10 +- 10 files changed, 196 insertions(+), 94 deletions(-) create mode 100644 android/assets/break.png create mode 100644 core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java diff --git a/android/assets/break.png b/android/assets/break.png new file mode 100644 index 0000000000000000000000000000000000000000..1af7a40c7ea69785f8788432f16aae5d78d44e06 GIT binary patch literal 750 zcmV000mO1^@s6kp*;E00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY4yFJA4yFNz+^KH>000McNliru;t384As=>^n5zH)02y>e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00LG?L_t(&-tC$}j>8}fMV%A_$&W65I~f}PHkc7l{e5v#5#mcwz%@w}Y2TxTNKIdF14Qf2M*Y3SMPq`j`n>G48qtUM8W3h~j zcuQ2|{d;)t_sNz=7tZt4EYoz1(ap;UXXUqdN~fb*h-|eKaklu9)p*S@EZ=_xkBESX zMes#)bPM0wB%}ONYh8XLiXF#M5D`cSTl?4Hf{`q4C_6Vd5S5);x{!tvZ>9=VRe~ zFQ8cY);KME&bh80A#5#2{D;QpNz;*|^ThR@r9aLiqN>SKN~>HCtxk8w%Y%fMPbsZk z4LHNWV?=cKgt&+23qAvH4FnobP9ZfI*V>~z*YsEUsZYUP=kqR{7PYCO?=4=!JpEO<0zx$Bh8M=O1+IGOHbB_%1b5O(KTM%2wwjFGr~lXyk$4S%i?k`BA-O= gGLjLrsP5sv0Q(wyftb6Bc>n+a07*qoM6N<$g1LEQ-~a#s literal 0 HcmV?d00001 diff --git a/android/assets/items.png b/android/assets/items.png index cecb5e8cc63369f91734298023b6aa0a34898973..d4ca336da12bf638f97aee84ed09210ef7adac54 100644 GIT binary patch delta 1406 zcmV-^1%dj-3aAZ`RDTK^Cwn~pOaK4|HAzH4RCwC$*k5ebcNGBea~XzufyFkKV!E}R z!ng#p(GaU9x2y~0;rcR(Cd>z;K9D6!NR08%gE8^J#i|bmk%wxWuS+mwPdorRfn-r6 z&Siw+mIdp0pv>0Ds1S5tAC`Ol^=8of`xb?!pU=~MIq9$8e1FgRo^vXZ;p1CBkea`L zcj51qvhj^ZqZNPb*s;>_z+O4YBj_?yNu9Xf)EEJ$qtoY%D8&e0)3|KYlz89Xga1|KJlNY4eev#>3zLMppdj z=%)0m7k0#te}D2(w})kKbx!inUAq))51{Bv`2(cRsho%|OsUW_eUwqz&&jo1GY zU7H58lmD;NH{;=fH99Aq)5<9T?aBYbnVC|TxIOug9z9y>61OM+?%lgfUE=oSf9k$-Z|FCya9sZ$XVDd+qmBHn)K zj}Z|m=lmifUis5}eD^z%6oF+@03`q2N&dNOw_^V0JJJ8aHSvec&S`#rKKlFnvpc6N zSFXg)ojbETr+;0YjdhSJ#wVyR;{NwOU*Dfzp*ACPtTk=8}tHnc89M4Z3$b|okI>-Bnyh&XfROeH7zYqeU6h?tt1 zs^lbp*XE%V5pm4Dua9nh_xn#@sNAjOZ=J(PZ~Ab5HL7b?&q&ljgj8;#<#y0t9yI0ihpQhq&IzS;uF!`{lJpWk^gZA@X&^? zRw2lF`3D9DT7@9z<=?eySE~@@y!`8Teymjpa$f$iCwp6k;BF@W*l(&590Q>|7@ zDWxJ!WTTV|sde!D6tJ_!s|NjROY`#QF2*<=GvOB-1Db9A;Kum{@r8s>i?#gk#=o;5zL4-~v6ep~Vpy>I`oi!3 zZ^C!f#xC{puk?8CgPA`kzBu#e#207&ocQ9*pY{EPnSZHg*%;|v(%ie!(n&-?RCwC$+23oGbsPuq&yk{8PMok|pxeS< zXBf7S=FOQ-HZOK%Qn0$S3$K#hRsVrxS8*~gW~8@*B3|u6C2NBy5kwNVv{=il30t(R ziO{zTdDhuDan5;!!0q+AIydigo{Q)GJbLcCQtbfmD*z8Yc08caBy%i z9X@Z~0S7X<}j`rIb?T7*KEd z_dK|sc71z3?RjuLRgMAmmVah;DBZaEW}2BDN|j>(D1X25gYqjsJcD+1u1mW**QLDW zFO^EER4S#sX8SS+Sfr%t76 zJAryMZSPF&pL~?6?F8z&{@$+i#g_+DwVeR0G)w;3276jl$ELM0c560vZ*7j*`Nwg8 zW+597YRd9I%(h2&cX!Or&c^igbc~OWHZU=6W_B)PMbRFU67fHpkS|qqz3fgKRv2mAeBN>}gGXuWyVqqxWNC`e7j= zQpA(RU__)^hrrVO^kP0+4AwdXmgmdma*BAe7>tNi>kz2SFHAoy%$z=#BAzS;BO=v0 z1pe##`wp~5L?nj*EAjxy9`idkt*tD7<$u3^s`bbp5z(=6dPzPje62Acd(7|H^yiX% zMd4GeNB$@IznA1I3ZH5{@<&8;v^-pT{r?u;7{Kb7`Sau}XZ}3-%9%e;zH;Wzb^R4H zzq^6eW=%xIt)J$f>Pv3ky!ll5a=H9e`I*z_o+^L#%zbwP0000000000000000F%B2 h(v!di4;b*j`v<_E=lC%ShnN5W002ovPDHLkV1j* 0) { - gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0); - } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) { - gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0); - } - + gameProc.blockDmg = 0; } } gameProc.isTouchDown = false; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index fdf1206..c387bab 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.game.mobs.Mob; +import ru.deadsoftware.cavecraft.game.objects.Drop; import ru.deadsoftware.cavecraft.game.objects.Player; import java.util.Iterator; @@ -67,6 +68,16 @@ public class GamePhysics { return gameProc.world.getForeMap((int)(rect.x+rect.width/2)/16, (int)(rect.y+rect.height/8*7)/16); } + private void dropPhy(Drop drop) { + if (drop.move.y < 9) drop.move.y += gravity.y/4; + drop.position.add(drop.move); + drop.position.y = MathUtils.round(drop.position.y); + while (checkColl(drop.getRect())) { + drop.position.y--; + drop.move.y = 0; + } + } + private void playerPhy(Player pl) { pl.position.add(pl.moveY); if (checkColl(pl.getRect())) { @@ -170,6 +181,7 @@ public class GamePhysics { } public void update(float delta) { + for (Drop drop : gameProc.drops) dropPhy(drop); for (Mob mob : gameProc.mobs) { mob.ai(); mobPhy(mob); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index ddeac68..25658c1 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -9,6 +9,7 @@ import ru.deadsoftware.cavecraft.game.mobs.FallingGravel; import ru.deadsoftware.cavecraft.game.mobs.FallingSand; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.mobs.Pig; +import ru.deadsoftware.cavecraft.game.objects.Drop; import ru.deadsoftware.cavecraft.game.objects.Player; import ru.deadsoftware.cavecraft.misc.AppState; import ru.deadsoftware.cavecraft.misc.Assets; @@ -22,11 +23,11 @@ public class GameProc implements Serializable{ public static boolean DO_UPD = false; public static int UPD_X = -1, UPD_Y = -1; - public static int FUPD_X, FUPD_Y; public Player player; public ArrayList mobs; + public ArrayList drops; public transient GameWorld world; public transient GameRenderer renderer; @@ -36,6 +37,7 @@ public class GameProc implements Serializable{ public int invSlot; public int ctrlMode; public int creativeScroll, maxCreativeScroll; + public int blockDmg = 0; public boolean isTouchDown, isKeyDown, swim; public int touchDownX, touchDownY, keyDownCode; @@ -46,6 +48,7 @@ public class GameProc implements Serializable{ world = new GameWorld(); world.generate(1024,256); player = new Player(world.getSpawnPoint()); + drops = new ArrayList(); mobs = new ArrayList(); for (int i=0; i<16; i++) { mobs.add(new Pig(i*256, 196*16)); @@ -79,6 +82,7 @@ public class GameProc implements Serializable{ } private void moveCursor() { + int pastX = cursorX, pastY = cursorY; if (ctrlMode == 0 && CaveGame.TOUCH) { cursorX = (int) (player.position.x + player.texWidth / 2) / 16; if (player.dir == 0) cursorX--; @@ -103,6 +107,7 @@ public class GameProc implements Serializable{ (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)<0) cursorX--; } + if (pastX!=cursorX || pastY!=cursorY) blockDmg = 0; } private void checkCursorBounds() { @@ -397,29 +402,33 @@ public class GameProc implements Serializable{ } } - updateFluids(FUPD_X, FUPD_Y); - FUPD_X++; - if (FUPD_X>=(int)(renderer.camera.position.x+renderer.camera.viewportWidth)/16+1) { - FUPD_X = (int) renderer.camera.position.x / 16 - 1; - FUPD_Y++; - if (FUPD_Y>=(int)(renderer.camera.position.y+renderer.camera.viewportHeight)/16+1) { - FUPD_Y = (int) renderer.camera.position.y / 16 - 1; - } - } - physics.update(delta); moveCursor(); checkCursorBounds(); + if (isTouchDown && touchDownButton==Input.Buttons.LEFT) { + if (world.getForeMap(cursorX, cursorY) > 0 && + Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp()>=0){// || world.getBackMap(cursorX, cursorY) > 0) { + blockDmg++; + if (blockDmg>=Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp()) { + if (Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getDrop()>0) + drops.add(new Drop(cursorX*16+4, cursorY*16+4, Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getDrop())); + world.placeToForeground(cursorX, cursorY, 0); + blockDmg=0; + } + } + } + if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { if (touchDownButton== Input.Buttons.RIGHT) { useItem(cursorX, cursorY, player.inventory[invSlot], true); + isTouchDown = false; } else if (touchDownY< Assets.invBar.getRegionHeight() && touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && touchDownX 0) { + spriteBatch.draw(Assets.wreck[ + 10*gameProc.blockDmg/ + Items.BLOCKS.getValueAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)).getHp()], + gameProc.cursorX*16-camera.position.x, + gameProc.cursorY*16-camera.position.y); + } if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)>0 || gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY)>0 || gameProc.ctrlMode==1 || @@ -224,6 +244,7 @@ public class GameRenderer extends Renderer { drawWorldBackground(); drawPlayer(gameProc.player); for (Mob mob : gameProc.mobs) drawMob(mob); + for (Drop drop : gameProc.drops) drawDrop(drop); drawWorldForeground(); drawGUI(); } @@ -250,7 +271,8 @@ public class GameRenderer extends Renderer { drawString("X: "+(int)(gameProc.player.position.x/16),0, 10); drawString("Y: "+(int)(gameProc.player.position.y/16),0, 20); drawString("Mobs: "+gameProc.mobs.size(), 0, 30); - drawString("Block: "+Items.BLOCKS.getKeyAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)), 0, 40); + drawString("Drops: "+gameProc.drops.size(), 0, 40); + drawString("Block: "+Items.BLOCKS.getKeyAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)), 0, 50); } spriteBatch.end(); diff --git a/core/src/ru/deadsoftware/cavecraft/game/Items.java b/core/src/ru/deadsoftware/cavecraft/game/Items.java index db32ad1..690d5ac 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/Items.java +++ b/core/src/ru/deadsoftware/cavecraft/game/Items.java @@ -146,6 +146,16 @@ public class Items { ITEMS.add(new Item("Diamond Sword", 3, 1)); //58 ITEMS.add(new Item("Golden Sword", 4, 1)); + //59 + ITEMS.add(new Item("Wooden Shovel", 5, 1)); + //60 + ITEMS.add(new Item("Stone Shovel", 6, 1)); + //61 + ITEMS.add(new Item("Iron Shovel", 7, 1)); + //62 + ITEMS.add(new Item("Diamond Shovel", 8, 1)); + //63 + ITEMS.add(new Item("Golden Shovel", 9, 1)); } @@ -153,141 +163,141 @@ public class Items { //0 BLOCKS.put("none", null); //1 - BLOCKS.put("stone", new Block(0)); + BLOCKS.put("stone", new Block(0, 450, 4)); //2 - BLOCKS.put("grass", new Block(1)); + BLOCKS.put("grass", new Block(1, 54, 3)); //3 - BLOCKS.put("dirt", new Block(2)); + BLOCKS.put("dirt", new Block(2, 45, 3)); //4 - BLOCKS.put("cobblestone", new Block(3)); + BLOCKS.put("cobblestone", new Block(3, 600, 4)); //5 - BLOCKS.put("planks", new Block(4)); + BLOCKS.put("planks", new Block(4, 180, 5)); //6 - BLOCKS.put("sapling", new Block(5,false,false,true)); + BLOCKS.put("sapling", new Block(5,0,6,false,false,true)); //7 - BLOCKS.put("bedrock", new Block(6)); + BLOCKS.put("bedrock", new Block(6,-1,7)); //8 - BLOCKS.put("water", new Block(7,false,false,true)); + BLOCKS.put("water", new Block(7,-1,0,false,false,true)); //9 - BLOCKS.put("lava", new Block(8,false,false,false)); + BLOCKS.put("lava", new Block(8,-1,0,false,false,false)); //10 - BLOCKS.put("sand", new Block(9)); + BLOCKS.put("sand", new Block(9, 45,8)); //11 - BLOCKS.put("gravel", new Block(10)); + BLOCKS.put("gravel", new Block(10, 54,9)); //12 - BLOCKS.put("gold_ore", new Block(11)); + BLOCKS.put("gold_ore", new Block(11, 900,10)); //13 - BLOCKS.put("iron_ore", new Block(12)); + BLOCKS.put("iron_ore", new Block(12, 900,11)); //14 - BLOCKS.put("coal_ore", new Block(13)); + BLOCKS.put("coal_ore", new Block(13, 900,0)); //15 - BLOCKS.put("log", new Block(14)); + BLOCKS.put("log", new Block(14, 180,13)); //16 - BLOCKS.put("leaves", new Block(15)); + BLOCKS.put("leaves", new Block(15, 21,0)); //17 - BLOCKS.put("sponge", new Block(16)); + BLOCKS.put("sponge", new Block(16, 54,0)); //18 - BLOCKS.put("glass", new Block(17,true,false,true)); + BLOCKS.put("glass", new Block(17, 27,0,true,false,true)); //19 - BLOCKS.put("lapis_ore", new Block(18)); + BLOCKS.put("lapis_ore", new Block(18, 900,0)); //20 - BLOCKS.put("lapis_block", new Block(19)); + BLOCKS.put("lapis_block", new Block(19, 900,17)); //21 - BLOCKS.put("sandstone", new Block(20)); + BLOCKS.put("sandstone", new Block(20, 240,18)); //22 - BLOCKS.put("noteblock", new Block(21)); + BLOCKS.put("noteblock", new Block(21, 75,0)); //23 - BLOCKS.put("bed_l", new Block(22,false,true,true)); + BLOCKS.put("bed_l", new Block(22, 21,0,false,true,true)); //24 - BLOCKS.put("bed_r", new Block(23, false,true, true)); + BLOCKS.put("bed_r", new Block(23, 21,0, false,true, true)); //25 - BLOCKS.put("cobweb", new Block(24,false,false,true)); + BLOCKS.put("cobweb", new Block(24, 1200,0,false,false,true)); //26 - BLOCKS.put("tallgrass", new Block(25,false,false,true)); + BLOCKS.put("tallgrass", new Block(25, 0,0,false,false,true)); //27 - BLOCKS.put("deadbush", new Block(26,false,false,true)); + BLOCKS.put("deadbush", new Block(26, 0,0,false,false,true)); //28 - BLOCKS.put("brick_block", new Block(27)); + BLOCKS.put("brick_block", new Block(27, 600,22)); //29 - BLOCKS.put("dandelion", new Block(28,false,false,true)); + BLOCKS.put("dandelion", new Block(28, 0,23,false,false,true)); //30 - BLOCKS.put("rose", new Block(29,false,false,true)); + BLOCKS.put("rose", new Block(29, 0,24,false,false,true)); //31 - BLOCKS.put("brown_mushroom", new Block(30,false,false,true)); + BLOCKS.put("brown_mushroom", new Block(30, 0,25,false,false,true)); //32 - BLOCKS.put("red_mushroom", new Block(31,false,false,true)); + BLOCKS.put("red_mushroom", new Block(31, 0,26,false,false,true)); //33 - BLOCKS.put("wool_while", new Block(32,true,false,false)); + BLOCKS.put("wool_while", new Block(32, 75,27,true,false,false)); //34 - BLOCKS.put("wool_orange", new Block(33,true,false,false)); + BLOCKS.put("wool_orange", new Block(33, 75,28,true,false,false)); //35 - BLOCKS.put("wool_magenta", new Block(34,true,false,false)); + BLOCKS.put("wool_magenta", new Block(34, 75,29,true,false,false)); //36 - BLOCKS.put("wool_lightblue", new Block(35,true,false,false)); + BLOCKS.put("wool_lightblue", new Block(35, 75,30,true,false,false)); //37 - BLOCKS.put("wool_yellow", new Block(36,true,false,false)); + BLOCKS.put("wool_yellow", new Block(36, 75,31,true,false,false)); //38 - BLOCKS.put("wool_lime", new Block(37,true,false,false)); + BLOCKS.put("wool_lime", new Block(37, 75,32,true,false,false)); //39 - BLOCKS.put("wool_pink", new Block(38,true,false,false)); + BLOCKS.put("wool_pink", new Block(38, 75,33,true,false,false)); //40 - BLOCKS.put("wool_gray", new Block(39,true,false,false)); + BLOCKS.put("wool_gray", new Block(39, 75,34,true,false,false)); //41 - BLOCKS.put("wool_lightgray", new Block(40,true,false,false)); + BLOCKS.put("wool_lightgray", new Block(40, 75,35,true,false,false)); //42 - BLOCKS.put("wool_cyan", new Block(41,true,false,false)); + BLOCKS.put("wool_cyan", new Block(41, 75,36,true,false,false)); //43 - BLOCKS.put("wool_purple", new Block(42,true,false,false)); + BLOCKS.put("wool_purple", new Block(42, 75,37,true,false,false)); //44 - BLOCKS.put("wool_blue", new Block(43,true,false,false)); + BLOCKS.put("wool_blue", new Block(43, 75,38,true,false,false)); //45 - BLOCKS.put("wool_brown", new Block(44,true,false,false)); + BLOCKS.put("wool_brown", new Block(44, 75,39,true,false,false)); //46 - BLOCKS.put("wool_green", new Block(45,true,false,false)); + BLOCKS.put("wool_green", new Block(45, 75,40,true,false,false)); //47 - BLOCKS.put("wool_red", new Block(46,true,false,false)); + BLOCKS.put("wool_red", new Block(46, 75,41,true,false,false)); //48 - BLOCKS.put("wool_black", new Block(47,true,false,false)); + BLOCKS.put("wool_black", new Block(47, 75,42,true,false,false)); //49 - BLOCKS.put("gold_block", new Block(48)); + BLOCKS.put("gold_block", new Block(48, 900,43)); //50 - BLOCKS.put("iron_block", new Block(49)); + BLOCKS.put("iron_block", new Block(49, 1500,44)); //51 - BLOCKS.put("stone_slab", new Block(0, 8, 16,8, 50, true, false, true)); + BLOCKS.put("stone_slab", new Block(0, 8, 16,8, 50, 600,45, true, false, true)); //52 - BLOCKS.put("double_stone_slab", new Block(51)); + BLOCKS.put("double_stone_slab", new Block(51, 600,45)); //53 - BLOCKS.put("sandstone_slab", new Block(0, 8, 16,8, 52, true, false, true)); + BLOCKS.put("sandstone_slab", new Block(0, 8, 16,8, 52, 600,46, true, false, true)); //54 - BLOCKS.put("wooden_slab", new Block(0, 8, 16,8, 53, true, false, true)); + BLOCKS.put("wooden_slab", new Block(0, 8, 16,8, 53, 180,47, true, false, true)); //55 - BLOCKS.put("cobblestone_slab", new Block(0, 8, 16,8, 54, true, false, true)); + BLOCKS.put("cobblestone_slab", new Block(0, 8, 16,8, 54, 600,48, true, false, true)); //56 - BLOCKS.put("brick_slab", new Block(0, 8, 16,8, 55, true, false, true)); + BLOCKS.put("brick_slab", new Block(0, 8, 16,8, 55, 600,49, true, false, true)); //57 - BLOCKS.put("stonebrick", new Block(64)); + BLOCKS.put("stonebrick", new Block(64, 450,50)); //58 - BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 56, true, false, true)); + BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 56, 450,51, true, false, true)); //59 - BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, true, false, true)); + BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, 39,52, true, false, true)); //60 - BLOCKS.put("water_16", new Block(7,false,false,true)); + BLOCKS.put("water_16", new Block(7, -1,0,false,false,true)); //61 - BLOCKS.put("water_12", new Block(58,false,false,true)); + BLOCKS.put("water_12", new Block(58, -1,0,false,false,true)); //62 - BLOCKS.put("water_8", new Block(59,false,false,true)); + BLOCKS.put("water_8", new Block(59, -1,0,false,false,true)); //63 - BLOCKS.put("water_4", new Block(60,false,false,true)); + BLOCKS.put("water_4", new Block(60, -1,0,false,false,true)); //64 - BLOCKS.put("lava_16", new Block(8,false,false,true)); + BLOCKS.put("lava_16", new Block(8, -1,0,false,false,true)); //65 - BLOCKS.put("lava_12", new Block(61,false,false,true)); + BLOCKS.put("lava_12", new Block(61, -1,0,false,false,true)); //66 - BLOCKS.put("lava_8", new Block(62,false,false,true)); + BLOCKS.put("lava_8", new Block(62, -1,0,false,false,true)); //67 - BLOCKS.put("lava_4", new Block(63,false,false,true)); + BLOCKS.put("lava_4", new Block(63, -1,0,false,false,true)); //68 - BLOCKS.put("obsidian", new Block(65)); + BLOCKS.put("obsidian", new Block(65, 1500,53)); } public static void load() { diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java index 44619f0..5d2814e 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java @@ -1,29 +1,31 @@ package ru.deadsoftware.cavecraft.game.objects; -import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Rectangle; public class Block { private int x,y,w,h; private int texture; + private int hp, drop; public boolean collision, background, transparent; - public Block(int texture) { - this(0,0,16,16,texture, true, false, false); + public Block(int texture, int hp, int drop) { + this(0,0,16,16,texture, hp, drop, true, false, false); } - public Block(int texture, boolean collision, boolean background, boolean transparent) { - this(0,0,16,16,texture, collision, background, transparent); + public Block(int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) { + this(0,0,16,16,texture, hp, drop, collision, background, transparent); } - public Block(int x, int y, int w, int h, int texture, boolean collision, boolean background, boolean transparent) { + public Block(int x, int y, int w, int h, int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) { this.x = x; this.y = y; this.w = w; this.h = h; this.texture = texture; + this.hp = hp; + this.drop = drop; this.collision = collision; this.background = background; this.transparent = transparent; @@ -33,6 +35,14 @@ public class Block { return texture; } + public int getHp() { + return hp; + } + + public int getDrop() { + return drop; + } + public Rectangle getRect(int x, int y) { x*=16; y*=16; diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java new file mode 100644 index 0000000..5ff36e4 --- /dev/null +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java @@ -0,0 +1,35 @@ +package ru.deadsoftware.cavecraft.game.objects; + +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; + +import java.io.Serializable; + +public class Drop implements Serializable { + private int id; + public Vector2 move, position; + + public static void pickUpDrop(Player pl, int id) { + for (int i = 0; i < pl.inventory.length; i++) { + if (pl.inventory[i] == 0) { + pl.inventory[i] = id; + break; + } + } + } + + public Drop(float x, float y, int id) { + this.id = id; + position = new Vector2(x, y); + move = new Vector2(0, -1); + } + + public int getId() { + return id; + } + + public Rectangle getRect() { + return new Rectangle(position.x, position.y, 8, 8); + } + +} diff --git a/core/src/ru/deadsoftware/cavecraft/misc/Assets.java b/core/src/ru/deadsoftware/cavecraft/misc/Assets.java index 14575a3..e28c322 100644 --- a/core/src/ru/deadsoftware/cavecraft/misc/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/misc/Assets.java @@ -11,7 +11,7 @@ import ru.deadsoftware.cavecraft.CaveGame; public class Assets { public static final int BLOCK_TEXTURES = 66; - public static final int ITEM_TEXTURES = 5; + public static final int ITEM_TEXTURES = 10; private static GlyphLayout layout; @@ -41,6 +41,9 @@ public class Assets { public static TextureRegion invBarCur; public static TextureRegion guiCur; + public static Texture wreckTexture; + public static TextureRegion[] wreck = new TextureRegion[10]; + public static Texture creativeTexture; public static TextureRegion creativeInv; public static TextureRegion creativeScroll; @@ -124,6 +127,11 @@ public class Assets { creativeScroll = new TextureRegion(creativeTexture, 3, 137, 12, 15); creativeScroll.flip(false, true); + wreckTexture = new Texture(Gdx.files.internal("break.png")); + for (int i=0; i<10; i++) { + wreck[i] = new TextureRegion(wreckTexture, 16*i, 0, 16, 16); + } + if (CaveGame.TOUCH) { touchGui = new Texture(Gdx.files.internal("touch_gui.png")); for (int i = 0; i < 4; i++) { -- 2.29.2