morganq/jam — pull request #3 by ingrid (2013-01-29 08:49:48+00:00)
Title: Rect collisions

Added rectangular collisions!

### New Stuff:
* jam.Rect
* jam.Rect.overlap
* Takes two sprites or lists of sprites, returns true if any are overlapping, returns false otherwise.
* jam.Rect.collide
* Takes two sprites or lists of sprites, tries to separates them and returns true if any are overlapping. If no overlapping sprites are found or it cannot successfully separate any of the overlapping sprites it returns false.
* jam.Rect.separate
* Takes two sprite and tries to separate them, return true if successful, false otherwise.

### Incidental New Stuff:
* util.js
* Currently not exposed in jam lib because it only has a coupld tiny internal functions, you can move them and delete this file if you want.
* jam.Debug
* jam.Debug.drawBox
* Right now if you want to use it you call sprite.on and draw the box for that one sprite...wasn't sure how to do it for every one...also this is the only function in the module so you might want to move it and delete the file?
* Crap in the example game.
* The test code I wrote is messy, but I figure it can be rewritten once physics and input are added. Or just delete it.

### To test:
In the example game, move about with the arrow keys and press 'o' to see the results of the overlap function, 'c' to see the results of the collide function, or 's' to see the results of the separate function (all of those print to the console). To see collide or separate in real time just add them to the update loop and then you can see the the player push around/be pushed around.