DEADSOFTWARE

Add items
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameProc.java
index 49fe7056faf70015c50f5828e724c7374052491b..45c62b82beaac999e403bf7fe6ab41ee2407187d 100644 (file)
@@ -59,7 +59,7 @@ public class GameProc implements Serializable{
             renderer = new GameRenderer(this,480,
                     480*((float)GameScreen.getHeight()/GameScreen.getWidth()));
         }
-        maxCreativeScroll = Items.BLOCKS.size/8;
+        maxCreativeScroll = Items.ITEMS.size()/8;
         GameSaver.save(this);
     }
 
@@ -373,6 +373,13 @@ public class GameProc implements Serializable{
         }
     }
 
+    public void useItem(int x, int y, int id, boolean bg) {
+        if (Items.ITEMS.get(id).getType()==0) {
+            if (!bg) world.placeToForeground(x, y, Items.ITEMS.get(id).getBlock());
+            else world.placeToBackground(x, y,  Items.ITEMS.get(id).getBlock());
+        }
+    }
+
     public void update(float delta) {
         RUN_TIME += delta;
 
@@ -406,8 +413,7 @@ public class GameProc implements Serializable{
 
         if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) {
             if (touchDownButton== Input.Buttons.RIGHT) {
-                world.placeToBackground(cursorX, cursorY,
-                        player.inventory[invSlot]);
+                useItem(cursorX, cursorY, player.inventory[invSlot], true);
             } else if (touchDownY< Assets.invBar.getRegionHeight() &&
                     touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 &&
                     touchDownX<renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {