Added collision detection for screen borders.