From 9a31f0960b6742913b72bbf1c26fac489b879923 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:09:34 +0100 Subject: [PATCH] added checkInput function to Player --- src/main/java/pacmanGame/Player.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index 852b90d..411f504 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -4,6 +4,7 @@ public class Player { public Vector2 position; public Vector2 direction; public GameManager gameManager; + public Vector2 savedDirection; public Player(GameManager gameManager) { this.gameManager = gameManager; @@ -23,6 +24,9 @@ public class Player { if(!newPosIsWall) { position = newPosition; } + if(savedDirection != null) { + checkInput(savedDirection); + } gameManager.updatePlayerCell(); } @@ -52,6 +56,10 @@ public class Player { boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall"); if(!newPosIsWall) { direction = input; + savedDirection = null; + } + else { + savedDirection = input; } }