The way it works is that the left side of the sub is checked with the individual sides of the left wall, and the right side is checked with the sides of the right wall. For optimization, only the lines of the wall that are at the same Y-level as the sub are checked.
As for actually calculating collisions, i used the line collision algorithm provided by the olc utils 2d geometry library.