|
@@ -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;
|
|
|
+ }
|
|
|
}
|