Fixing minor improvements
This commit is contained in:
@ -19,7 +19,6 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class Ghost {
|
||||
private static final int COLLISION_BOX_SIZE = 16;
|
||||
private static final int GHOST_SPEED = 1;
|
||||
private static final int GHOST_MOVEMENT_UPDATE_FREQUENCY = 2;
|
||||
public static final int GHOST_SIZE = 32;
|
||||
private static final int ANIMATION_UPDATE_FREQUENCY = 25;
|
||||
@ -49,8 +48,8 @@ public class Ghost {
|
||||
this.scaterStrategy = scaterStrategy;
|
||||
this.animation = animation;
|
||||
position = new Point(
|
||||
13 * GameMap.MAP_TILESIZE + (GameMap.MAP_TILESIZE / 2) + GameMap.OFFSET_X,
|
||||
4 * GameMap.MAP_TILESIZE + (GameMap.MAP_TILESIZE / 2) + GameMap.OFFSET_Y);
|
||||
13 * GameMap.MAP_TILESIZE + GameMap.OFFSET_X + (GameMap.MAP_TILESIZE / 2),
|
||||
4 * GameMap.MAP_TILESIZE + GameMap.OFFSET_Y + (GameMap.MAP_TILESIZE / 2) );
|
||||
|
||||
this.currentStrategy = chaseStrategy;
|
||||
}
|
||||
@ -86,8 +85,8 @@ public class Ghost {
|
||||
}
|
||||
|
||||
Point newPosition = new Point(
|
||||
position.x + direction.dx * GHOST_SPEED,
|
||||
position.y + direction.dy * GHOST_SPEED);
|
||||
position.x + direction.dx,
|
||||
position.y + direction.dy);
|
||||
log.debug("Next position {}", newPosition);
|
||||
|
||||
Point destination = collisionChecker.canMoveTo(direction, newPosition);
|
||||
@ -124,15 +123,15 @@ public class Ghost {
|
||||
.orElse(Integer.MAX_VALUE);
|
||||
|
||||
// Return all directions that have this priority
|
||||
List<Direction> l = options.entrySet().stream()
|
||||
List<Direction> directions = options.entrySet().stream()
|
||||
.filter(entry -> entry.getValue() == lowestPriority)
|
||||
.map(Map.Entry::getKey)
|
||||
.toList();
|
||||
|
||||
Direction best = l.getFirst();
|
||||
Direction best = directions.getFirst();
|
||||
double bestDist = Double.MAX_VALUE;
|
||||
|
||||
for (Direction d : l) {
|
||||
for (Direction d : directions) {
|
||||
int nx = position.x + d.dx * GameMap.MAP_TILESIZE;
|
||||
int ny = position.y + d.dy * GameMap.MAP_TILESIZE;
|
||||
double dist = target.distance(nx, ny);
|
||||
|
||||
@ -7,6 +7,8 @@ import java.awt.Point;
|
||||
public class ScatterToBottomRight implements GhostStrategy {
|
||||
@Override
|
||||
public Point chooseTarget(Ghost ghost, PacMan pacman, GameMap map) {
|
||||
return new Point(map.getHeight() - 1, map.getHeight() - 1);
|
||||
return new Point(
|
||||
map.rowToWorldY(map.rows() - 1),
|
||||
map.colToWorldX(map.columns() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user