Create a list of all units (you can use a struct, this is not very complicated) and use one function to iterate through all of them.

In addition to that, only do the calculations for the units where it's needed.
So don't calculate collisions for units which are not moving f.e.


POTATO-MAN saves the day! - Random