Initial commit

This commit is contained in:
Urban Modig
2025-08-10 17:01:15 +02:00
commit 5ffb77dd00
29 changed files with 736 additions and 0 deletions

View File

@ -0,0 +1,39 @@
package se.urmo.game.state;
import se.urmo.game.GameMap;
public class CollisionChecker {
private GameMap map;
public CollisionChecker(GameMap map) {
this.map = map;
}
public boolean canMoveTo(int dir, int objectLeft, int objectTop, int width, int height) {
int objectRight = objectLeft + width;
int objectBotton = objectTop + height;
return switch (dir){
case 0 -> isPassibleRight(objectRight, objectTop, objectBotton);// right
case 1 -> isPassibleLeft(objectLeft, objectTop, objectBotton);// right
case 2 -> isPassibleBottom(objectLeft, objectRight, objectBotton);
case 3 -> isPassibleTop(objectLeft, objectRight, objectTop);// right
default -> throw new IllegalArgumentException("Invalid dir: " + dir);
};
}
private boolean isPassibleBottom(int objectLeft, int objectRight, int objectBotton) {
return map.isPassable(objectLeft, objectBotton) && map.isPassable(objectRight, objectBotton);
}
private boolean isPassibleTop(int objectLeft, int objectRight, int objectTop) {
return map.isPassable(objectLeft, objectTop) && map.isPassable(objectRight, objectTop);
}
private boolean isPassibleLeft(int objectLeft, int objectTop, int objectBotton) {
return map.isPassable(objectLeft, objectTop) && map.isPassable(objectLeft, objectBotton);
}
private boolean isPassibleRight(int objectRight, int objectTop, int objectBotton) {
return map.isPassable(objectRight, objectTop) && map.isPassable(objectRight, objectBotton);
}
}