Making a perfect collision detection system

I was learning game development by making a game engine at https://code.google.com/p/game-engine-for-java/

I want to make a perfect Map class which checks the collisions and updates all the entities. The main problem is that tilemaps wont fit for every game and I want to implement a most robust and perfect and faster implementation.

The current class is listed at https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/map/Map.java.

I’m currently using Quadtrees for the collision which still seems slow.

Here’s the quadtree class. https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/collision/QuadTree.java

What else could I do? I intend it to make it work automatically and every object is collidable.

Does it seem slow or is it too slow for an actual use case ?

Besides that, your should split up your map class because it has too many responsibilties:

  • it stores the model, map and objects
  • it loads the map
  • it renders and is bound to Java2d
  • it does collision checks
  • updates game logic

The collision check should not move back any object - that decision should be made by callers of the method.
Making the whole stuff static narrows its flexibility and usability.

That’s alright but it is not necessarily always the case.
Someone wants to use your collision detection system for his spooky ghost hunting game. As it is part of the nature of ghosts, they can pass walls. So he wants no automatic back moving, but still be notified of wall collisions to play a nice graphic effect for instance. And for the hunters, fine, move them back when colliding with walls. But the decision can not be made by the collision check.

The most efficient way to find the cause is to use a profiler. VisualVM is even free. Studying source code before that is rather a waste of time.

Just identify all various tasks like I did and create new classes for them.
A perfect collision detection system has no dependency on Java2d. It should be usable on its own without rendering stuff and the like and it should be usable in a multiplayer environment where players might hang out on different maps at the same time. Not possible when there is only one map with static attributes.
The way to load and store maps is another part that should be certainly extracted. There too many ways and flavors to do that.

The game is much faster if I use brute force collision checking.

I am not interested in multiplayer features and moreover There is an option to not revert the object position.

Also the main problem is coming with platform games which has large levels.

And though there’s only one map, the map is loaded from a mapinfo class.