private void SpawnNewAsteroid(AsteroidSizeType asteroidSize, Vector3 position, Vector2 direction, float angularVelocity)
    {
        Asteroid asteroid = GetAsteroidFromPool(asteroidSize);

        asteroid.Activate();
        asteroid.MoveTo(position);
        asteroid.FlyInDirection(direction);
        asteroid.SetAngularVelocity(angularVelocity);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Spwans a new asteroid into the game.
    /// </summary>
    /// <param name="type">Type of the asteroid (Rock, Ice, Metal)</param>
    /// <param name="size">Size of the asteroid (Big, Middle, Small)</param>
    /// <param name="position">Position of the asteroid</param>
    /// <param name="velocity">Velocity of the asteroid</param>
    public void SpawnAsteroid(Asteroid.AsteroidType type, Asteroid.AsteroidSize size, Vector2 position = default(Vector2), Vector2 velocity = default(Vector2))
    {
        if (position == default(Vector2) && velocity == default(Vector2))
        {
            Vector3 playerPosition = GameManager.Instance.Player.transform.position;
            Vector3 spawnPosition  = GameManager.Instance.SpawnOutsideViewport();

            playerPosition.x -= spawnPosition.x;
            playerPosition.y -= spawnPosition.y;

            position = spawnPosition;
            velocity = playerPosition.normalized;
        }
        else if (velocity == default(Vector2))
        {
            velocity = new Vector2(Random.Range(-1, 1f), Random.Range(-1f, 1f));
        }

        Asteroid asteroid = Instance.GetAsteroid(type, size);

        asteroid.Activate(position, velocity);
    }
Ejemplo n.º 3
0
    IEnumerator DoBurst(float prewarmAmount = 0)
    {
        if (gameOver)
        {
            yield break;
        }

        bursting = true;
        int   amount = currentBurstAmount != 0 ? currentBurstAmount : 1;       //Avoiding zero-division.
        float delayBetweenActivations = burstDuration / amount;

        while (lastBurstTime + burstDuration >= Time.time && !gameOver)
        {
            Vector3 currentVelocity = asteroidDirection * Random.Range(minMaxForceMultiplier.x, minMaxForceMultiplier.y);
            float   currentLifetime = 0;
            if (minMaxAsteroidLifetime.sqrMagnitude > 0)
            {
                currentLifetime = Random.Range(minMaxAsteroidLifetime.x, minMaxAsteroidLifetime.y);
            }

            Vector3 spawnPos = Vector3.Lerp(spawnLineStart.position, spawnLineEnd.position, Random.Range(0f, 1f));
            spawnPos.y = Random.Range(spawnLineStart.position.y, spawnLineEnd.position.y);

            if (prewarmAmount > 0)
            {
                spawnPos += currentVelocity * prewarmAmount;
            }
            Vector3 currentPosition = spawnPos;

            Vector3  currentSize = Vector3.one * sizesToSpawn[Random.Range(0, sizesToSpawn.Count)];
            Asteroid asteroid    = NextAsteroid();
            asteroid.Activate(currentPosition, currentSize, currentVelocity, currentLifetime);
            yield return(new WaitForSeconds(delayBetweenActivations));
        }
        bursting = false;
    }
Ejemplo n.º 4
0
 public static void ActivateAsteroid(Asteroid asteroidObj)
 {
     asteroidObj.gameObject.SetActive(true);
     asteroidObj.Activate();
 }