예제 #1
0
 private bool IsTooCloseToAnotherBlackhole(GravitySystem newBlackhole)
 {
     foreach (GravitySystem blackhole in _activeBlackholesGravitySystems)
     {
         if (AreTooClose(newBlackhole, blackhole))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #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);
                }
            }
        }
예제 #3
0
 private bool IsInImmutableArea(GravitySystem newBlackhole) =>
 (newBlackhole.CenterOfGravity - (Vector2)_transform.position).magnitude < immutableAreaRadius;
예제 #4
0
 private bool AreTooClose(GravitySystem newBlackhole, GravitySystem blackhole) =>
 (newBlackhole.InfluenceRadius + blackhole.InfluenceRadius) > (newBlackhole.CenterOfGravity - blackhole.CenterOfGravity).magnitude;