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