DEADSOFTWARE

Move items to JSON
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameProc.java
index 7364e5967c767fcb3cc9be56d27400080c95a7a5..cd957a0842583ebc6f8fc5ec87bc353a60a6abfa 100644 (file)
@@ -58,6 +58,14 @@ public class GameProc implements Serializable {
                     480 * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
         }
         maxCreativeScroll = GameItems.getItemsSize() / 8;
+
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                while (true) fluidUpdater();
+            }
+        }).start();
+
         GameSaver.save(this);
     }
 
@@ -362,7 +370,7 @@ public class GameProc implements Serializable {
 
         if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).requiresBlock()) {
             if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).hasCollision()) {
-                world.destroyForeMap(x, y, this);
+                world.destroyForeMap(x, y);
                 updateBlock(x, y - 1);
             }
         }
@@ -375,10 +383,31 @@ public class GameProc implements Serializable {
         }
     }
 
+    private void fluidUpdater() {
+        for (int y = 0; y < world.getHeight(); y++) {
+            for (int x = (int) renderer.getCamX() / 16 - 1; x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) {
+                updateFluids(x, y);
+            }
+        }
+    }
+
     void useItem(int x, int y, int id, boolean bg) {
-        if (id > 0 && GameItems.getItem(id).getType() == 0) {
-            if (!bg) world.placeToForeground(x, y, GameItems.getItem(id).getBlock());
-            else world.placeToBackground(x, y, GameItems.getItem(id).getBlock());
+        if (id > 0) {
+            if (GameItems.getItem(id).isBlock()) {
+                if (!bg) world.placeToForeground(x, y, GameItems.getBlockIdByItemId(id));
+                else world.placeToBackground(x, y, GameItems.getBlockIdByItemId(id));
+            } else {
+                    switch (id) {
+                        case 65:
+                            world.placeToForeground(x, y, 8);
+                            player.inv[player.invSlot] = 64;
+                            break;
+                        case 66:
+                            world.placeToForeground(x, y, 9);
+                            player.inv[player.invSlot] = 64;
+                            break;
+                    }
+            }
         }
     }
 
@@ -391,12 +420,6 @@ public class GameProc implements Serializable {
             DO_UPD = false;
         }
 
-        for (int y = 0; y < world.getHeight(); y++) {
-            for (int x = (int) renderer.getCamX() / 16 - 1; x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) {
-                updateFluids(x, y);
-            }
-        }
-
         physics.update(delta);
         moveCursor();
         checkCursorBounds();
@@ -410,12 +433,12 @@ public class GameProc implements Serializable {
                     blockDmg++;
                     if (world.getForeMap(curX, curY) > 0) {
                         if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
-                            world.destroyForeMap(curX, curY, this);
+                            world.destroyForeMap(curX, curY);
                             blockDmg = 0;
                         }
                     } else if (world.getBackMap(curX, curY) > 0) {
                         if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
-                            world.destroyBackMap(curX, curY, this);
+                            world.destroyBackMap(curX, curY);
                             blockDmg = 0;
                         }
                     }