Added most of the main loop to the Pygame implementation.