I made it instead of storing direction and length (theta & r) decompose it into its x and y components and stored those. The advantage of that is that it allows you to just add up the vectors, and the result is the combination of all of em. We then use the atan2 function to find the angle of the resulting vector. Although I did make lists for the result vector, two variables would've been fine aswell, but I realized that a bit too late. I also organized the code according to my coding standards, but the scratch editor likes to shuffle threads around a bit so it doesn't look quite as tidy as on turbowarp.
It does seem to overcorrect a bit when there's something in the way, but I didn't fix that as it may be an intended feature. Should you want to get rid of that, you should change the way you keep track of the line length as it seems to take off much more of that than the actual line. (that was quite a rambling)