瀏覽代碼

animation per selected character trait, swimming / boat idle animation

Kajetan Johannes Hammerle 5 年之前
父節點
當前提交
85fe8ad671
共有 3 個文件被更改,包括 99 次插入5 次删除
  1. 21 0
      src/pathgame/gameplay/Facing.java
  2. 33 1
      src/pathgame/gameplay/Player.java
  3. 45 4
      src/pathgame/rendering/PlayerRenderer.java

+ 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.logging.Logger;
 import pathgame.tilemap.Tile;
 import pathgame.tilemap.Tile;
 import pathgame.tilemap.TileMap;
 import pathgame.tilemap.TileMap;
+import pathgame.tilemap.Tiles;
 
 
 /**
 /**
  * A container for holding everything about the player
  * A container for holding everything about the player
@@ -15,6 +16,8 @@ public class Player
 {
 {
     private static final float SPEED = 0.25f;
     private static final float SPEED = 0.25f;
 
 
+    private int ticksLived = 0;
+
     private PlayerAbilities abilities = PlayerAbilities.NORMAL;
     private PlayerAbilities abilities = PlayerAbilities.NORMAL;
 
 
     private float lastX = 0;
     private float lastX = 0;
@@ -34,7 +37,9 @@ public class Player
     private int objectivesAmount;
     private int objectivesAmount;
     private int objectivesVisited = 0;
     private int objectivesVisited = 0;
     private final LinkedList<MinusStepsValues> steps = new LinkedList<>();
     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
      * Constructor of the player
@@ -104,6 +109,7 @@ public class Player
      */
      */
     public void tick(TileMap map)
     public void tick(TileMap map)
     {
     {
+        ticksLived++;
         tickSteps();
         tickSteps();
 
 
         int currentTileX = Math.round(x);
         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))
         if(Keys.LEFT_KEY.isDown() && !isMoving && currentTileX > 0 && !map.getTile(currentTileX - 1, currentTileY).isBlockingMovement(this))
         {
         {
+            facing = Facing.WEST;
             velX = -SPEED;
             velX = -SPEED;
             isMoving = true;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
             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))
         else if(Keys.RIGHT_KEY.isDown() && !isMoving && currentTileX < map.getWidth() - 1 && !map.getTile(currentTileX + 1, currentTileY).isBlockingMovement(this))
         {
         {
+            facing = Facing.EAST;
             velX = SPEED;
             velX = SPEED;
             isMoving = true;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
             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))
         else if(Keys.UP_KEY.isDown() && !isMoving && currentTileY > 0 && !map.getTile(currentTileX, currentTileY - 1).isBlockingMovement(this))
         {
         {
+            facing = Facing.NORTH;
             velY = -SPEED;
             velY = -SPEED;
             isMoving = true;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
             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))
         else if(Keys.DOWN_KEY.isDown() && !isMoving && currentTileY < map.getHeight() - 1 && !map.getTile(currentTileX, currentTileY + 1).isBlockingMovement(this))
         {
         {
+            facing = Facing.SOUTH;
             velY = SPEED;
             velY = SPEED;
             isMoving = true;
             isMoving = true;
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
             Logger.onTileLeave(this, map, currentTileX, currentTileY);
@@ -386,6 +396,8 @@ public class Player
      */
      */
     public void reset(int sx, int sy, int energySupply, int objectivesAmount)
     public void reset(int sx, int sy, int energySupply, int objectivesAmount)
     {
     {
+        ticksLived = 0;
+
         lastX = sx;
         lastX = sx;
         lastY = sy;
         lastY = sy;
         x = sx;
         x = sx;
@@ -455,4 +467,24 @@ public class Player
     {
     {
         return currentTile;
         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.Renderer;
 import me.hammerle.snuviengine.api.Texture;
 import me.hammerle.snuviengine.api.Texture;
+import pathgame.gameplay.Facing;
 import pathgame.gameplay.Player;
 import pathgame.gameplay.Player;
+import pathgame.gameplay.PlayerAbilities;
 import pathgame.tilemap.TileMap;
 import pathgame.tilemap.TileMap;
-import pathgame.tilemap.Tiles;
+import pathgame.tilemap.TileRenderType;
 
 
 /**
 /**
  * A container for holding everything about the renderer for the player
  * A container for holding everything about the renderer for the player
@@ -14,6 +16,10 @@ import pathgame.tilemap.Tiles;
 public class PlayerRenderer
 public class PlayerRenderer
 {
 {
     private static final Texture CHARACTER = new Texture("resources/character.png");
     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
      * 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)
     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;
         float playerSize = mapR.getScale() * TileRenderer.TILE_SIZE;
 
 
         r.setMixColorEnabled(false);
         r.setMixColorEnabled(false);
@@ -52,7 +59,8 @@ public class PlayerRenderer
         float xTexOff = 0;
         float xTexOff = 0;
         float yTexOff = 0;
         float yTexOff = 0;
 
 
-        CHARACTER.bind();
+        bindTexture(p, inWater);
+        
         if(p.getVelX() > 0)
         if(p.getVelX() > 0)
         {
         {
             //go right
             //go right
@@ -80,14 +88,19 @@ public class PlayerRenderer
         else
         else
         {
         {
             //stand still
             //stand still
-            yIndex = 0;
+            yIndex = p.getFacing().getIndex();
+            // idle animation on water
+            if(inWater && (p.getTicksLived() % 20) < 10)
+            {
+                tIndex = 1;
+            }
         }
         }
 
 
         if(p.isSailing())
         if(p.isSailing())
         {
         {
             yTexOff = 0.5f;
             yTexOff = 0.5f;
         }
         }
-        else if(p.getCurrTile() == Tiles.SHALLOW_WATER)
+        else if(inWater)
         {
         {
             xTexOff = 0.5f;
             xTexOff = 0.5f;
         }
         }
@@ -105,4 +118,32 @@ public class PlayerRenderer
     {
     {
         return ((int) (base * 4 * 2)) % 4;
         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();
+        }
+    }
 }
 }