diff --git a/src/main/java/se/urmo/game/entities/PacMan.java b/src/main/java/se/urmo/game/entities/PacMan.java index 0567c77..37a18d7 100644 --- a/src/main/java/se/urmo/game/entities/PacMan.java +++ b/src/main/java/se/urmo/game/entities/PacMan.java @@ -129,4 +129,8 @@ public class PacMan { public void resetPosition() { position = startPosition; } + + public Image getLifeIcon() { + return movmentImages[0][1]; + } } diff --git a/src/main/java/se/urmo/game/state/GhostManager.java b/src/main/java/se/urmo/game/state/GhostManager.java index eda3485..8026664 100644 --- a/src/main/java/se/urmo/game/state/GhostManager.java +++ b/src/main/java/se/urmo/game/state/GhostManager.java @@ -50,8 +50,7 @@ public class GhostManager { ghosts.add(blinky); ghosts.add(new Ghost(ghostCollisionChecker, new PinkyStrategy(),new ScatterToTopLeft(), image[2])); ghosts.add(new Ghost(ghostCollisionChecker,new InkyStrategy(blinky), new ScatterToBottomRight(), image[1])); - Ghost clyde = new Ghost(ghostCollisionChecker, new ClydeStrategy(), new ScatterToBottomLeft(), image[3]); - ghosts.add(clyde); + ghosts.add(new Ghost(ghostCollisionChecker, new ClydeStrategy(), new ScatterToBottomLeft(), image[3])); setMode(GhostMode.CHASE); } @@ -68,7 +67,7 @@ public class GhostManager { public void setMode(GhostMode mode) { this.globalMode = mode; - log.debug("Mode changed to {}", globalMode); + log.info("Mode changed to {}", globalMode); for (Ghost g : ghosts) { g.setMode(mode); } diff --git a/src/main/java/se/urmo/game/state/PlayingState.java b/src/main/java/se/urmo/game/state/PlayingState.java index fde6af2..fa8a2e5 100644 --- a/src/main/java/se/urmo/game/state/PlayingState.java +++ b/src/main/java/se/urmo/game/state/PlayingState.java @@ -12,15 +12,18 @@ import se.urmo.game.util.Direction; import java.awt.*; import java.awt.event.KeyEvent; +import java.io.InputStream; public class PlayingState implements GameState { private final Game game; private final GameStateManager gameStateManager; private final GhostManager ghostManager; + private final Font arcadeFont; private PacMan pacman; @Getter private GameMap map; private int score; + private int lives = 3; public PlayingState(Game game, GameStateManager gameStateManager) { this.game = game; @@ -28,6 +31,7 @@ public class PlayingState implements GameState { this.map = new GameMap(); this.pacman = new PacMan(game, new CollisionChecker(map)); this.ghostManager = new GhostManager(new GhostCollisionChecker(map)); + this.arcadeFont = loadArcadeFont(); } @Override @@ -42,6 +46,24 @@ public class PlayingState implements GameState { map.draw(g); pacman.draw(g); ghostManager.draw(g); + drawUI(g); + } + + private void drawUI(Graphics2D g) { + g.setColor(Color.WHITE); + g.setFont(arcadeFont); + + // Score (above map, left) + g.drawString("Your Score", 48, 48); + g.drawString("" + score, 48, 72); + + // Lives (below map, left) + for (int i = 1; i < lives; i++) { + g.drawImage(pacman.getLifeIcon(), + 6 * GameMap.OFFSET_X - i * 24, + map.rows() * GameMap.MAP_TILESIZE + GameMap.OFFSET_Y, + null); + } } @Override @@ -75,10 +97,19 @@ public class PlayingState implements GameState { ghost.resetPosition(); } else { // Pac-Man loses a life - pacman.loseLife(); - pacman.resetPosition(); + lives--; + if(lives == 0)System.exit(1); + else pacman.resetPosition(); } } } } + + private Font loadArcadeFont() { + try (InputStream is = getClass().getResourceAsStream("/fonts/PressStart2P-Regular.ttf")) { + return Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(16f); + } catch (Exception e) { + return new Font("Monospaced", Font.BOLD, 16); + } + } } diff --git a/src/main/resources/fonts/PressStart2P-Regular.ttf b/src/main/resources/fonts/PressStart2P-Regular.ttf new file mode 100644 index 0000000..2442aff Binary files /dev/null and b/src/main/resources/fonts/PressStart2P-Regular.ttf differ