Hi! For you and everyone else, i wanted to explain the line loop algorithm. Finding the number of loops in a line is a huge pain, and there are so many edge cases for what counts and what doesnt.
For reference, the player is just over 80 units tall
The game records the player's position every time they've moved 20 units. At the end of the level, the loop finder is passed that list of position and scans it - checking for an intersection between line (i, i+1) and line (j, j+1). If one is found, we then check whether it should be excluded
- if the lines are parallel, there is not loop here, so it is excluded. Lines left by the character walking back and forth are generally parallel
- if the loop is too close to a previously found loop, something has probably gone wrong or the player is scribbling, so we discard the loop. This threshold is set at 100 units.
- if the loop contains too few line segments, it is discarded. for a viable loop to be found, there must be at least 10 line segments between the two intersecting lines.
This, obviously, isnt perfect. It works most of the time, but there are still a million edge cases i simply cant work out.