Deathanimation working

This commit is contained in:
Urban Modig
2025-09-02 21:30:08 +02:00
parent 96c89b6598
commit 5ba16402e4
5 changed files with 120 additions and 30 deletions

View File

@ -88,22 +88,19 @@ public class PlayingState implements GameState {
case LIFE_LOST -> {
// Freeze, then reset round (keep dot state)
if (phaseElapsed() >= LIFE_LOST_MS) {
pacman.reset();
deathInProgress = false;
resetAfterLifeLost();
ghostManager.setFrozen(false);
setPhase(RoundPhase.READY);
if (lives <= 0) {
endGame();
}
}
pacman.update();
}
}
}
private void resetAfterLifeLost() {
pacman.reset(); // to start tile, direction stopped
ghostManager.reset(); // to house
}
private void advanceLevel() {
levelManager.nextLevel();
map.reset();
@ -142,8 +139,8 @@ public class PlayingState implements GameState {
@Override
public void render(Graphics2D g) {
map.draw(g);
pacman.draw(g);
ghostManager.draw(g);
pacman.draw(g);
fruitManager.draw(g);
drawUI(g);
@ -215,6 +212,8 @@ public class PlayingState implements GameState {
ghost.resetPosition();
ghost.setMode(GhostMode.CHASE); // end frightend
} else {
ghostManager.setFrozen(true);
pacman.startDeathAnimation();
deathInProgress = true;
// Pac-Man loses a life
lives--;