diff --git a/core/src/com/me/pacman/entity/Blinky.java b/core/src/com/me/pacman/entity/Blinky.java index efa0456..1e20912 100644 --- a/core/src/com/me/pacman/entity/Blinky.java +++ b/core/src/com/me/pacman/entity/Blinky.java @@ -20,9 +20,9 @@ public class Blinky extends Ghost { protected float getNormalSpeed() { int round = state.round; if (!state.hasDied || !state.ghosts[3].inHouse) { - if (state.pelletsRemaining <= RoundModifiers.getElroy2DotsLeft(round)) { + if (state.level.getPelletsRemaining() <= RoundModifiers.getElroy2DotsLeft(round)) { return RoundModifiers.getElroy2Speed(round); - } else if (state.pelletsRemaining <= RoundModifiers.getElroy1DotsLeft(round)) { + } else if (state.level.getPelletsRemaining() <= RoundModifiers.getElroy1DotsLeft(round)) { return RoundModifiers.getElroy1Speed(round); } } diff --git a/core/src/com/me/pacman/level/Level.java b/core/src/com/me/pacman/level/Level.java index 3eab01e..32cbf46 100644 --- a/core/src/com/me/pacman/level/Level.java +++ b/core/src/com/me/pacman/level/Level.java @@ -16,9 +16,12 @@ public class Level { // Grid of tiles, [rows][columns] public LevelTile[][] tiles; + // Level width and height in tiles public int width; public int height; + private int pellets; + private int pelletsRemaining; public Level(PacDude game, String level) { this.game = game; @@ -32,6 +35,20 @@ public class Level { height = tiles.length; width = tiles[0].length; + + pellets = pelletsRemaining = getTileCount(LevelTile.PELLET) + getTileCount(LevelTile.POWER_PELLET); + } + + public int getPelletCount() { + return pellets; + } + + public int getPelletsRemaining() { + return pelletsRemaining; + } + + public int getPelletsEaten() { + return pellets - pelletsRemaining; } public LevelTile getTile(int x, int y) { @@ -47,6 +64,10 @@ public class Level { } public void setTile(int x, int y, LevelTile tile) { + LevelTile exist = tiles[y][x]; + if (exist.isPellet() && !tile.isPellet()) { + pelletsRemaining--; + } tiles[y][x] = tile; } diff --git a/core/src/com/me/pacman/level/LevelTile.java b/core/src/com/me/pacman/level/LevelTile.java index 3bfa9aa..0fbef03 100644 --- a/core/src/com/me/pacman/level/LevelTile.java +++ b/core/src/com/me/pacman/level/LevelTile.java @@ -13,7 +13,22 @@ public enum LevelTile { ; public boolean isPassable() { - return this != WALL && this != GHOST_CHAMBER && this != GHOST_GATE; + switch (this) { + case WALL: + case GHOST_CHAMBER: + case GHOST_GATE: + return false; + } + return true; + } + + public boolean isPellet() { + switch (this) { + case PELLET: + case POWER_PELLET: + return true; + } + return false; } } diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index 809a007..921ea3d 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -41,9 +41,6 @@ public class PlayState extends LevelState { public Random random; - public int pelletsRemaining; - private int pelletsEaten; - public int pelletsEatenSinceDeath; public boolean pelletsEatenSinceDeathCounterEnabled; public boolean hasDied; @@ -152,7 +149,6 @@ public class PlayState extends LevelState { private void initializeLevel() { level = new Level(game,"level"); - pelletsRemaining = level.getTileCount(LevelTile.PELLET) + level.getTileCount(LevelTile.POWER_PELLET); pacman = new Pacman(this, false); } @@ -160,7 +156,6 @@ public class PlayState extends LevelState { scatter = true; scatterChaseTransition = 0; - pelletsEaten = 0; pelletsEatenSinceDeath = 0; pelletsEatenSinceDeathCounterEnabled = false; hasDied = false; @@ -336,10 +331,7 @@ public class PlayState extends LevelState { private void pelletEaten(float x, float y) { level.setTile(x, y, LevelTile.EMPTY); - game.sound.play(pelletsEaten % 2 == 0? SoundManager.Effect.CHOMP_1 : SoundManager.Effect.CHOMP_2); - - pelletsEaten++; - pelletsRemaining--; + game.sound.play(level.getPelletsEaten() % 2 == 0? SoundManager.Effect.CHOMP_1 : SoundManager.Effect.CHOMP_2); if (pelletsEatenSinceDeathCounterEnabled) { // Increase global dot counter when enabled @@ -358,7 +350,7 @@ public class PlayState extends LevelState { secondsSinceLastDot = 0; - if (pelletsRemaining == 0) { + if (level.getPelletsRemaining() == 0) { game.sound.stopLoops(); setGameState(GameState.ROUND_WON_WAIT); }