Minor fixes

This commit is contained in:
Urban Modig
2025-08-18 12:46:09 +02:00
parent 9d06b038e0
commit e62776b616
5 changed files with 23 additions and 26 deletions

View File

@ -1,6 +1,7 @@
package se.urmo.game.collision;
import lombok.extern.slf4j.Slf4j;
import se.urmo.game.util.Direction;
import se.urmo.game.map.GameMap;
@ -8,6 +9,7 @@ import java.awt.Point;
import java.util.Collections;
import java.util.List;
@Slf4j
public class CollisionChecker {
private GameMap map;
@ -17,7 +19,7 @@ public class CollisionChecker {
public Point getValidDestination(Direction direction, Point position, int agent_width, int agent_height) {
List<Point> list = switch (direction) {
List<Point> boundaries = switch (direction) {
case RIGHT -> List.of(
new Point(position.x + agent_width, position.y), // TOPRIGHT
new Point(position.x + agent_width, position.y + agent_height)); // BOTTOMRIGHT
@ -33,13 +35,13 @@ public class CollisionChecker {
default -> Collections.EMPTY_LIST;
};
System.out.println( direction + " bounderies for " + position + " are " + list);
log.debug("{} boundaries for {} are {}", direction, position, boundaries);
List<Point> list2 = list.stream()
List<Point> normalized = boundaries.stream()
.map(p -> normalizePosition(direction, p, agent_width, agent_height))
.toList();
if (map.isPassable(list2)) {
if (map.isPassable(normalized)) {
return normalizePosition(direction, position, agent_width, agent_height);
}
return null; // Blocked