From 5adcced8fbcd722bc0da3c92900bae7c8d19667f Mon Sep 17 00:00:00 2001
From: fdai7910 <kyrill.schwarzkopf@informatik@hs-fulda.de>
Date: Mon, 5 Feb 2024 20:02:24 +0100
Subject: [PATCH] fixed spamming input into wall would make player stop in
 Player

---
 src/main/java/pacmanGame/Player.java | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java
index 40b5e70..852b90d 100644
--- a/src/main/java/pacmanGame/Player.java
+++ b/src/main/java/pacmanGame/Player.java
@@ -4,7 +4,6 @@ public class Player {
 	public Vector2 position;
 	public Vector2 direction;
 	public GameManager gameManager;
-	public Vector2 oldDirection;
 	
 	public Player(GameManager gameManager) {
 		this.gameManager = gameManager;
@@ -15,7 +14,6 @@ public class Player {
 	public void Spawn() {
 		position = gameManager.map.playerSpawn;
 		direction = new Vector2(0, -1);
-		oldDirection = direction;
 	}
 	
 	public void Move() {
@@ -25,32 +23,36 @@ public class Player {
 		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);
+			checkInput(new Vector2(0,1));
 		}
 		
 		else if(inputchar == 's') {
-			direction = new Vector2(0,-1);
+			checkInput(new Vector2(0,-1));
 		}
 		
 		else if(inputchar == 'd') {
-			direction = new Vector2(1,0);
+			checkInput(new Vector2(1,0));
 		}
 		
 		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;
+		}
+	}
+	
 }