Hudriwudri 5 жил өмнө
parent
commit
09bbee05c8

+ 58 - 10
src/pathgame/gameplay/Player.java

@@ -1,10 +1,10 @@
 package pathgame.gameplay;
 
-import pathgame.tilemap.Tile;
 import pathgame.tilemap.TileMap;
 
 public class Player
 {
+
     private static final float SPEED = 0.125f;
 
     private float lastX = 0;
@@ -15,7 +15,8 @@ public class Player
     private float velX = 0;
     private float velY = 0;
     private boolean isMoving = false;
-    
+    private int currSpeedSlowdown = 1;
+
     private final int energySupply;
     private int energyUsed = 0;
 
@@ -46,9 +47,15 @@ public class Player
 
     public void tick(TileMap map)
     {
+        currSpeedSlowdown = map.getTile(Math.round(x), Math.round(y)).getEnergyCost();
         lastX = x;
         lastY = y;
 
+        if(velY != 0)
+        {
+            //System.out.println(velY + " " + currSpeedSlowdown + " " + y);
+        }
+
         if(isOnTile())
         {
             velX = 0.0f;
@@ -56,9 +63,9 @@ public class Player
             if(isMoving)
             {
                 //System.out.print(map.getTile((int)x,(int) y).getEnergyCost());
-                energyUsed += map.getTile((int)x,(int) y).getEnergyCost();
-                
-                System.out.print(energyUsed);
+
+                energyUsed += currSpeedSlowdown;
+                //currSpeedSlowdown = 1;
                 //TODO: +Energy
                 //Tile currTile = map.getTile((int)x,(int) y);
 
@@ -86,25 +93,66 @@ public class Player
             velY = SPEED;
             isMoving = true;
         }
-        x += velX;
-        y += velY;
+
+        float moveX = Math.abs(velX / currSpeedSlowdown);
+        float moveY = Math.abs(velY / currSpeedSlowdown);
+        if(velX < 0.0f)
+        {
+            float d = x - (float) Math.floor(x);
+            if(d < 0.01f)
+            {
+                d = 1.0f;
+            }
+            moveX = -Math.min(moveX, d);
+        }
+        else if(velX > 0.0f)
+        {
+            float d = (float) Math.ceil(x) - x;
+            if(d < 0.01f)
+            {
+                d = 1.0f;
+            }
+            moveX = Math.min(moveX, d);
+        }
+        else if(velY < 0.0f)
+        {
+            float d = y - (float) Math.floor(y);
+            if(d < 0.01f)
+            {
+                d = 1.0f;
+            }
+            moveY = -Math.min(moveY, d);
+        }
+        else if(velY > 0.0f)
+        {
+            float d = (float) Math.ceil(y) - y;
+            if(d < 0.01f)
+            {
+                d = 1.0f;
+            }
+            moveY = Math.min(moveY, d);
+        }
+
+        System.out.println(moveX);
+        x += moveX;
+        y += moveY;
     }
 
     private boolean isOnTile()
     {
         return Math.abs(x - Math.round(x)) < 0.01f && Math.abs(y - Math.round(y)) < 0.01f;
     }
-    
+
     public int getEnergySupply()
     {
         return energySupply;
     }
-    
+
     public int getEnergyLeft()
     {
         return energySupply - energyUsed;
     }
-    
+
     public int getEnergyUsed()
     {
         return energyUsed;

+ 1 - 1
src/pathgame/rendering/TileTexture.java

@@ -37,7 +37,7 @@ public class TileTexture
      * @param tMaxY the lower y coordinate in the texture atlas
      */
     public TileTexture(float tMinX, float tMinY, float tMaxX, float tMaxY)
-    {
+    {     
         this.tMinX = tMinX;
         this.tMinY = tMinY;
         this.tMaxX = tMaxX;

+ 2 - 2
src/pathgame/tilemap/Tile.java

@@ -8,7 +8,6 @@ public class Tile
 {
     private static int idCounter = 0;
     private static Tile[] tiles = new Tile[8];
-    private final int energyCost;
     
     private static int addTile(Tile t)
     {
@@ -37,6 +36,7 @@ public class Tile
     }
     
     private final int id;
+    private final int energyCost;
     
     /** Creates a new tile, which is automatically registered.
      *
@@ -56,7 +56,7 @@ public class Tile
         return id;
     }
     
-    public final int getEnergyCost()
+    public int getEnergyCost()
     {
         return energyCost;
     }