Browse Source

changed movement behaviour in Player

remotes/origin/player
fdai7910 11 months ago
parent
commit
fea82c0a73
  1. 8
      src/main/java/pacmanGame/Player.java

8
src/main/java/pacmanGame/Player.java

@ -4,6 +4,7 @@ public class Player {
public Vector2 position;
public Vector2 direction;
public GameManager gameManager;
public Vector2 oldDirection;
public Player(GameManager gameManager) {
this.gameManager = gameManager;
@ -14,20 +15,25 @@ public class Player {
public void Spawn() {
position = gameManager.map.playerSpawn;
direction = new Vector2(0, -1);
oldDirection = direction;
}
public void Move() {
Vector2 newPosition = position.Add(direction);
boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall");
if(!newPosIsWall) {
position = newPosition;
}
else if(oldDirection != direction) {
direction = oldDirection;
Move();
}
gameManager.updatePlayerCell();
}
public void processInput(char inputchar) {
oldDirection = direction;
if(inputchar == 'w') {
direction = new Vector2(0,1);

Loading…
Cancel
Save