|
@@ -6,9 +6,13 @@ import pathgame.logging.Logger;
|
|
|
import pathgame.tilemap.Tile;
|
|
|
import pathgame.tilemap.TileMap;
|
|
|
|
|
|
+
|
|
|
+ * A container for holding everything about the player
|
|
|
+ *
|
|
|
+ * @author julia
|
|
|
+ */
|
|
|
public class Player
|
|
|
{
|
|
|
-
|
|
|
private static final float SPEED = 0.25f;
|
|
|
|
|
|
private PlayerAbilities abilities = PlayerAbilities.NORMAL;
|
|
@@ -32,25 +36,49 @@ public class Player
|
|
|
private final LinkedList<MinusStepsValues> steps = new LinkedList<>();
|
|
|
private Tile currentTile;
|
|
|
|
|
|
+
|
|
|
+ * Constructor of the player
|
|
|
+ *
|
|
|
+ */
|
|
|
public Player()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns x-position of the player of the last frame
|
|
|
+ *
|
|
|
+ * @return x-position of the player of the last frame
|
|
|
+ */
|
|
|
public float getLastX()
|
|
|
{
|
|
|
return lastX;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns y-position of the player of the last frame
|
|
|
+ *
|
|
|
+ * @return y-position of the player of the last frame
|
|
|
+ */
|
|
|
public float getLastY()
|
|
|
{
|
|
|
return lastY;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns current x-position of the player
|
|
|
+ *
|
|
|
+ * @return current x-position of the player
|
|
|
+ */
|
|
|
public float getX()
|
|
|
{
|
|
|
return x;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns current y-position of the player
|
|
|
+ *
|
|
|
+ * @return current y-position of the player
|
|
|
+ */
|
|
|
public float getY()
|
|
|
{
|
|
|
return y;
|
|
@@ -69,6 +97,11 @@ public class Player
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Recalculates the player position every gametick based on user input
|
|
|
+ *
|
|
|
+ * @param map the current map
|
|
|
+ */
|
|
|
public void tick(TileMap map)
|
|
|
{
|
|
|
tickSteps();
|
|
@@ -172,92 +205,185 @@ public class Player
|
|
|
return Math.abs(x - Math.round(x)) < 0.01f && Math.abs(y - Math.round(y)) < 0.01f;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the current x-velocity of the player
|
|
|
+ *
|
|
|
+ * @return the current x-velocity of the player
|
|
|
+ */
|
|
|
public float getVelX()
|
|
|
{
|
|
|
return velX;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the current y-velocity of the player
|
|
|
+ *
|
|
|
+ * @return the current y-velocity of the player
|
|
|
+ */
|
|
|
public float getVelY()
|
|
|
{
|
|
|
return velY;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the overall energy supply of the player for the current map
|
|
|
+ *
|
|
|
+ * @return the overall energy supply of the player for the current map
|
|
|
+ */
|
|
|
public int getEnergySupply()
|
|
|
{
|
|
|
return energySupply;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the current energy of the player that is left for the current map
|
|
|
+ *
|
|
|
+ * @return the current energy of the player that is left for the current map
|
|
|
+ */
|
|
|
public int getEnergyLeft()
|
|
|
{
|
|
|
return energySupply - energyUsed;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the energy of the player that is already used for the current map
|
|
|
+ *
|
|
|
+ * @return the energy of the player that is already used for the current map
|
|
|
+ */
|
|
|
public int getEnergyUsed()
|
|
|
{
|
|
|
return energyUsed;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the overall amount of objectives that the player has to visit
|
|
|
+ *
|
|
|
+ * @return the overall amount of objectives that the player has to visit
|
|
|
+ */
|
|
|
public int getObjectivesAmount()
|
|
|
{
|
|
|
return objectivesAmount;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets the overall amount of objectives that the player has to visit
|
|
|
+ *
|
|
|
+ * @param objectivesAmount sets the overall amount of objectives that the
|
|
|
+ * player has to visit
|
|
|
+ */
|
|
|
public void setObjectivesAmount(int objectivesAmount)
|
|
|
{
|
|
|
this.objectivesAmount = objectivesAmount;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the amount of objectives that the player has already to visited
|
|
|
+ *
|
|
|
+ * @return the amount of objectives that the player has already to visited
|
|
|
+ */
|
|
|
public int getObjectivesVisited()
|
|
|
{
|
|
|
return objectivesVisited;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Player visits a town and updates the player statistics
|
|
|
+ */
|
|
|
public void visitTown()
|
|
|
{
|
|
|
objectivesVisited++;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns a list of the last energy costs of the last steps of the player
|
|
|
+ *
|
|
|
+ * @return a list of the last energy costs of the last steps of the player
|
|
|
+ */
|
|
|
public LinkedList<MinusStepsValues> getLastSteps()
|
|
|
{
|
|
|
return steps;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets the abilities of the player
|
|
|
+ *
|
|
|
+ * @param playerAbilities sets the abilities of the player
|
|
|
+ */
|
|
|
public void setAbilities(PlayerAbilities playerAbilities)
|
|
|
{
|
|
|
abilities = playerAbilities;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the abilities of the player
|
|
|
+ *
|
|
|
+ * @return the abilities of the player
|
|
|
+ */
|
|
|
public PlayerAbilities getAbilities()
|
|
|
{
|
|
|
return abilities;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets the overall energy supply for the player for the current map
|
|
|
+ *
|
|
|
+ * @param energySupply sets the overall energy supply for the player for the
|
|
|
+ * current map
|
|
|
+ */
|
|
|
public void setEnergySupply(int energySupply)
|
|
|
{
|
|
|
this.energySupply = energySupply;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns if player has already visited all towns and is allowed win when
|
|
|
+ * going to the start field
|
|
|
+ *
|
|
|
+ * @return if player has already visited all towns and is allowed win when
|
|
|
+ * going to the start field
|
|
|
+ */
|
|
|
public boolean canWin()
|
|
|
{
|
|
|
return objectivesVisited >= objectivesAmount;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ * Returns if player has already won the current map
|
|
|
+ *
|
|
|
+ * @return if player has already won the current map
|
|
|
+ */
|
|
|
public boolean hasWon()
|
|
|
{
|
|
|
return hasWon;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Player wins and updates the player statistics
|
|
|
+ */
|
|
|
public void win(TileMap map)
|
|
|
{
|
|
|
this.hasWon = true;
|
|
|
Logger.onWin(this, map);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns if player has lost the current map
|
|
|
+ *
|
|
|
+ * @return if player has lost the current map
|
|
|
+ */
|
|
|
public boolean hasLost()
|
|
|
{
|
|
|
return energyUsed >= energySupply;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Player is resetted
|
|
|
+ *
|
|
|
+ * @param sx start x-position
|
|
|
+ * @param sy start y-position
|
|
|
+ * @param energySupply overall energy supply for current map
|
|
|
+ * @param objectivesAmount objectives amount on current map
|
|
|
+ */
|
|
|
public void reset(int sx, int sy, int energySupply, int objectivesAmount)
|
|
|
{
|
|
|
lastX = sx;
|
|
@@ -280,26 +406,51 @@ public class Player
|
|
|
this.objectivesAmount = objectivesAmount;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Player is resetted, energy supply is set to standard of 1000, objectives
|
|
|
+ * amount is set to standard of 10
|
|
|
+ *
|
|
|
+ * @param sx start x-position
|
|
|
+ * @param sy start y-position
|
|
|
+ */
|
|
|
public void reset(int sx, int sy)
|
|
|
{
|
|
|
reset(sx, sy, 1000, 10);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns if player is currently moving
|
|
|
+ *
|
|
|
+ * @return if player is currently moving
|
|
|
+ */
|
|
|
public boolean isMoving()
|
|
|
{
|
|
|
return isMoving;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Changes Player state to sailing
|
|
|
+ */
|
|
|
public void switchSailing()
|
|
|
{
|
|
|
isSailing = !isSailing;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ * Returns if player is currently sailing
|
|
|
+ *
|
|
|
+ * @return if player is currently sailing
|
|
|
+ */
|
|
|
public boolean isSailing()
|
|
|
{
|
|
|
return isSailing;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the tile the player is currently standing on
|
|
|
+ *
|
|
|
+ * @return the tile the player is currently standing on
|
|
|
+ */
|
|
|
public Tile getCurrTile()
|
|
|
{
|
|
|
return currentTile;
|