Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Making a perfect collision detection system  (Read 1483 times)
0 Members and 1 Guest are viewing this topic.
Offline SHC
« Posted 2012-11-10 14:50:23 »

I was learning game development by making a game engine at

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

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

Here's the quadtree class.

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

Offline 65K
« Reply #1 - Posted 2012-11-10 15:18:24 »

I'm currently using Quadtrees for the collision which still seems slow.
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.

Lethal Running - a RPG about a deadly game show held in a futuristic dysoptian society.
Offline 65K
« Reply #2 - Posted 2012-11-10 15:52:28 »

I am only moving back objects if they collide solid objects.
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 game is slow for actual use itself. I can notice a half second delay in movement.
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.

Also how could I split it?
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.

Lethal Running - a RPG about a deadly game show held in a futuristic dysoptian society.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #3 - Posted 2012-11-10 16:05:52 »

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.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

numerical (72 views)
2017-02-21 07:32:16

numerical (73 views)
2017-02-21 07:31:46

theagentd (177 views)
2017-02-18 13:42:33

theagentd (180 views)
2017-02-18 13:35:16

h.pernpeintner (1343 views)
2017-01-24 22:39:11

h.pernpeintner (1331 views)
2017-01-24 22:38:32

Galdo (1892 views)
2017-01-12 13:44:09

Archive (1981 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2518 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2310 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!