Browse Source

Character - Swim Animation Function

Hudriwudri 5 years ago
parent
commit
cab9890a82

BIN
resources/character.png


+ 15 - 3
src/pathgame/gameplay/Player.java

@@ -4,6 +4,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import pathgame.tilemap.Tile;
 import pathgame.tilemap.TileMap;
+import pathgame.tilemap.Tiles;
 
 public class Player
 {
@@ -26,6 +27,7 @@ public class Player
     private int objectivesAmount;
     private int objectivesVisited = 0;
     private final LinkedList<MinusStepsValues> steps = new LinkedList<>();
+    private Tile currentTile;// = Tiles.GRASS;
 
     public Player()
     {
@@ -70,12 +72,17 @@ public class Player
 
         int currentTileX = Math.round(x);
         int currentTileY = Math.round(y);
-        Tile currentTile = map.getTile(currentTileX, currentTileY);
-
+        
+        //TODO: Bug beheben: Exception, wenn Spieler sofort an den unteren Levelrand geht (auch am rechten Levelrand)
+        //ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
+        //System.out.println(currentTileY);
+        //currentTile = Tiles.GRASS;
+        currentTile = map.getTile(currentTileX, currentTileY);
+        //System.out.println(currentTile);
         currSpeedSlowdown = currentTile.getEnergyCost(abilities);
         lastX = x;
         lastY = y;
-
+        
         if(isOnTile())
         {
             velX = 0.0f;
@@ -266,4 +273,9 @@ public class Player
     {
         return isMoving;
     }
+    
+    public Tile getCurrTile()
+    {
+        return currentTile;
+    }
 }

+ 17 - 1
src/pathgame/rendering/PlayerRenderer.java

@@ -4,6 +4,7 @@ import me.hammerle.snuviengine.api.Renderer;
 import me.hammerle.snuviengine.api.Texture;
 import pathgame.gameplay.Player;
 import pathgame.tilemap.TileMap;
+import pathgame.tilemap.Tiles;
 
 public class PlayerRenderer
 {
@@ -31,6 +32,8 @@ public class PlayerRenderer
         baseY = baseY - (int) baseY;
 
         int tIndex = 0;
+        float xTexOff = 0;
+        float yTexOff = 0;
 
         CHARACTER.bind();
         if(p.getVelX() > 0)
@@ -62,8 +65,21 @@ public class PlayerRenderer
             //stand still
             yIndex = 0;
         }
+        
+        
+        if(p.getCurrTile()== Tiles.DEEP_WATER) //TODO: check for shallowwater with ship port
+        {
+            yTexOff = 0.5f;
+        }
+        else if(p.getCurrTile()== Tiles.SHALLOW_WATER)
+        {
+            xTexOff = 0.5f;
+        }
+        
+        
         r.getTextureRenderer().drawRectangle(ix, iy, ix + playerSize, iy + playerSize,
-                tIndex * 0.25f, yIndex * 0.25f, (tIndex + 1) * 0.25f, yIndex * 0.25f + 0.25f);
+                tIndex * 0.125f + xTexOff, yIndex * 0.125f + yTexOff,
+                (tIndex + 1) * 0.125f + xTexOff, yIndex * 0.125f + 0.125f + yTexOff);
     }
 
     private int checkForAnimationIndex(float base)