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