Hey everyone. I’d just like a little advice on how I should do collision detection in my game. I have made a few small games in the past (simple pong game, short text adventure) but never anything really big. I decided to try my hand at making a tower defense game.
Right now I have an abstract class “Entity” which is extended by anything that needs to draw itself, so far just an enemy, a canon, and a bullet. I put all my entities in an ArrayList and loop through them to draw everything. I keep a reference to this arraylist in each entity, and when the game loop calls the updateMe() method of an entity, collision detection is done in there. So when a bullet is updated for instance, you check to see if you intersect any enemy, and if you go you kill it.
My question is if this is the best object oriented way to do this. It works fine for a small number of things, but if I decide to add more and more types of entities then things could get a little weird. Enemies for instance totally ignore all other entities and just move along their path, so there’s no reason really for them to have a reference to that array list. The only reason they do is because I built it into the super class. Only putting the array list reference in the subclasses that need it seemed redundant (maybe I am wrong about this?) I thought about writing a “CollisionDetector” class which would handle all this stuff, but again I don’t know if that is good programming practice, or if such a thing would be difficult to deal with in the future. I’d appreciate any advice Cheers.