Refactoring to use pixel-perfect Collision check

This commit is contained in:
Urban Modig
2025-08-15 20:45:29 +02:00
parent fe2eb8cb48
commit 7bcc46122c
4 changed files with 15 additions and 13 deletions

View File

@ -16,6 +16,7 @@ public class CollisionChecker {
}
public Point getValidDestination(Direction direction, Point position, int agent_width, int agent_height) {
List<Point> list = switch (direction) {
case RIGHT -> List.of(
new Point(position.x + agent_width, position.y), // TOPRIGHT
@ -32,6 +33,8 @@ public class CollisionChecker {
default -> Collections.EMPTY_LIST;
};
System.out.println( direction + " bounderies for " + position + " are " + list);
List<Point> list2 = list.stream()
.map(p -> normalizePosition(direction, p, agent_width, agent_height))
.toList();
@ -51,9 +54,6 @@ public class CollisionChecker {
// tunnel
if (x < GameMap.OFFSET_X) x = width - agent_width - GameMap.OFFSET_X; // right
if (x >= (width - GameMap.OFFSET_X)) x = GameMap.OFFSET_X; // left
//
// if (y < 0) y = height - 1; // optional vertical wrap
// else if (y >= height) y = 0;
return new Point(x, y);
}