Browse Source

animation per selected character trait, swimming / boat idle animation

Kajetan Johannes Hammerle 5 years ago
parent
commit
85fe8ad671

+ 21 - 0
src/pathgame/gameplay/Facing.java

@@ -0,0 +1,21 @@
+package pathgame.gameplay;
+
+public enum Facing
+{
+    NORTH(3), 
+    EAST(2), 
+    SOUTH(0), 
+    WEST(1);
+    
+    private final int index;
+    
+    private Facing(int index)
+    {
+        this.index = index;
+    }
+    
+    public int getIndex()
+    {
+        return index;
+    }
+}

+ 33 - 1
src/pathgame/gameplay/Player.java

@@ -5,6 +5,7 @@ import java.util.LinkedList;
 import pathgame.logging.Logger;
 import pathgame.tilemap.Tile;
 import pathgame.tilemap.TileMap;
+import pathgame.tilemap.Tiles;
 
 /**
  * A container for holding everything about the player
@@ -15,6 +16,8 @@ public class Player
 {
     private static final float SPEED = 0.25f;
 
+    private int ticksLived = 0;
+
     private PlayerAbilities abilities = PlayerAbilities.NORMAL;
 
     private float lastX = 0;
@@ -34,7 +37,9 @@ public class Player
     private int objectivesAmount;
     private int objectivesVisited = 0;
     private final LinkedList<MinusStepsValues> steps = new LinkedList<>();
-    private Tile currentTile;// = Tiles.GRASS;
+    private Tile currentTile = Tiles.HOME_TOWN;
+    
+    private Facing facing = Facing.SOUTH;
 
     /**
      * Constructor of the player
@@ -104,6 +109,7 @@ public class Player
      */
     public void tick(TileMap map)
     {
+        ticksLived++;
         tickSteps();
 
         int currentTileX = Math.round(x);
@@ -131,6 +137,7 @@ public class Player
 
         if(Keys.LEFT_KEY.isDown() && !isMoving && currentTileX > 0 && !map.getTile(currentTileX - 1, currentTileY).isBlockingMovement(this))
         {
+            facing = Facing.WEST;
             velX = -SPEED;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
@@ -138,6 +145,7 @@ public class Player
         }
         else if(Keys.RIGHT_KEY.isDown() && !isMoving && currentTileX < map.getWidth() - 1 && !map.getTile(currentTileX + 1, currentTileY).isBlockingMovement(this))
         {
+            facing = Facing.EAST;
             velX = SPEED;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
@@ -145,6 +153,7 @@ public class Player
         }
         else if(Keys.UP_KEY.isDown() && !isMoving && currentTileY > 0 && !map.getTile(currentTileX, currentTileY - 1).isBlockingMovement(this))
         {
+            facing = Facing.NORTH;
             velY = -SPEED;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
@@ -152,6 +161,7 @@ public class Player
         }
         else if(Keys.DOWN_KEY.isDown() && !isMoving && currentTileY < map.getHeight() - 1 && !map.getTile(currentTileX, currentTileY + 1).isBlockingMovement(this))
         {
+            facing = Facing.SOUTH;
             velY = SPEED;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
@@ -386,6 +396,8 @@ public class Player
      */
     public void reset(int sx, int sy, int energySupply, int objectivesAmount)
     {
+        ticksLived = 0;
+
         lastX = sx;
         lastY = sy;
         x = sx;
@@ -455,4 +467,24 @@ public class Player
     {
         return currentTile;
     }
+
+    /**
+     * Returns how much ticks this player is alive.
+     *
+     * @return how much ticks this player is alive
+     */
+    public int getTicksLived()
+    {
+        return ticksLived;
+    }
+    
+    /**
+     * Returns the direction the player is facing.
+     *
+     * @return the direction the player is facing
+     */
+    public Facing getFacing()
+    {
+        return facing;
+    }
 }

+ 45 - 4
src/pathgame/rendering/PlayerRenderer.java

@@ -2,9 +2,11 @@ package pathgame.rendering;
 
 import me.hammerle.snuviengine.api.Renderer;
 import me.hammerle.snuviengine.api.Texture;
+import pathgame.gameplay.Facing;
 import pathgame.gameplay.Player;
+import pathgame.gameplay.PlayerAbilities;
 import pathgame.tilemap.TileMap;
-import pathgame.tilemap.Tiles;
+import pathgame.tilemap.TileRenderType;
 
 /**
  * A container for holding everything about the renderer for the player
@@ -14,6 +16,10 @@ import pathgame.tilemap.Tiles;
 public class PlayerRenderer
 {
     private static final Texture CHARACTER = new Texture("resources/character.png");
+    private static final Texture CHARACTER_HIKER = new Texture("resources/hiker.png");
+    private static final Texture CHARACTER_HUNTER = new Texture("resources/hunter.png");
+    private static final Texture CHARACTER_SAILOR = new Texture("resources/sailor.png");
+    private static final Texture CHARACTER_SWIMMER = new Texture("resources/swimmer.png");
 
     /**
      * Recalculates the rendering positions and settings of the menu-elements on
@@ -29,6 +35,7 @@ public class PlayerRenderer
      */
     public void renderTick(TileMap map, TileMapRenderer mapR, Renderer r, Player p, float lag, float offX, float offY)
     {
+        boolean inWater = p.getCurrTile().getRenderType() == TileRenderType.WATER;
         float playerSize = mapR.getScale() * TileRenderer.TILE_SIZE;
 
         r.setMixColorEnabled(false);
@@ -52,7 +59,8 @@ public class PlayerRenderer
         float xTexOff = 0;
         float yTexOff = 0;
 
-        CHARACTER.bind();
+        bindTexture(p, inWater);
+        
         if(p.getVelX() > 0)
         {
             //go right
@@ -80,14 +88,19 @@ public class PlayerRenderer
         else
         {
             //stand still
-            yIndex = 0;
+            yIndex = p.getFacing().getIndex();
+            // idle animation on water
+            if(inWater && (p.getTicksLived() % 20) < 10)
+            {
+                tIndex = 1;
+            }
         }
 
         if(p.isSailing())
         {
             yTexOff = 0.5f;
         }
-        else if(p.getCurrTile() == Tiles.SHALLOW_WATER)
+        else if(inWater)
         {
             xTexOff = 0.5f;
         }
@@ -105,4 +118,32 @@ public class PlayerRenderer
     {
         return ((int) (base * 4 * 2)) % 4;
     }
+    
+    private void bindTexture(Player p, boolean inWater)
+    {
+        if(p.isSailing() || inWater || p.getAbilities() == PlayerAbilities.NORMAL)
+        {
+            CHARACTER.bind();
+        }
+        else if(p.getAbilities() == PlayerAbilities.HIKER)
+        {
+            CHARACTER_HIKER.bind();
+        }
+        else if(p.getAbilities() == PlayerAbilities.HUNTER)
+        {
+            CHARACTER_HUNTER.bind();
+        }
+        else if(p.getAbilities() == PlayerAbilities.SAILOR)
+        {
+            CHARACTER_SAILOR.bind();
+        }
+        else if(p.getAbilities() == PlayerAbilities.SWIMMER)
+        {
+            CHARACTER_SWIMMER.bind();
+        }
+        else
+        {
+            CHARACTER.bind();
+        }
+    }
 }