From 7a402cddf970ef5efbeb195b777252d5acd66936 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 21:40:05 +0100 Subject: [PATCH] changed movement behaviour in Player --- src/main/java/pacmanGame/Player.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index b729254..0780614 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -4,6 +4,8 @@ public class Player { public Vector2 position; public Vector2 direction; public GameManager gameManager; + public Vector2 oldDirection; + public Vector2 futureDirection; public Player(GameManager gameManager) { this.gameManager = gameManager; @@ -14,23 +16,28 @@ 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); + direction = new Vector2(0,1); } else if(inputchar == 's') {