Part of it is that I am creating clusters of bubbles (one parent bubble with n child bubbles). The child bubbles all follow the parent, so far so good.
Next step is to create a random distribution of these clusters. So the clusters all need to be n pixels away from each other. My idea was to build this into the clumping algorithm. I.e. if one parent is too close to another parent, their x and y will increase/decrease with a value.
Also I am trying to let the clusters stay in the boundary of the stage. Simply by adding to the algorithm the bubbles should move n pixels to the left when they are too close to the left border of the stage (same principle for the other 3 sides).
Problem is that it kind of not works what I am trying. I extended the algorithm so far that it became a mess difficult to see what's going wrong (see attachment).
Can somebody help me with describing how I can improve the Clumping algorithm so that it meets my requirements (1. Clusters distributed randomly, 2. Stage boundary collision)? Pseudo-code is also okay