Rudimentary colisioncheck
This commit is contained in:
@ -20,6 +20,7 @@ public class PlayingState implements GameState {
|
||||
private PacMan pacman;
|
||||
@Getter
|
||||
private GameMap map;
|
||||
private int score;
|
||||
|
||||
public PlayingState(Game game, GameStateManager gameStateManager) {
|
||||
this.game = game;
|
||||
@ -33,6 +34,7 @@ public class PlayingState implements GameState {
|
||||
public void update() {
|
||||
pacman.update();
|
||||
ghostManager.update(pacman, map);
|
||||
checkCollisions();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,4 +64,21 @@ public class PlayingState implements GameState {
|
||||
pacman.setMoving(false);
|
||||
pacman.setDirection(Direction.NONE);
|
||||
}
|
||||
|
||||
private void checkCollisions() {
|
||||
for (Ghost ghost : ghostManager.getGhosts()) {
|
||||
double dist = pacman.distanceTo(ghost.getPosition());
|
||||
if (dist < GameMap.MAP_TILESIZE / 2.0) {
|
||||
if (ghost.isFrightened()) {
|
||||
// Pac-Man eats ghost
|
||||
score += 200;
|
||||
ghost.resetPosition();
|
||||
} else {
|
||||
// Pac-Man loses a life
|
||||
pacman.loseLife();
|
||||
pacman.resetPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user