|
@@ -2,12 +2,14 @@ package pathgame.gameplay;
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
import java.util.LinkedList;
|
|
|
+import me.hammerle.snuviengine.api.KeyBinding;
|
|
|
import pathgame.tilemap.Tile;
|
|
|
import pathgame.tilemap.TileMap;
|
|
|
import pathgame.tilemap.Tiles;
|
|
|
|
|
|
public class Player
|
|
|
{
|
|
|
+
|
|
|
private static final float SPEED = 0.125f;
|
|
|
|
|
|
private PlayerAbilities abilities = PlayerAbilities.NORMAL;
|
|
@@ -21,6 +23,7 @@ public class Player
|
|
|
private float velY = 0;
|
|
|
private boolean isMoving = false;
|
|
|
private int currSpeedSlowdown = 1;
|
|
|
+ private boolean isSailing = false;
|
|
|
|
|
|
private int energySupply;
|
|
|
private int energyUsed = 0;
|
|
@@ -72,7 +75,7 @@ public class Player
|
|
|
|
|
|
int currentTileX = Math.round(x);
|
|
|
int currentTileY = Math.round(y);
|
|
|
-
|
|
|
+
|
|
|
//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);
|
|
@@ -82,13 +85,17 @@ public class Player
|
|
|
currSpeedSlowdown = currentTile.getEnergyCost(abilities);
|
|
|
lastX = x;
|
|
|
lastY = y;
|
|
|
-
|
|
|
+
|
|
|
if(isOnTile())
|
|
|
{
|
|
|
velX = 0.0f;
|
|
|
velY = 0.0f;
|
|
|
if(isMoving)
|
|
|
{
|
|
|
+ //if(currentTile == Tiles.FOREST) //TODO: check for port with onEnter() or if
|
|
|
+ {
|
|
|
+ //isSailing = !isSailing;
|
|
|
+ }
|
|
|
currentTile.onEnter(this, map, currentTileX, currentTileY);
|
|
|
steps.addLast(new MinusStepsValues(currSpeedSlowdown));
|
|
|
energyUsed += currSpeedSlowdown;
|
|
@@ -98,27 +105,48 @@ public class Player
|
|
|
|
|
|
if(Keys.LEFT_KEY.isDown() && !isMoving && x > 0 && !map.getTile(currentTileX - 1, currentTileY).isBlockingMovement())
|
|
|
{
|
|
|
- velX = -SPEED;
|
|
|
- isMoving = true;
|
|
|
- currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ if((!isSailing && map.getTile(currentTileX - 1, currentTileY) != Tiles.DEEP_WATER)
|
|
|
+ || (isSailing && (map.getTile(currentTileX - 1, currentTileY) == Tiles.SHALLOW_WATER
|
|
|
+ || map.getTile(currentTileX - 1, currentTileY) == Tiles.DEEP_WATER))) // TODO: or is port
|
|
|
+ {
|
|
|
+ velX = -SPEED;
|
|
|
+ isMoving = true;
|
|
|
+ currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ }
|
|
|
}
|
|
|
else if(Keys.RIGHT_KEY.isDown() && !isMoving && x < map.getWidth() - 1 && !map.getTile(currentTileX + 1, currentTileY).isBlockingMovement())
|
|
|
{
|
|
|
- velX = SPEED;
|
|
|
- isMoving = true;
|
|
|
- currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ if((!isSailing && map.getTile(currentTileX + 1, currentTileY) != Tiles.DEEP_WATER)
|
|
|
+ || (isSailing && (map.getTile(currentTileX + 1, currentTileY) == Tiles.SHALLOW_WATER
|
|
|
+ || map.getTile(currentTileX + 1, currentTileY) == Tiles.DEEP_WATER))) // TODO: or is port
|
|
|
+ {
|
|
|
+ velX = SPEED;
|
|
|
+ isMoving = true;
|
|
|
+ currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ }
|
|
|
}
|
|
|
else if(Keys.UP_KEY.isDown() && !isMoving && y > 0 && !map.getTile(currentTileX, currentTileY - 1).isBlockingMovement())
|
|
|
{
|
|
|
- velY = -SPEED;
|
|
|
- isMoving = true;
|
|
|
- currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ if((!isSailing && map.getTile(currentTileX, currentTileY - 1) != Tiles.DEEP_WATER)
|
|
|
+ || (isSailing && (map.getTile(currentTileX, currentTileY - 1) == Tiles.SHALLOW_WATER
|
|
|
+ || map.getTile(currentTileX, currentTileY - 1) == Tiles.DEEP_WATER))) // TODO: or is port
|
|
|
+
|
|
|
+ {
|
|
|
+ velY = -SPEED;
|
|
|
+ isMoving = true;
|
|
|
+ currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ }
|
|
|
}
|
|
|
else if(Keys.DOWN_KEY.isDown() && !isMoving && y < map.getHeight() - 1 && !map.getTile(currentTileX, currentTileY + 1).isBlockingMovement())
|
|
|
{
|
|
|
- velY = SPEED;
|
|
|
- isMoving = true;
|
|
|
- currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ if((!isSailing && map.getTile(currentTileX, currentTileY + 1) != Tiles.DEEP_WATER)
|
|
|
+ || (isSailing && (map.getTile(currentTileX, currentTileY + 1) == Tiles.SHALLOW_WATER
|
|
|
+ || map.getTile(currentTileX, currentTileY + 1) == Tiles.DEEP_WATER))) // TODO: or is port
|
|
|
+ {
|
|
|
+ velY = SPEED;
|
|
|
+ isMoving = true;
|
|
|
+ currentTile.onLeave(this, map, currentTileX, currentTileY);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
float moveX = Math.abs(velX / currSpeedSlowdown);
|
|
@@ -197,7 +225,7 @@ public class Player
|
|
|
{
|
|
|
return objectivesAmount;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void setObjectivesAmount(int objectivesAmount)
|
|
|
{
|
|
|
this.objectivesAmount = objectivesAmount;
|
|
@@ -207,7 +235,7 @@ public class Player
|
|
|
{
|
|
|
return objectivesVisited;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void visitTown()
|
|
|
{
|
|
|
objectivesVisited++;
|
|
@@ -273,7 +301,13 @@ public class Player
|
|
|
{
|
|
|
return isMoving;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public boolean isSailing()
|
|
|
+ {
|
|
|
+ return false; //TODO: delete line
|
|
|
+ //return isSailing;
|
|
|
+ }
|
|
|
+
|
|
|
public Tile getCurrTile()
|
|
|
{
|
|
|
return currentTile;
|