From 9ffc4af8dffa349c6319921063db0d041dcc78ab Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 02:46:18 +0100 Subject: [PATCH] added the collision function player vs Ghosts --- src/main/java/pacmanGame/GhostBehaviorRandom.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/GhostBehaviorRandom.java b/src/main/java/pacmanGame/GhostBehaviorRandom.java index d461501..a60db09 100644 --- a/src/main/java/pacmanGame/GhostBehaviorRandom.java +++ b/src/main/java/pacmanGame/GhostBehaviorRandom.java @@ -1,7 +1,9 @@ package pacmanGame; import java.util.Random; public class GhostBehaviorRandom implements GhostBehavior { - +public int player; +public int ghost; +public boolean isPlayerAlive = true; @Override public Vector2 GetDirection(Ghost ghost) { Random random = new Random(); @@ -20,5 +22,9 @@ public class GhostBehaviorRandom implements GhostBehavior { } return null; } - + public void checkCollision() { + if (player == ghost) { + isPlayerAlive = false; + } + } }