public List <SmallAsteroid> GetSmallAsteroid(int count)
    {
        if (count <= 0)
        {
            throw new ArgumentException("Count must be higher than 0");
        }
        List <SmallAsteroid> smallAsteroids = new List <SmallAsteroid>();

        for (int i = 0; i < _smallAsteroids.Count && smallAsteroids.Count < count; i++)
        {
            if (!_smallAsteroids[i].IsActive())
            {
                smallAsteroids.Add(_smallAsteroids[i]);
            }
        }
        if (smallAsteroids.Count < count)
        {
            for (int i = smallAsteroids.Count; i < count; i++)
            {
                SmallAsteroid smallAsteroid = Instantiate(_smallAsteroidPrefab);
                _smallAsteroids.Add(smallAsteroid);
                smallAsteroids.Add(smallAsteroid);
            }
        }
        return(smallAsteroids);
    }
Exemple #2
0
    /// <summary>
    /// Destroys the small asteroid and validates how many are remaining this level
    /// </summary>
    public void DestroySmallAsteroid(SmallAsteroid asteroid)
    {
        // Return 'destroyed' asteroid to the pool
        asteroidPooler.ReturnToPool(asteroidPooler.SmallPoolTag, asteroid);

        explosion.Play();

        ValidateRemainingAsteroids();
    }
        public Enemy CreateSmallAsteroid(Point2D[] points, Point2D creationPoint)
        {
            Enemy enemy = new SmallAsteroid(points, creationPoint);

            enemy.Rotation = _rnd.Next(0, 360);
            enemy.Destroy += OnDestroy;
            enemy.Speed    = _enemiesSpeed;
            _enemies.Add(enemy);
            CreateGameObject?.Invoke(this, enemy);
            return(enemy);
        }