DEADSOFTWARE

Add logic to some blocks and fluids
authorfred-boy <fred-boy@protonmail.com>
Mon, 10 Sep 2018 10:58:28 +0000 (17:58 +0700)
committerfred-boy <fred-boy@protonmail.com>
Mon, 10 Sep 2018 10:58:28 +0000 (17:58 +0700)
14 files changed:
android/assets/terrain.png
core/src/ru/deadsoftware/cavecraft/game/GameInput.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
core/src/ru/deadsoftware/cavecraft/game/Items.java
core/src/ru/deadsoftware/cavecraft/game/WorldGen.java
core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java
core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java
core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
core/src/ru/deadsoftware/cavecraft/misc/Assets.java

index 73cb45ab0f7f2f5a215e3f8d071e3a409e8ceef0..f17c02ae889fdef80eb081494919962b0f28b360 100644 (file)
Binary files a/android/assets/terrain.png and b/android/assets/terrain.png differ
index e44e0053376122e474bda26fe04002fbadea1484..d151ec6b3279ffae07fc3e1e279e72cf3bb3e0be 100644 (file)
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Input;
 import com.badlogic.gdx.utils.TimeUtils;
 import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.GameScreen;
+import ru.deadsoftware.cavecraft.game.mobs.FallingSand;
 import ru.deadsoftware.cavecraft.game.mobs.Pig;
 import ru.deadsoftware.cavecraft.misc.AppState;
 import ru.deadsoftware.cavecraft.misc.Assets;
