Fixed issue with freezing ghosts
This commit is contained in:
@ -6,6 +6,12 @@ import se.urmo.game.collision.GhostCollisionChecker;
|
||||
import se.urmo.game.entities.ghost.Ghost;
|
||||
import se.urmo.game.entities.ghost.mode.GhostMode;
|
||||
import se.urmo.game.entities.ghost.strategy.BlinkyStrategy;
|
||||
import se.urmo.game.entities.ghost.strategy.ClydeStrategy;
|
||||
import se.urmo.game.entities.ghost.strategy.InkyStrategy;
|
||||
import se.urmo.game.entities.ghost.strategy.PinkyStrategy;
|
||||
import se.urmo.game.entities.ghost.strategy.ScatterToBottomLeft;
|
||||
import se.urmo.game.entities.ghost.strategy.ScatterToBottomRight;
|
||||
import se.urmo.game.entities.ghost.strategy.ScatterToTopLeft;
|
||||
import se.urmo.game.entities.ghost.strategy.ScatterToTopRight;
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.map.GameMap;
|
||||
@ -42,9 +48,9 @@ public class GhostManager {
|
||||
// Create ghosts with their strategies
|
||||
Ghost blinky = new Ghost(ghostCollisionChecker, new BlinkyStrategy(), new ScatterToTopRight(), BLINKY_ANIMATION, levelManager);
|
||||
ghosts.add(blinky);
|
||||
// ghosts.add(new Ghost(ghostCollisionChecker, new PinkyStrategy(), new ScatterToTopLeft(), PINKY_ANIMATION, levelManager));
|
||||
// ghosts.add(new Ghost(ghostCollisionChecker,new InkyStrategy(blinky), new ScatterToBottomRight(), INKY_ANIMATION, levelManager));
|
||||
// ghosts.add(new Ghost(ghostCollisionChecker, new ClydeStrategy(), new ScatterToBottomLeft(), CLYDE_ANIMATION, levelManager));
|
||||
ghosts.add(new Ghost(ghostCollisionChecker, new PinkyStrategy(), new ScatterToTopLeft(), PINKY_ANIMATION, levelManager));
|
||||
ghosts.add(new Ghost(ghostCollisionChecker, new InkyStrategy(blinky), new ScatterToBottomRight(), INKY_ANIMATION, levelManager));
|
||||
ghosts.add(new Ghost(ghostCollisionChecker, new ClydeStrategy(), new ScatterToBottomLeft(), CLYDE_ANIMATION, levelManager));
|
||||
|
||||
ghosts.forEach(animationManager::register);
|
||||
|
||||
@ -58,7 +64,6 @@ public class GhostManager {
|
||||
}
|
||||
|
||||
public void update(PacMan pacman, GameMap map) {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (phaseIndex < cycleDurations.length) {
|
||||
int duration = cycleDurations[phaseIndex];
|
||||
|
||||
@ -72,6 +72,7 @@ public class PlayingState implements GameState {
|
||||
case READY -> {
|
||||
// Freeze everything during READY
|
||||
if (phaseElapsed() >= READY_MS) {
|
||||
ghostManager.setMode(GhostMode.CHASE);
|
||||
setPhase(RoundPhase.PLAYING);
|
||||
}
|
||||
}
|
||||
@ -95,7 +96,7 @@ public class PlayingState implements GameState {
|
||||
if (phaseElapsed() >= LIFE_LOST_MS) {
|
||||
pacman.setState(PacMan.PacmanState.ALIVE);
|
||||
deathInProgress = false;
|
||||
ghostManager.setFrozen(false);
|
||||
ghostManager.getGhosts().forEach(ghost -> ghost.requestModeChange(GhostMode.CHASE));
|
||||
setPhase(RoundPhase.READY);
|
||||
if (lives <= 0) {
|
||||
endGame();
|
||||
@ -215,11 +216,11 @@ public class PlayingState implements GameState {
|
||||
if (dist < GameMap.MAP_TILESIZE / 2.0) {
|
||||
if (ghost.isEaten()) return;
|
||||
if (ghost.isFrightened()) {
|
||||
// Pac-Man eats ghost
|
||||
log.debug("Pacman eats ghost");
|
||||
score += 200 * (1 << (ghostManager.getGhosts().size() - ghostManager.isFrightened()));
|
||||
|
||||
ghost.setMode(GhostMode.EATEN);
|
||||
} else {
|
||||
log.debug("Pacman loses a life");
|
||||
ghostManager.setFrozen(true);
|
||||
pacman.setState(PacMan.PacmanState.DYING);
|
||||
deathInProgress = true;
|
||||
|
||||
Reference in New Issue
Block a user