I'm going to make a golfed version of this soon. Basically, the only reason this is so long is to get the graphics working, otherwise, it'd be a lot quicker. I'm making this to try a new method of calculating shadows.
...