@@ -61,7 +62,10 @@ public class GameInput {
                 break;
 
             case Input.Keys.SPACE:
-                if (gameProc.player.canJump) {
+                if (Items.isFluid(gameProc.world.getForeMap((int)(gameProc.player.position.x+gameProc.player.width/2)/16,
+                        (int)(gameProc.player.position.y+gameProc.player.height/4*3)/16))) {
+                    gameProc.swim = true;
+                } else if (gameProc.player.canJump) {
                     gameProc.player.moveY.add(0, -7);
                 } else if (!gameProc.player.flyMode) {
                     gameProc.player.flyMode = true;
@@ -102,6 +106,7 @@ public class GameInput {
 
             case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT:
                 if (gameProc.player.flyMode) gameProc.player.moveY.setZero();
+                gameProc.swim = false;
                 break;
         }
     }
@@ -118,7 +123,7 @@ public class GameInput {
     }
 
     public void touchUp(int screenX, int screenY, int button) {
-        if (gameProc.isKeyDown) {
+        if (CaveGame.TOUCH && gameProc.isKeyDown) {
             keyUp(gameProc.keyDownCode);
             gameProc.isKeyDown = false;
         }
index c335908a26b41ce274c4e72ec58f80e01f553a19..244875d9adecb9fbb33c8e2e4882982d5aa01b76 100644 (file)
@@ -1,5 +1,6 @@
 package ru.deadsoftware.cavecraft.game;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.math.Intersector;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Rectangle;
@@ -8,6 +9,8 @@ import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 
+import java.util.Iterator;
+
 public class GamePhysics {
 
     public static final int PL_SPEED = 2;
@@ -26,16 +29,17 @@ public class GamePhysics {
         switch (dir) {
             case 0:
                 bl = gameProc.world.getForeMap((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16));
-                if (checkColl(new Rectangle(rect.x-16, rect.y-18, rect.width, rect.height))) bl=0;
+                if (checkColl(new Rectangle(rect.x+rect.width/2, rect.y-18, rect.width, rect.height))) bl=0;
                 break;
             case 1:
                 bl = gameProc.world.getForeMap((int)((rect.x+rect.width+8)/16),(int)((rect.y+rect.height-8)/16));
-                if (checkColl(new Rectangle(rect.x+16, rect.y-18, rect.width, rect.height))) bl=0;
+                if (checkColl(new Rectangle(rect.x+rect.width/2, rect.y-18, rect.width, rect.height))) bl=0;
                 break;
             default:
                 bl=0;
         }
-        return (bl>0 && Items.BLOCKS.getValueAt(bl).collision);
+        return (bl>0 && Items.BLOCKS.getValueAt(bl).toJump() &&
+                (rect.y+rect.height)-Items.BLOCKS.getValueAt(bl).getRect((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16)).y>8);
     }
 
     private boolean checkColl(Rectangle rect) {
@@ -59,6 +63,10 @@ public class GamePhysics {
         return false;
     }
 
+    private int getBlock(Rectangle rect) {
+        return gameProc.world.getForeMap((int)(rect.x+rect.width/2)/16, (int)(rect.y+rect.height/8*7)/16);
+    }
+
     private void playerPhy(Player pl) {
         pl.position.add(pl.moveY);
         if (checkColl(pl.getRect())) {
@@ -74,7 +82,17 @@ public class GamePhysics {
         } else {
             pl.canJump = false;
         }
-        if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity);
+
+        if (Items.isFluid(getBlock(pl.getRect()))) {
+            if (!gameProc.swim) {
+                if (!pl.flyMode && pl.moveY.y < 9) pl.moveY.add(gravity.x / 2, gravity.y / 2);
+                if (!pl.flyMode && pl.moveY.y > 9) pl.moveY.add(0, -.9f);
+            } else {
+                pl.moveY.add(0, -.5f);
+                if (pl.moveY.y<-3) pl.moveY.y = -3;
+            }
+        } else if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity);
+
         pl.position.add(pl.moveX);
         if (checkColl(pl.getRect())) {
             if (pl.canJump && !pl.flyMode) pl.position.y-=8;
@@ -107,10 +125,21 @@ public class GamePhysics {
             mob.position.y = MathUtils.round(mob.position.y);
             while (checkColl(mob.getRect())) mob.position.y+=d;
             mob.moveY.setZero();
+            if (mob.getType() > 0) {
+                gameProc.world.setForeMap((int)mob.position.x/16, (int)mob.position.y/16, mob.getType());
+                mob.position.y = -1;
+                mob.dead = true;
+            }
         } else {
             mob.canJump = false;
         }
-        if (mob.moveY.y<18) mob.moveY.add(gravity);
+
+        if (mob.getType()==0 && Items.isFluid(getBlock(mob.getRect()))) {
+            if (mob.moveY.y > 9) mob.moveY.add(0, -.9f);
+            mob.moveY.add(0, -.5f);
+            if (mob.moveY.y<-3) mob.moveY.y = -3;
+        } else if (mob.moveY.y<18) mob.moveY.add(gravity);
+
         mob.position.add(mob.moveX);
         if (checkColl(mob.getRect())) {
             if (mob.canJump) {
@@ -142,6 +171,11 @@ public class GamePhysics {
             mob.ai();
             mobPhy(mob);
         }
+        for (Iterator<Mob> it = gameProc.mobs.iterator(); it.hasNext();) {
+            Mob m = it.next();
+            if (m.dead)
+                it.remove();
+        }
         playerPhy(gameProc.player);
 
         gameProc.renderer.camera.position.set(
index 4b841bd47af0fd7103b3ac70b50f9cd73e67adc4..5d20e621cdc981ba66b94cabae10da0eed6bfb15 100644 (file)
@@ -5,6 +5,8 @@ import com.badlogic.gdx.Input;
 import com.badlogic.gdx.utils.TimeUtils;
 import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.GameScreen;
+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.Player;
@@ -18,6 +20,10 @@ public class GameProc implements Serializable{
 
     public static double RUN_TIME = 0;
 
+    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<Mob> mobs;
@@ -31,7 +37,7 @@ public class GameProc implements Serializable{
     public int ctrlMode;
     public int creativeScroll, maxCreativeScroll;
 
-    public boolean isTouchDown, isKeyDown;
+    public boolean isTouchDown, isKeyDown, swim;
     public int touchDownX, touchDownY, keyDownCode;
     public int touchDownButton;
     public long touchDownTime;
@@ -110,9 +116,283 @@ public class GameProc implements Serializable{
         }
     }
 
+    private void updateFluids(int x, int y) {
+        if (Items.isWater(world.getForeMap(x, y)) && world.getForeMap(x, y)!=8) {
+            if ((!Items.isWater(world.getForeMap(x-1,y)) ||
+                    (Items.isWater(world.getForeMap(x,y)) && world.getForeMap(x-1, y)>=world.getForeMap(x, y))) &&
+                    (!Items.isWater(world.getForeMap(x+1,y)) ||
+                            (Items.isWater(world.getForeMap(x,y)) && world.getForeMap(x+1, y)>=world.getForeMap(x, y)))){
+                world.setForeMap(x, y, world.getForeMap(x, y)+1);
+                if (world.getForeMap(x, y)>62) world.setForeMap(x, y, 0);
+            }
+        }
+
+        if (world.getForeMap(x, y) == 8) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,8);
+                updateBlock(x, y+2);
+            } else if (Items.isLava(world.getForeMap(x, y+1))) {
+                if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4);
+                else world.setForeMap(x, y+1, 66);
+            } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                if (world.getForeMap(x+1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ||
+                        (Items.isWater(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>60)) {
+                    world.setForeMap(x+1,y,60);
+                    updateBlock(x+1, y+1);
+                } else if (Items.isLava(world.getForeMap(x+1, y))) {
+                    if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4);
+                    else world.setForeMap(x+1, y, 66);
+                } else if (world.getForeMap(x+1, y)==60 && world.getForeMap(x+2, y)==8) world.setForeMap(x+1, y, 8);
+
+                if (world.getForeMap(x-1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ||
+                        (Items.isWater(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>60)) {
+                    world.setForeMap(x-1,y,60);
+                    updateBlock(x-1, y+1);
+                } else if (Items.isLava(world.getForeMap(x-1, y))) {
+                    if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4);
+                    else world.setForeMap(x-1, y, 66);
+                } else if (world.getForeMap(x-1, y)==60 && world.getForeMap(x-2, y)==8) world.setForeMap(x-1, y, 8);
+            }
+            return;
+        }
+        if (world.getForeMap(x, y) == 60) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,8);
+                updateBlock(x, y+2);
+            } else if (Items.isLava(world.getForeMap(x, y+1))) {
+                if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4);
+                else world.setForeMap(x, y+1, 66);
+            } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                if (world.getForeMap(x+1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ||
+                        (Items.isWater(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>61)){
+                    world.setForeMap(x+1,y,61);
+                    updateBlock(x+1, y+1);
+                } else if (Items.isLava(world.getForeMap(x+1, y))) {
+                    if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4);
+                    else world.setForeMap(x+1, y, 66);
+                }
+
+                if (world.getForeMap(x-1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ||
+                        (Items.isWater(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>61)){
+                    world.setForeMap(x-1,y,61);
+                    updateBlock(x-1, y+1);
+                } else if (Items.isLava(world.getForeMap(x-1, y))) {
+                    if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4);
+                    else world.setForeMap(x-1, y, 66);
+                }
+            }
+            return;
+        }
+        if (world.getForeMap(x, y) == 61) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,8);
+                updateBlock(x, y+2);
+            } else if (Items.isLava(world.getForeMap(x, y+1))) {
+                if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4);
+                else world.setForeMap(x, y+1, 66);
+            } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                if (world.getForeMap(x+1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ){
+                    world.setForeMap(x+1,y,62);
+                    updateBlock(x+1, y+1);
+                } else if (Items.isLava(world.getForeMap(x+1, y))) {
+                    if (world.getForeMap(x+1, y)>9) world.setForeMap(x+1, y, 4);
+                    else world.setForeMap(x+1, y, 66);
+                }
+
+                if (world.getForeMap(x-1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ){
+                    world.setForeMap(x-1,y,62);
+                    updateBlock(x-1, y+1);
+                } else if (Items.isLava(world.getForeMap(x-1, y))) {
+                    if (world.getForeMap(x-1, y)>9) world.setForeMap(x-1, y, 4);
+                    else world.setForeMap(x-1, y, 66);
+                }
+            }
+            return;
+        }
+        if (world.getForeMap(x, y) == 62) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=60 && world.getForeMap(x, y+1)<=62) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,8);
+                updateBlock(x, y+2);
+            } else if (Items.isLava(world.getForeMap(x, y+1))) {
+                if (world.getForeMap(x, y+1)>9) world.setForeMap(x, y+1, 4);
+                else world.setForeMap(x, y+1, 66);
+            }
+            return;
+        }
+
+        if (Items.isLava(world.getForeMap(x, y)) && world.getForeMap(x, y)!=9) {
+            if ((!Items.isLava(world.getForeMap(x-1,y)) ||
+                    (Items.isLava(world.getForeMap(x,y)) && world.getForeMap(x-1, y)>=world.getForeMap(x, y))) &&
+                    (!Items.isLava(world.getForeMap(x+1,y)) ||
+                            (Items.isLava(world.getForeMap(x,y)) && world.getForeMap(x+1, y)>=world.getForeMap(x, y)))){
+                world.setForeMap(x, y, world.getForeMap(x, y)+1);
+                if (world.getForeMap(x, y)>65) world.setForeMap(x, y, 0);
+            }
+        }
+
+        if (world.getForeMap(x, y) == 9) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,9);
+                updateBlock(x, y+2);
+            } else if (Items.isWater(world.getForeMap(x, y+1))) {
+                world.setForeMap(x, y+1, 1);
+            } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                if (world.getForeMap(x+1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ||
+                        (Items.isLava(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>63)) {
+                    world.setForeMap(x+1,y,63);
+                    updateBlock(x+1, y+1);
+                } else if (Items.isWater(world.getForeMap(x+1, y))) {
+                    world.setForeMap(x+1, y, 1);
+                }
+
+                if (world.getForeMap(x-1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ||
+                        (Items.isLava(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>63)) {
+                    world.setForeMap(x-1,y,63);
+                    updateBlock(x-1, y+1);
+                } else if (Items.isWater(world.getForeMap(x-1, y))) {
+                    world.setForeMap(x-1, y, 1);
+                }
+            }
+            return;
+        }
+        if (world.getForeMap(x, y) == 63) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,9);
+                updateBlock(x, y+2);
+            } else if (Items.isWater(world.getForeMap(x, y+1))) {
+                world.setForeMap(x, y+1, 1);
+            } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                if (world.getForeMap(x+1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ||
+                        (Items.isLava(world.getForeMap(x+1, y)) && world.getForeMap(x+1, y)>64)){
+                    world.setForeMap(x+1,y,64);
+                    updateBlock(x+1, y+1);
+                } else if (Items.isWater(world.getForeMap(x+1, y))) {
+                    world.setForeMap(x+1, y, 1);
+                }
+
+                if (world.getForeMap(x-1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ||
+                        (Items.isLava(world.getForeMap(x-1, y)) && world.getForeMap(x-1, y)>64)){
+                    world.setForeMap(x-1,y,64);
+                    updateBlock(x-1, y+1);
+                } else if (Items.isWater(world.getForeMap(x-1, y))) {
+                    world.setForeMap(x-1, y, 1);
+                }
+            }
+            return;
+        }
+        if (world.getForeMap(x, y) == 64) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,9);
+                updateBlock(x, y+2);
+            } else if (Items.isWater(world.getForeMap(x, y+1))) {
+                world.setForeMap(x, y+1, 1);
+            } else if (Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                if (world.getForeMap(x+1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x+1, y)).collision && !Items.isFluid(world.getForeMap(x+1, y))) ){
+                    world.setForeMap(x+1,y,65);
+                    updateBlock(x+1, y+1);
+                } else if (Items.isWater(world.getForeMap(x+1, y))) {
+                    world.setForeMap(x+1, y, 1);
+                }
+
+                if (world.getForeMap(x-1, y)==0 ||
+                        (!Items.BLOCKS.getValueAt(world.getForeMap(x-1, y)).collision && !Items.isFluid(world.getForeMap(x-1, y))) ){
+                    world.setForeMap(x-1,y,65);
+                    updateBlock(x-1, y+1);
+                } else if (Items.isWater(world.getForeMap(x-1, y))) {
+                    world.setForeMap(x-1, y, 1);
+                }
+            }
+            return;
+        }
+        if (world.getForeMap(x, y) == 65) {
+            if (world.getForeMap(x, y+1)==0 || (world.getForeMap(x, y+1)>=63 && world.getForeMap(x, y+1)<=65) ||
+                    (!Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision && !Items.isFluid(world.getForeMap(x, y+1)))) {
+                world.setForeMap(x,y+1,9);
+                updateBlock(x, y+2);
+            } else if (Items.isWater(world.getForeMap(x, y+1))) {
+                world.setForeMap(x, y+1, 1);
+            }
+            return;
+        }
+    }
+
+    private void updateBlock(int x, int y) {
+        if (world.getForeMap(x, y) == 10) {
+            if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x,y+1)).collision) {
+                world.setForeMap(x, y, 0);
+                mobs.add(new FallingSand(x*16, y*16));
+                updateBlock(x, y-1);
+            }
+        }
+
+        if (world.getForeMap(x, y) == 11) {
+            if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x,y+1)).collision) {
+                world.setForeMap(x, y, 0);
+                mobs.add(new FallingGravel(x*16, y*16));
+                updateBlock(x, y-1);
+            }
+        }
+
+        if (world.getForeMap(x, y) == 59) {
+            if (world.getForeMap(x, y+1)==0 || !Items.BLOCKS.getValueAt(world.getForeMap(x, y+1)).collision) {
+                world.setForeMap(x,y,0);
+                updateBlock(x, y-1);
+            }
+        }
+
+        if (world.getForeMap(x, y) == 2) {
+            if (world.getForeMap(x, y-1)>0 && (Items.BLOCKS.getValueAt(world.getForeMap(x, y-1)).collision ||
+                    Items.isFluid(world.getForeMap(x, y-1)))) {
+                world.setForeMap(x, y, 3);
+            }
+        }
+    }
+
     public void update(float delta) {
         RUN_TIME += delta;
 
+        if (DO_UPD) {
+            for (int y=UPD_Y; y<UPD_Y+16; y++)
+                for (int x=UPD_X; x<UPD_X+16; x++) {
+                    updateBlock(x, y);
+                }
+            DO_UPD = false;
+        }
+
+        for (int y=(int)renderer.camera.position.y/16-1; y<(int)(renderer.camera.position.y+renderer.camera.viewportHeight)/16+1; y++) {
+            for (int x=(int)renderer.camera.position.x/16-1; x<(int)(renderer.camera.position.x+renderer.camera.viewportWidth)/16+1; x++) {
+                updateFluids(x, y);
+            }
+        }
+
+        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();
index 58564bf3300e5a301c7a3969a83573e81a4abf5b..fac4ba2a9f25d42c987e1c6d68e1adaa33d38562 100644 (file)
@@ -1,7 +1,9 @@
 package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
 import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.GameScreen;
index 65c9d0300f354eb94aa182de4b1635cc0eed7634..42050e2fb2d1b06f5bf5a24d888f7ef6f76e2e0b 100644 (file)
@@ -37,7 +37,7 @@ public class GameWorld {
             x = transformX(x);
             map = foreMap[x][y];
         } catch (ArrayIndexOutOfBoundsException e) {
-            Gdx.app.error("GameWorld",e.toString());
+            //Gdx.app.error("GameWorld",e.toString());
         }
         return map;
     }
