Implement ghost "eaten" behavior and refine fright mechanics

Added a new "eaten" mode for ghosts, including animations, movement strategy, and logic to reset ghosts after being eaten. Adjusted scoring for frightened ghosts using a fright multiplier and introduced enhancements like streamlined direction prioritization and position alignment. Also temporarily disabled non-essential ghosts for testing purposes.
This commit is contained in:
Urban Modig
2025-09-03 12:53:26 +02:00
parent d4b980f522
commit 11a550e997
5 changed files with 65 additions and 19 deletions

View File

@ -52,6 +52,7 @@ public class PlayingState implements GameState {
private RoundPhase phase = RoundPhase.PLAYING;
private long phaseStartMs = System.currentTimeMillis();
private boolean deathInProgress;
private int frightMultiplier;
public PlayingState(GameStateManager gameStateManager, GameOverState gameOverState) {
this.gameStateManager = gameStateManager;
@ -129,6 +130,7 @@ public class PlayingState implements GameState {
boolean wasRemoved = map.removeTileImage(pacmanScreenPos);
if (wasRemoved && tile.getTileType() == TileType.LARGE_PELLET) {
ghostManager.setFrightMode();
frightMultiplier = 1;
}
if (wasRemoved) {
dotsEaten++;
@ -211,11 +213,12 @@ public class PlayingState implements GameState {
//if(overlap(pacman, ghost)
double dist = pacman.distanceTo(ghost.getPosition());
if (dist < GameMap.MAP_TILESIZE / 2.0) {
if (ghost.isEaten()) return;
if (ghost.isFrightened()) {
// Pac-Man eats ghost
score += 200;
ghost.resetPosition();
ghost.setMode(GhostMode.CHASE); // end frightend
score += 200 * (1 << (ghostManager.getGhosts().size() - ghostManager.isFrightened()));
ghost.setMode(GhostMode.EATEN);
} else {
ghostManager.setFrozen(true);
pacman.startDeathAnimation();