Cleanup collision code and fix bug.

Bug was due to checking gTiles[i].size() rather than gTiles.size().

Refactored a bunch of code and renamed a few to make them easier to
read.