I am working on a collision system for a game, i am handling it with Rectangles and the intersects() function. However the collision is also happening a little too far away from where the actual collision is supposed to happen. In the picture you can see the closest i can get to the machines.
Rectangle playerBox = new Rectangle(hitboxLeft, hitboxTop, hitboxWidth, hitboxHeight);
boolean canMoveUp = true;
for(int i = 0; i < MapLoader.machineCoordinate.length; i++) {
Rectangle machineHitbox = new Rectangle(MapLoader.machineCoordinate[i][0] - offsetX, MapLoader.machineCoordinate[i][1] - offsetY, MapLoader.machineCoordinate[i][2], MapLoader.machineCoordinate[i][3]);
if(playerBox.intersects(machineHitbox)) {
canMoveUp = false;
}
}
if(canMoveUp) {
up();
movementDirection = "UP";
} else canMoveUp = true;
static int[][] machineCoordinate = {{434, 1223, 185, 95},
{434, 1423, 185, 95},
{434, 1623, 185, 95},
{434, 1823, 185, 95}};
offsetX and offsetY are basically the camera, the player is always in the center. They get substraced from the map coordinates.