The problem:
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 for checking collisions?
Links:
The game (finished)
Code explanation:
I've got a list of entities in my world class:
List<Entity> entities = new ArrayList<Entity>();
// The list in the World class
I update them with this code (only if inside the view range):
public void update(GameContainer gc, int delta) {
for (int i = 0; i < entities.size(); i++) {
entities.get(i).update(gc, delta);
}
}
// Update entities
So now I wanna check for collision inside the entities update method.
I tried this as my update method:
@Override
public void update(GameContainer gc, int delta) {
for (Entity entity : world.entities) {
if (intersects(entity)) {
// world.remove(this);
}
}
}
// The update method of an entitiy
And this is the current instersects method:
public boolean intersects(Entity entity) {
if (entity instanceof Player) {
// Do nothing
} else {
if (shape != null) {
return this.getShape().intersects(entity.getShape());
}
}
return false;
}
// The intersects method of the abstract Entity class
Currently the intersects method always returns true. But why?