In my game I have many obstacles for the player to go around, but instead it just moves right through the object. How do I make the obstacles solid and not move-through-able?


1 2 3 4 5 | public void setLocation( int x, int y) { if (getWorld().getObjectsAt(x, y, Obstacle. class ).isEmpty()) { super .setLocation(x, y); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | public void setLocation( int x, int y) { int oldX = getX(); int oldY = getY(); List<Obstacle> obstacles = getWorld().getObjects(Obstacle. class ); super .setLocation(x, y); for (Obstacle obstacle : obstacles) { if (intersects(obstacle)) { super .setLocation(oldX, oldY); break ; } } } |
1 2 3 4 5 6 7 8 9 10 | public void setLocation( int x, int y) { int oldX = getX(); int oldY = getY(); super .setLocation(x, y); if (!getIntersectingObjects(Obstacle. class ).isEmpty()) { super .setLocation(oldX, oldY); } } |
1 | setLocation(x,y); |