Rewrote collision detection to incorporate elements from Jake
Gundersen's tutorial on collisions.