Fixing minor improvements

This commit is contained in:
Urban Modig
2025-08-21 13:50:22 +02:00
parent d06e7131ad
commit dc9dad4d9c
3 changed files with 105 additions and 68 deletions

View File

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