Move pellet eaten counters to level

This commit is contained in:
Matt Low 2020-01-22 03:03:05 +04:00
parent f655fe2448
commit 784bcac437
4 changed files with 41 additions and 13 deletions

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}