Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 931 times)
0 Members and 1 Guest are viewing this topic.
Offline SHC
« Posted 2012-11-10 15:50:23 »

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.

Offline 65K
« Reply #1 - Posted 2012-11-10 16: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.



Offline 65K
« Reply #2 - Posted 2012-11-10 16: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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #3 - Posted 2012-11-10 17: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (11 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!