Example #1
0
 private bool IsTooCloseToAnotherBlackhole(GravitySystem newBlackhole)
 {
     foreach (GravitySystem blackhole in _activeBlackholesGravitySystems)
     {
         if (AreTooClose(newBlackhole, blackhole))
         {
             return(true);
         }
     }
     return(false);
 }
Example #2
0
        public void FillAllSpaceWithBlackholes()
        {
            int currentAttempts = 0;

            while (currentAttempts < maxNumberOfAttempts && _activeBlackholesGravitySystems.Count < _activeBlackholesGravitySystems.Capacity)
            {
                GravitySystem newBlackhole = _blackholesPool.Get()?.GetComponent <GravitySystem>();
                if (newBlackhole == null)
                {
                    return;
                }
                if (!IsTooCloseToAnotherBlackhole(newBlackhole) && !IsInImmutableArea(newBlackhole))
                {
                    _activeBlackholesGravitySystems.Add(newBlackhole);
                    currentAttempts = 0;
                }
                else
                {
                    currentAttempts++;
                    _blackholesPool.Release(newBlackhole.gameObject);
                }
            }
        }
Example #3
0
 private bool IsInImmutableArea(GravitySystem newBlackhole) =>
 (newBlackhole.CenterOfGravity - (Vector2)_transform.position).magnitude < immutableAreaRadius;
Example #4
0
 private bool AreTooClose(GravitySystem newBlackhole, GravitySystem blackhole) =>
 (newBlackhole.InfluenceRadius + blackhole.InfluenceRadius) > (newBlackhole.CenterOfGravity - blackhole.CenterOfGravity).magnitude;