Browse Source

added checkInput function to Player

remotes/origin/player
fdai7910 11 months ago
parent
commit
9a31f0960b
  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 position;
public Vector2 direction; public Vector2 direction;
public GameManager gameManager; public GameManager gameManager;
public Vector2 savedDirection;
public Player(GameManager gameManager) { public Player(GameManager gameManager) {
this.gameManager = gameManager; this.gameManager = gameManager;
@ -23,6 +24,9 @@ public class Player {
if(!newPosIsWall) { if(!newPosIsWall) {
position = newPosition; position = newPosition;
} }
if(savedDirection != null) {
checkInput(savedDirection);
}
gameManager.updatePlayerCell(); gameManager.updatePlayerCell();
} }
@ -52,6 +56,10 @@ public class Player {
boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall"); boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall");
if(!newPosIsWall) { if(!newPosIsWall) {
direction = input; direction = input;
savedDirection = null;
}
else {
savedDirection = input;
} }
} }

Loading…
Cancel
Save