duke-compsci308-spring2013/vooga — pull request #30 by jackmatt16 (2013-04-23 23:08:32+00:00)
Title: Collision detector

Hi Everyone,

After realizing my team needed a Collision detector - we were just using the Rectangle's intersect method- I asked around and it seemed like there might have been some interest in a collision detector utility.

So I went ahead and created a CollisionDetector class, as well as a ShapeMeasurement class, the latter of which really just has static convenience methods to return locations of specific points on a given shape.

The CollisionDetector itself is fairly rudimentary, but is well commented and is quite extensible. I chose to give it non-static methods so that you (or more likely, the developer) could choose to subclass this class and rewrite any method of their choosing (or add they're own method!).

All of the methods deal strictly with Shapes, the class from which Rectangle is extended, and Locations. Therefore if you are using Rectangles, or any other Shape, for collisions, this class can be integrated very easily into your engine. I provide some convenience methods specifically assuming the objects are Rectangular, like boolean hitTop(Shape1,Shape2), which returns a boolean based on whether Shape1's top was hit by Shape2. I also provide some "precision" methods that are a bit more robust and intricate algorithm for more complicated shapes (say if you wanted to collide two ellipses).

Anyway, please someone look this over and let me know what you think!

Again, sorry that this is so late in the project. I do think it's helpful and quite easy to integrate/ extensible.

Best,
Jack