DEADSOFTWARE

Refactor world generator
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / objects / Drop.java
index 3b5c76031d5a41b8a78861f48b2648441431cbcb..9e4e570396b903139e8a3d590966c7ae7dbb6ab7 100644 (file)
@@ -4,7 +4,7 @@ import com.badlogic.gdx.math.Intersector;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 
 import java.io.Serializable;
@@ -12,17 +12,17 @@ import java.io.Serializable;
 public class Drop extends Rectangle implements Serializable {
 
     private final int id;
-    private final Vector2 move;
+    private final Vector2 velocity;
     private boolean pickedUp = false;
 
     Drop(float x, float y, int id) {
         super(x, y, 8, 8);
         this.id = id;
-        this.move = new Vector2(0, -1);
+        this.velocity = new Vector2(0, -1);
     }
 
-    public Vector2 getMove() {
-        return move;
+    public Vector2 getVelocity() {
+        return velocity;
     }
 
     public int closeToPlayer(GameWorld gameWorld, Player player) {
@@ -44,7 +44,7 @@ public class Drop extends Rectangle implements Serializable {
         return 0;
     }
 
-    public void moveToPlayer(GameWorld gameWorld, Player player, int ctp) {
+    public void moveToPlayer(GameWorld gameWorld, Player player, int ctp, float delta) {
         if (ctp > 0) {
             float px = player.getX();
             float py = player.getY();
@@ -61,29 +61,29 @@ public class Drop extends Rectangle implements Serializable {
             float dx = 0, dy = 0;
 
             if (px + player.getWidth() < x + 4) {
-                dx = -.5f;
+                dx = -300f;
             } else if (px > x + 4) {
-                dx = .5f;
+                dx = 300f;
             }
 
             if (py + player.getHeight() < y + 4) {
-                dy = -.5f;
+                dy = -300f;
             } else if (py > y + 4) {
-                dy = .5f;
+                dy = .300f;
             }
 
-            move.add(dx, dy);
+            velocity.add(dx * delta, dy * delta);
 
-            if (move.x > 2) {
-                move.x = 1;
-            } else if (move.x < -2) {
-                move.x = -1;
+            if (velocity.x > 300f) {
+                velocity.x = 300f;
+            } else if (velocity.x < -300f) {
+                velocity.x = -300f;
             }
 
-            if (move.y > 2) {
-                move.y = 1;
-            } else if (move.y < -2) {
-                move.y = -1;
+            if (velocity.y > 300f) {
+                velocity.y = 300f;
+            } else if (velocity.y < -300f) {
+                velocity.y = -300f;
             }
         }
     }
@@ -106,9 +106,9 @@ public class Drop extends Rectangle implements Serializable {
 //        }
     }
 
-    public void move() {
-        x += move.x;
-        y += move.y;
+    public void move(float delta) {
+        x += velocity.x * delta;
+        y += velocity.y * delta;
         checkWorldBounds();
         y = MathUtils.round(y);
     }