I know this has been asked for many times, but I didnt find any good answers.
So I have got some entities for my game, now what is the best way
The classic way to do this is to have a Shape boundingBox associated with each Entity and then use Slick2d's "intersects" method on the shapes:
http://www.slick2d.org/javadoc/org/newdawn/slick/geom/Shape.html#intersects(org.newdawn.slick.geom.Shape)
I believe there is a way to do per-pixel checks on sprites but the bounding box method is more efficient if you don't need pixel-level accuracy.
Some code:
In your Entity abstract class add:
private Shape boundingBox;
public Shape getBoundingBox() {
return this.boundingBox;
}
Then your intersects method is:
public boolean intersects(Entity entity) {
if (this.getBoundingBox() == null) {
return false;
}
return this.getBoundingBox().intersects(entity.getBoundingBox());
}
Then you need to set up a bounding box for each Entity that you want to check for collisions.