Browse Source

added the move function for Ghost in GameManager class and Ghost move in random stage

remotes/origin/ghostsbehaviour
fdai2751 11 months ago
parent
commit
841238de2e
  1. 3
      src/main/java/pacmanGame/GameManager.java
  2. 6
      src/main/java/pacmanGame/Ghost.java

3
src/main/java/pacmanGame/GameManager.java

@ -33,6 +33,9 @@ public class GameManager {
visualizer.Update(); visualizer.Update();
if(time%5 == 0) { if(time%5 == 0) {
player.Move(); player.Move();
for(int i = 0; i<ghostCount; i++) {
ghosts[i].move();
}
} }
if(time == 300) { if(time == 300) {
spawnCherry(); spawnCherry();

6
src/main/java/pacmanGame/Ghost.java

@ -4,12 +4,13 @@ public class Ghost {
public Vector2 position; public Vector2 position;
public final GameManager gameManager; public final GameManager gameManager;
public final int ghostNumber; public final int ghostNumber;
public GhostBehavior behavior;
public Ghost(GameManager gameManager, int ghostNumber) { public Ghost(GameManager gameManager, int ghostNumber) {
this.gameManager = gameManager; this.gameManager = gameManager;
this.ghostNumber = ghostNumber; this.ghostNumber = ghostNumber;
this.position = new Vector2(-1, -1); this.position = new Vector2(-1, -1);
behavior = new GhostBehaviorRandom();
} }
public void setPosition(Vector2 newPosition) { public void setPosition(Vector2 newPosition) {
@ -23,4 +24,7 @@ public class Ghost {
public void spawn() { public void spawn() {
this.position = gameManager.map.ghostSpawns[ghostNumber].Clone(); this.position = gameManager.map.ghostSpawns[ghostNumber].Clone();
} }
public void move() {
move(behavior.GetDirection(this));
}
} }
Loading…
Cancel
Save