Move pellet eaten counters to level
This commit is contained in:
parent
f655fe2448
commit
784bcac437
@ -20,9 +20,9 @@ public class Blinky extends Ghost {
|
|||||||
protected float getNormalSpeed() {
|
protected float getNormalSpeed() {
|
||||||
int round = state.round;
|
int round = state.round;
|
||||||
if (!state.hasDied || !state.ghosts[3].inHouse) {
|
if (!state.hasDied || !state.ghosts[3].inHouse) {
|
||||||
if (state.pelletsRemaining <= RoundModifiers.getElroy2DotsLeft(round)) {
|
if (state.level.getPelletsRemaining() <= RoundModifiers.getElroy2DotsLeft(round)) {
|
||||||
return RoundModifiers.getElroy2Speed(round);
|
return RoundModifiers.getElroy2Speed(round);
|
||||||
} else if (state.pelletsRemaining <= RoundModifiers.getElroy1DotsLeft(round)) {
|
} else if (state.level.getPelletsRemaining() <= RoundModifiers.getElroy1DotsLeft(round)) {
|
||||||
return RoundModifiers.getElroy1Speed(round);
|
return RoundModifiers.getElroy1Speed(round);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,12 @@ public class Level {
|
|||||||
// Grid of tiles, [rows][columns]
|
// Grid of tiles, [rows][columns]
|
||||||
public LevelTile[][] tiles;
|
public LevelTile[][] tiles;
|
||||||
|
|
||||||
|
// Level width and height in tiles
|
||||||
public int width;
|
public int width;
|
||||||
public int height;
|
public int height;
|
||||||
|
|
||||||
|
private int pellets;
|
||||||
|
private int pelletsRemaining;
|
||||||
|
|
||||||
public Level(PacDude game, String level) {
|
public Level(PacDude game, String level) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
@ -32,6 +35,20 @@ public class Level {
|
|||||||
|
|
||||||
height = tiles.length;
|
height = tiles.length;
|
||||||
width = tiles[0].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) {
|
public LevelTile getTile(int x, int y) {
|
||||||
@ -47,6 +64,10 @@ public class Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTile(int x, int y, LevelTile tile) {
|
public void setTile(int x, int y, LevelTile tile) {
|
||||||
|
LevelTile exist = tiles[y][x];
|
||||||
|
if (exist.isPellet() && !tile.isPellet()) {
|
||||||
|
pelletsRemaining--;
|
||||||
|
}
|
||||||
tiles[y][x] = tile;
|
tiles[y][x] = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,22 @@ public enum LevelTile {
|
|||||||
;
|
;
|
||||||
|
|
||||||
public boolean isPassable() {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,6 @@ public class PlayState extends LevelState {
|
|||||||
|
|
||||||
public Random random;
|
public Random random;
|
||||||
|
|
||||||
public int pelletsRemaining;
|
|
||||||
private int pelletsEaten;
|
|
||||||
|
|
||||||
public int pelletsEatenSinceDeath;
|
public int pelletsEatenSinceDeath;
|
||||||
public boolean pelletsEatenSinceDeathCounterEnabled;
|
public boolean pelletsEatenSinceDeathCounterEnabled;
|
||||||
public boolean hasDied;
|
public boolean hasDied;
|
||||||
@ -152,7 +149,6 @@ public class PlayState extends LevelState {
|
|||||||
|
|
||||||
private void initializeLevel() {
|
private void initializeLevel() {
|
||||||
level = new Level(game,"level");
|
level = new Level(game,"level");
|
||||||
pelletsRemaining = level.getTileCount(LevelTile.PELLET) + level.getTileCount(LevelTile.POWER_PELLET);
|
|
||||||
pacman = new Pacman(this, false);
|
pacman = new Pacman(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +156,6 @@ public class PlayState extends LevelState {
|
|||||||
scatter = true;
|
scatter = true;
|
||||||
scatterChaseTransition = 0;
|
scatterChaseTransition = 0;
|
||||||
|
|
||||||
pelletsEaten = 0;
|
|
||||||
pelletsEatenSinceDeath = 0;
|
pelletsEatenSinceDeath = 0;
|
||||||
pelletsEatenSinceDeathCounterEnabled = false;
|
pelletsEatenSinceDeathCounterEnabled = false;
|
||||||
hasDied = false;
|
hasDied = false;
|
||||||
@ -336,10 +331,7 @@ public class PlayState extends LevelState {
|
|||||||
private void pelletEaten(float x, float y) {
|
private void pelletEaten(float x, float y) {
|
||||||
level.setTile(x, y, LevelTile.EMPTY);
|
level.setTile(x, y, LevelTile.EMPTY);
|
||||||
|
|
||||||
game.sound.play(pelletsEaten % 2 == 0? SoundManager.Effect.CHOMP_1 : SoundManager.Effect.CHOMP_2);
|
game.sound.play(level.getPelletsEaten() % 2 == 0? SoundManager.Effect.CHOMP_1 : SoundManager.Effect.CHOMP_2);
|
||||||
|
|
||||||
pelletsEaten++;
|
|
||||||
pelletsRemaining--;
|
|
||||||
|
|
||||||
if (pelletsEatenSinceDeathCounterEnabled) {
|
if (pelletsEatenSinceDeathCounterEnabled) {
|
||||||
// Increase global dot counter when enabled
|
// Increase global dot counter when enabled
|
||||||
@ -358,7 +350,7 @@ public class PlayState extends LevelState {
|
|||||||
|
|
||||||
secondsSinceLastDot = 0;
|
secondsSinceLastDot = 0;
|
||||||
|
|
||||||
if (pelletsRemaining == 0) {
|
if (level.getPelletsRemaining() == 0) {
|
||||||
game.sound.stopLoops();
|
game.sound.stopLoops();
|
||||||
setGameState(GameState.ROUND_WON_WAIT);
|
setGameState(GameState.ROUND_WON_WAIT);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user