DEADSOFTWARE

One GameProc object for everything
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / objects / Drop.java
index 478a05b5efec729cf036ebad2cffbea2771a20e0..f541daa2090b2855ec4fc102262f5944a6d9a16c 100644 (file)
@@ -7,7 +7,10 @@ import ru.deadsoftware.cavecraft.game.GameProc;
 
 import java.io.Serializable;
 
+import static ru.deadsoftware.cavecraft.GameScreen.GP;
+
 public class Drop implements Serializable {
+
     private int id;
     public boolean pickedUp = false;
     public Vector2 move, pos;
@@ -18,39 +21,39 @@ public class Drop implements Serializable {
         move = new Vector2(0, -1);
     }
 
-    public int closeToPlayer(GameProc gp) {
-        boolean c1 = Intersector.overlaps(new Rectangle(gp.player.pos.x - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
-        boolean c2 = Intersector.overlaps(new Rectangle((gp.player.pos.x + gp.world.getWidth() * 16) - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
-        boolean c3 = Intersector.overlaps(new Rectangle((gp.player.pos.x - gp.world.getWidth() * 16) - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
+    public int closeToPlayer() {
+        boolean c1 = Intersector.overlaps(new Rectangle(GP.player.pos.x - 16, GP.player.pos.y - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32), getRect());
+        boolean c2 = Intersector.overlaps(new Rectangle((GP.player.pos.x + GP.world.getWidthPx()) - 16, GP.player.pos.y - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32), getRect());
+        boolean c3 = Intersector.overlaps(new Rectangle((GP.player.pos.x - GP.world.getWidthPx()) - 16, GP.player.pos.y - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32), getRect());
         if (c1) return 1;
         if (c2) return 2;
         if (c3) return 3;
         return 0;
     }
 
-    public void moveToPlayer(GameProc gp) {
-        int ctp = closeToPlayer(gp);
+    public void moveToPlayer() {
+        int ctp = closeToPlayer();
         if (ctp > 0) {
-            float px = gp.player.pos.x + (gp.player.texWidth / 2);
-            float py = gp.player.pos.y + (gp.player.height / 2);
+            float px = GP.player.pos.x;
+            float py = GP.player.pos.y;
             switch (ctp) {
                 case 2:
-                    px += gp.world.getWidth() * 16;
+                    px += GP.world.getWidthPx();
                     break;
                 case 3:
-                    px -= gp.world.getWidth() * 16;
+                    px -= GP.world.getWidthPx();
                     break;
             }
             float dx = 0, dy = 0;
-            if (px < pos.x + 4) dx = -.5f;
+            if (px + GP.player.getWidth() < pos.x + 4) dx = -.5f;
             else if (px > pos.x + 4) dx = .5f;
-            if (py < pos.y + 4) dy = -.5f;
+            if (py + GP.player.getHeight() < pos.y + 4) dy = -.5f;
             else if (py > pos.y + 4) dy = .5f;
             move.add(dx, dy);
-//            if (move.x > 2) move.x = 2;
-//            if (move.x < -2) move.x = -2;
-//            if (move.y > 2) move.y = 2;
-//            if (move.y < -2) move.y = -2;
+            if (move.x > 2) move.x = 1;
+            if (move.x < -2) move.x = -1;
+            if (move.y > 2) move.y = 1;
+            if (move.y < -2) move.y = -1;
         }
     }