DEADSOFTWARE

Better spawn point pick
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameWorld.java
index faf0322ed38491d995f717417069d4f46a291722..97d05cb2d41f5767cd88482f27c238453da61f41 100644 (file)
@@ -1,6 +1,8 @@
 package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.Items;
 
 public class GameWorld {
 
@@ -66,7 +68,28 @@ public class GameWorld {
     }
 
     public void placeToBackground(int x, int y, int value) {
-        if (getBackMap(x,y) == 0 || value == 0) setBackMap(x,y,value);
+        if (value==0 || (getBackMap(x,y) == 0 && !Items.BLOCKS.getValueAt(value).foreground))
+               setBackMap(x,y,value);
+    }
+
+    public Vector2 getSpawnPoint() {
+        float x=0, y=0;
+        boolean found = false;
+        x = getWidth()/2;
+        while (!found) {
+            for (int i = 0; i < getHeight(); i++) {
+                if (getForeMap((int)x, i)>0 &&
+                        Items.BLOCKS.getValueAt(getForeMap((int)x, i)).collision) {
+                    y = i-3;
+                    found = true;
+                    break;
+                }
+            }
+            if (!found) x--;
+        }
+        x = x*16 + 4;
+        y *= 16;
+        return new Vector2(x,y);
     }
 
 }