DEADSOFTWARE

Better spawn point pick
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameWorld.java
index c32bbd9358f297088f28c43572154652520b919c..97d05cb2d41f5767cd88482f27c238453da61f41 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavecraft.Items;
 
 public class GameWorld {
@@ -71,4 +72,24 @@ public class GameWorld {
                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);
+    }
+
 }