DEADSOFTWARE

Better spawn point pick
authorfred-boy <fred-boy@protonmail.com>
Thu, 12 Apr 2018 15:57:28 +0000 (22:57 +0700)
committerfred-boy <fred-boy@protonmail.com>
Thu, 12 Apr 2018 15:57:28 +0000 (22:57 +0700)
core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
core/src/ru/deadsoftware/cavecraft/game/objects/Player.java

index 102a0f7b003f79471cca77e2dc3c65778debe6a3..0b714ddd43eda90fa210a60108f592d79ece325e 100644 (file)
@@ -2,6 +2,7 @@ package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.utils.TimeUtils;
+import ru.deadsoftware.cavecraft.GameScreen;
 
 public class GameInputHandler {
 
index 8b79fe0116273791655bac30dc245e82c962371e..e461a9399381d38c59b31dfcf518b6cba66176da 100644 (file)
@@ -91,7 +91,9 @@ public class GamePhysics {
                 while (checkColl(pl.getRect())) pl.position.x += d;
             }
         }
-
+        if (pl.position.y > gameProc.world.getHeight()*16) {
+            pl.position = gameProc.world.getSpawnPoint().cpy();
+        }
         /*if (checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && !pl.moveX.equals(Vector2.Zero)) {
             pl.moveY.add(0, -8);
             pl.canJump = false;
index b955d2309d24cbc6d76158e38811f78e8b9846e6..0e3993d8a4caf0018cd28e9e5e5279d1e8ad3b74 100644 (file)
@@ -31,7 +31,7 @@ public class GameProc {
         world = new GameWorld(4096,256);
         renderer = new GameRenderer(this);
         physics = new GamePhysics(this);
-        player = new Player(world.getWidth()/2*16+4, 0);
+        player = new Player(world.getSpawnPoint());
         mobs = new Array<Mob>();
 
     }
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);
+    }
+
 }
index bcebde6f3d6198ae7ecba5185c4d3ff445ccabe6..92c81716c3b13c1007e2b3758ae342f5aa3fb82d 100644 (file)
@@ -15,8 +15,8 @@ public class Player {
     public int[] inventory;
     public boolean flyMode = false;
 
-    public Player(int x, int y) {
-        position = new Vector2(x, y);
+    public Player(Vector2 spawnPoint) {
+        position = spawnPoint.cpy();
         moveX = new Vector2(0, 0);
         moveY = new Vector2(0, 0);
         width = 4;