@@ -47,7 +47,7 @@ public class GameWorld {
             x = transformX(x);
             foreMap[x][y] = value;
         } catch (ArrayIndexOutOfBoundsException e) {
-            Gdx.app.error("GameWorld", e.toString());
+            //Gdx.app.error("GameWorld", e.toString());
         }
     }
 
@@ -57,7 +57,7 @@ public class GameWorld {
             x = transformX(x);
             map = backMap[x][y];
         } catch (ArrayIndexOutOfBoundsException e) {
-            Gdx.app.error("GameWorld",e.toString());
+            //Gdx.app.error("GameWorld",e.toString());
         }
         return map;
     }
@@ -67,13 +67,16 @@ public class GameWorld {
             x = transformX(x);
             backMap[x][y] = value;
         } catch (ArrayIndexOutOfBoundsException e) {
-            Gdx.app.error("GameWorld", e.toString());
+            //Gdx.app.error("GameWorld", e.toString());
         }
     }
 
     public void placeToForeground(int x, int y, int value) {
-        if (getForeMap(x,y) == 0 || value == 0) {
+        if (getForeMap(x,y) == 0 || value == 0 || !Items.BLOCKS.getValueAt(getForeMap(x, y)).collision) {
             setForeMap(x, y, value);
+            GameProc.UPD_X = x-8;
+            GameProc.UPD_Y = y-8;
+            GameProc.DO_UPD = true;
         }
     }
 
index ca0c949d5acd2ac1bd33f0faf192403c4427a1dc..9987cbe080ccb1425b639b2c8239ade9ed1a1851 100644 (file)
@@ -7,67 +7,153 @@ public class Items {
 
     public static ArrayMap<String, Block> BLOCKS = new ArrayMap<String, Block>();
 
+    public static boolean isFluid(int bl) {
+        return (bl == 8 || bl == 9 || bl == 60 || bl == 61 || bl == 62 || bl == 63 || bl == 64 || bl == 65);
+    }
+
+    public static boolean isWater(int bl) {
+        return (bl == 8 || bl == 60 || bl == 61 || bl == 62);
+    }
+
+    public static boolean isLava(int bl) {
+        return (bl == 9 || bl == 63 || bl == 64 || bl == 65);
+    }
+
     public static void loadBlocks() {
+        //0
         BLOCKS.put("none", null);
+        //1
         BLOCKS.put("stone", new Block(0));
+        //2
         BLOCKS.put("grass", new Block(1));
+        //3
         BLOCKS.put("dirt", new Block(2));
+        //4
         BLOCKS.put("cobblestone", new Block(3));
+        //5
         BLOCKS.put("planks", new Block(4));
+        //6
         BLOCKS.put("sapling", new Block(5,false,false,true));
+        //7
         BLOCKS.put("bedrock", new Block(6));
+        //8
         BLOCKS.put("water", new Block(7,false,false,true));
+        //9
         BLOCKS.put("lava", new Block(8,false,false,false));
+        //10
         BLOCKS.put("sand", new Block(9));
+        //11
         BLOCKS.put("gravel", new Block(10));
+        //12
         BLOCKS.put("gold_ore", new Block(11));
+        //13
         BLOCKS.put("iron_ore", new Block(12));
+        //14
         BLOCKS.put("coal_ore", new Block(13));
+        //15
         BLOCKS.put("log", new Block(14));
+        //16
         BLOCKS.put("leaves", new Block(15));
+        //17
         BLOCKS.put("sponge", new Block(16));
+        //18
         BLOCKS.put("glass", new Block(17,true,false,true));
+        //19
         BLOCKS.put("lapis_ore", new Block(18));
+        //20
         BLOCKS.put("lapis_block", new Block(19));
+        //21
         BLOCKS.put("sandstone", new Block(20));
+        //22
         BLOCKS.put("noteblock", new Block(21));
+        //23
         BLOCKS.put("bed_l", new Block(22,false,true,true));
+        //24
         BLOCKS.put("bed_r", new Block(23, false,true, true));
+        //25
         BLOCKS.put("cobweb", new Block(24,false,false,true));
+        //26
         BLOCKS.put("tallgrass", new Block(25,false,false,true));
+        //27
         BLOCKS.put("deadbush", new Block(26,false,false,true));
+        //28
         BLOCKS.put("brick_block", new Block(27));
+        //29
         BLOCKS.put("dandelion", new Block(28,false,false,true));
+        //30
         BLOCKS.put("rose", new Block(29,false,false,true));
+        //31
         BLOCKS.put("brown_mushroom", new Block(30,false,false,true));
+        //32
         BLOCKS.put("red_mushroom", new Block(31,false,false,true));
+        //33
         BLOCKS.put("wool_while", new Block(32,true,false,false));
+        //34
         BLOCKS.put("wool_orange", new Block(33,true,false,false));
+        //35
         BLOCKS.put("wool_magenta", new Block(34,true,false,false));
+        //36
         BLOCKS.put("wool_lightblue", new Block(35,true,false,false));
+        //37
         BLOCKS.put("wool_yellow", new Block(36,true,false,false));
+        //38
         BLOCKS.put("wool_lime", new Block(37,true,false,false));
+        //39
         BLOCKS.put("wool_pink", new Block(38,true,false,false));
+        //40
         BLOCKS.put("wool_gray", new Block(39,true,false,false));
+        //41
         BLOCKS.put("wool_lightgray", new Block(40,true,false,false));
+        //42
         BLOCKS.put("wool_cyan", new Block(41,true,false,false));
+        //43
         BLOCKS.put("wool_purple", new Block(42,true,false,false));
+        //44
         BLOCKS.put("wool_blue", new Block(43,true,false,false));
+        //45
         BLOCKS.put("wool_brown", new Block(44,true,false,false));
+        //46
         BLOCKS.put("wool_green", new Block(45,true,false,false));
+        //47
         BLOCKS.put("wool_red", new Block(46,true,false,false));
+        //48
         BLOCKS.put("wool_black", new Block(47,true,false,false));
+        //49
         BLOCKS.put("gold_block", new Block(48));
+        //50
         BLOCKS.put("iron_block", new Block(49));
+        //51
         BLOCKS.put("stone_slab", new Block(0, 8, 16,8, 50, true, false, true));
+        //52
         BLOCKS.put("double_stone_slab", new Block(51));
+        //53
         BLOCKS.put("sandstone_slab", new Block(0, 8, 16,8, 52, true, false, true));
+        //54
         BLOCKS.put("wooden_slab", new Block(0, 8, 16,8, 53, true, false, true));
+        //55
         BLOCKS.put("cobblestone_slab", new Block(0, 8, 16,8, 54, true, false, true));
+        //56
         BLOCKS.put("brick_slab", new Block(0, 8, 16,8, 55, true, false, true));
-        BLOCKS.put("stonebrick", new Block(56));
-        BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 57, true, false, true));
-        BLOCKS.put("cactus", new Block(1, 0, 14, 16, 58, true, false, true));
+        //57
+        BLOCKS.put("stonebrick", new Block(64));
+        //58
+        BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 56, true, false, true));
+        //59
+        BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, true, false, true));
+        //60
+        BLOCKS.put("water_12", new Block(58,false,false,true));
+        //61
+        BLOCKS.put("water_8", new Block(59,false,false,true));
+        //62
+        BLOCKS.put("water_4", new Block(60,false,false,true));
+        //63
+        BLOCKS.put("lava_12", new Block(61,false,false,true));
+        //64
+        BLOCKS.put("lava_8", new Block(62,false,false,true));
+        //65
+        BLOCKS.put("lava_4", new Block(63,false,false,true));
+        //66
+        BLOCKS.put("obsidian", new Block(65));
     }
 
     public static void load() {
index 8c0f4ca7eec7cd7ae6d038ce688fb32872d9fc74..97b548135591e21502c7aa25cd3f2988fabc0949 100644 (file)
@@ -23,7 +23,6 @@ public class WorldGen {
         int t;
         res[0] = mid;
         for (int i=1; i<width; i++) {
-            bMap[i] = i/(width/2);
             t = rand.nextInt(7)-3;
             if (t>-3 && t<3) t=0; else t/=Math.abs(t);
             if (i>width-(max-min)) {
@@ -33,6 +32,12 @@ public class WorldGen {
             res[i] = res[i-1] + t;
             if (res[i]<min) res[i] = min;
             if (res[i]>max) res[i] = max;
+            if (i>=width/2) {
+                bMap [i] = 1;
+                if (res[i] < 60) res[i] = 60;
+            } else {
+                bMap[i] = 0;
+            }
         }
         return res;
     }
@@ -73,7 +78,7 @@ public class WorldGen {
         rand = new RandomXS128(seed);
         foreMap = new int[width][height];
         backMap = new int[width][height];
-        hMap = genLandscape(width, height/8*3, height/8, height/2);
+        hMap = genLandscape(width, height/4, height/8, height/2);
         for (int x=0; x<width; x++) {
             dirtH = 4+rand.nextInt(2);
             for (int y = height- hMap[x]; y<height; y++) {
@@ -106,18 +111,23 @@ public class WorldGen {
                     foreMap[x][y] = 1;
                     backMap[x][y] = 1;
                 } else {
-                    if (bMap[x]==0) {
-                        foreMap[x][y] = 7;
-                        backMap[x][y] = 7;
-                    }
+                    foreMap[x][y] = 7;
+                    backMap[x][y] = 7;
                 }
             }
             for (int y = height-60; y<height-1; y++) {
                 if (foreMap[x][y]==0 && bMap[x]!=1){
                     foreMap[x][y] = 8;
-                    backMap[x][y] = 8;
+                    if (bMap[x] == 0) {
+                        if (y==height-60) {
+                            backMap[x][y] = 2;
+                        } else {
+                            backMap[x][y] = 3;
+                        }
+                    }
                     if (y==height-hMap[x]-1) {
                         foreMap[x][y+1] = 3;
+                        backMap[x][y+1] = 3;
                     }
                 }
             }
@@ -143,5 +153,7 @@ public class WorldGen {
     static void clear() {
         foreMap = null;
         backMap = null;
+        hMap = null;
+        bMap = null;
     }
 }
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java
new file mode 100644 (file)
index 0000000..0cfa261
--- /dev/null
@@ -0,0 +1,45 @@
+package ru.deadsoftware.cavecraft.game.mobs;
+
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.game.Items;
+import ru.deadsoftware.cavecraft.misc.Assets;
+
+public class FallingGravel extends Mob{
+
+    public FallingGravel(int x, int y) {
+        dir = 0;
+        position = new Vector2(x, y);
+        moveX = new Vector2(0, 0);
+        moveY = new Vector2(0, 1);
+        width = 16;
+        height = 16;
+        canJump = false;
+        dead = false;
+    }
+
+    @Override
+    public void ai() {
+    }
+
+    @Override
+    public void changeDir() {
+    }
+
+    @Override
+    public void draw(SpriteBatch spriteBatch, float x, float y) {
+        spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.get("gravel").getTexture()],x, y);
+    }
+
+    @Override
+    public Rectangle getRect() {
+        return new Rectangle(position.x, position.y, width, height);
+    }
+
+    @Override
+    public int getType() {
+        return 11;
+    }
+
+}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java
new file mode 100644 (file)
index 0000000..1d6a78e
--- /dev/null
@@ -0,0 +1,46 @@
+package ru.deadsoftware.cavecraft.game.mobs;
+
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.game.GameProc;
+import ru.deadsoftware.cavecraft.game.Items;
+import ru.deadsoftware.cavecraft.misc.Assets;
+
+public class FallingSand extends Mob {
+
+    public FallingSand(int x, int y) {
+        dir = 0;
+        position = new Vector2(x, y);
+        moveX = new Vector2(0, 0);
+        moveY = new Vector2(0, 1);
+        width = 16;
+        height = 16;
+        canJump = false;
+        dead = false;
+    }
+
+    @Override
+    public void ai() {
+    }
+
+    @Override
+    public void changeDir() {
+    }
+
+    @Override
+    public void draw(SpriteBatch spriteBatch, float x, float y) {
+        spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.get("sand").getTexture()],x, y);
+    }
+
+    @Override
+    public Rectangle getRect() {
+        return new Rectangle(position.x, position.y, width, height);
+    }
+
+    @Override
+    public int getType() {
+        return 10;
+    }
+
+}
index 0b0f9b3ec5e0fcfc2ab858a6a663208876e7e625..180c4d10b1905b91028c8133a8042a1027f62b26 100644 (file)
@@ -3,6 +3,7 @@ package ru.deadsoftware.cavecraft.game.mobs;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.game.GameProc;
 import ru.deadsoftware.cavecraft.misc.Assets;
 
 import java.io.Serializable;
@@ -14,11 +15,11 @@ public abstract class Mob implements Serializable{
     public Vector2 moveX, moveY;
     public int width, height, dir, animation;
     public boolean canJump;
-    public boolean agressive;
+    public boolean dead;
 
     public abstract void ai();
     public abstract void changeDir();
     public abstract void draw(SpriteBatch spriteBatch, float x, float y);
     public abstract Rectangle getRect();
-
+    public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel
 }
index 10c4242429f221641c1e0ec501545b1311127350..44333ab18a774d572a0225d3dd3cf56de0e5380a 100644 (file)
@@ -18,7 +18,7 @@ public class Pig extends Mob{
         width = 25;
         height = 18;
         canJump = false;
-        agressive = false;
+        dead = false;
     }
 
     @Override
@@ -61,4 +61,10 @@ public class Pig extends Mob{
     public Rectangle getRect() {
         return new Rectangle(position.x, position.y, width, height);
     }
+
+    @Override
+    public int getType() {
+        return 0;
+    }
+
 }
index 4fa47369fd151f2760ea314e58e9eadb2009ec43..44619f0654f3c9e2a22adbee85e66e28037962ba 100644 (file)
@@ -39,4 +39,8 @@ public class Block {
         return new Rectangle(x+this.x, y+this.y, w, h);
     }
 
+    public boolean toJump() {
+        return (y<8 && collision);
+    }
+
 }
index 23d3ea30c2eea01cd928a0bd08177e66cc3add48..15031d08ca056e807db49c6b61c00c18c85b565b 100644 (file)
@@ -10,7 +10,7 @@ import ru.deadsoftware.cavecraft.CaveGame;
 
 public class Assets {
 
-    public static final int BLOCK_TEXTURES = 59;
+    public static final int BLOCK_TEXTURES = 66;
 
     private static GlyphLayout layout;