By code, I have 8 feet distance from a 2 inches trap to vent. These 8 feet must be straight?
Can I change direction sideways or horizontal (sloped) to vertical and then horizontal again?
Depends on the jurisdiction. In most places 8 feet is too far from trap to vent. Better would be to route vent and waste lines from the trap separately. You can use turns and what not as needed in those lines as long as slope is maintained.