From 3c7d95299e9e3925ac0a1ebeb96ba1fd1711d500 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 18 Jan 2024 17:11:23 +0100 Subject: [PATCH] added process for player input --- src/main/java/pacmanGame/GameManager.java | 6 ++++++ src/main/java/pacmanGame/Player.java | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 40bae37..3df769f 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -24,6 +24,12 @@ public class GameManager { if(inputChar == 27) { //todo: escape key pauses game } + + else if (inputChar == 'w' || inputChar == 's' || inputChar == 'd' || inputChar == 'a') { + player.processInput(inputChar); + } + + else { System.out.println("Unprocessed Input: " + inputChar + " (" + (int)inputChar + ")"); } diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index 9e7ca7d..ae012b9 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -18,4 +18,25 @@ public class Player { position = newPosition; } } + + public void processInput(char inputchar) { + + if(inputchar == 'w') { + direction = new Vector2(0,1); + } + + else if(inputchar == 's') { + direction = new Vector2(0,-1); + } + + else if(inputchar == 'd') { + direction = new Vector2(1,0); + } + + else if(inputchar == 'a') { + direction = new Vector2(-1,0); + } + + } + }