IEnumerator Start()
    {
        //Fire burst
        for (int i = 0; i < numBurstsPerWave; i++)
        {
            float radDelta = (2f * Mathf.PI) / numBulletsPerBurst;

            //Fire bullet
            float curAngle = 0;
            while (curAngle < 2 * Mathf.PI)
            {
                PolarCoordinate direction = new PolarCoordinate(1, curAngle);
                ParentedBullet  newBullet = Instantiate(bulletPrefab, transform.position, new Quaternion()) as ParentedBullet;
                newBullet.damage       = bulletDamage;
                newBullet.owningPlayer = owningPlayer;
                if (!GameManager.S.inGame)
                {
                    newBullet.thisPlayer = thisPlayer;
                    newBullet.SetColor(thisPlayer.playerColor);
                }
                newBullet.transform.SetParent(transform);
                newBullet.transform.position      = gameObject.transform.position;
                newBullet.physics.actOnLocalSpace = true;
                newBullet.curState         = BulletState.parented;
                newBullet.physics.velocity = bulletVelocity * direction.PolarToCartesian().normalized;

                curAngle += radDelta;
            }

            yield return(new WaitForSeconds(timeBetweenBursts));
        }
    }
Example #2
0
 // Use this for initialization
 void Awake()
 {
     bulletPrefab    = Resources.Load <ParentedBullet>("Prefabs/Bullets/ParentedBullet");
     physics         = GetComponent <PhysicsObj>();
     bulletsPerShell = new int[numShells];
     for (int i = 0; i < numShells; i++)
     {
         bulletsPerShell[i] = Mathf.Max(1, i * bulletPerShellIncrease);
     }
 }
Example #3
0
    IEnumerator CreateBullets()
    {
        //Each shell
        for (int i = 0; i < numShells; i++)
        {
            float timeInShell = 0;
            float radDelta    = (2f * Mathf.PI) / bulletsPerShell[i];

            float curAngle    = 0;
            float bulletSpeed = (i * distanceBetweenShells) / timeBetweenEachShellForm;
            //Instantiating each bullet
            while (curAngle < 2 * Mathf.PI - 0.01f)
            {
                PolarCoordinate direction = new PolarCoordinate(1, curAngle);
                ParentedBullet  curBullet = Instantiate(bulletPrefab, transform.position, new Quaternion()) as ParentedBullet;
                curBullet.curState     = BulletState.parented;
                curBullet.damage       = bulletDamage;
                curBullet.owningPlayer = owningPlayer;
                if (!GameManager.S.inGame)
                {
                    curBullet.SetColor(thisPlayer.playerColor);
                    curBullet.thisPlayer = thisPlayer;
                }
                curBullet.transform.SetParent(transform);
                curBullet.transform.position = gameObject.transform.position;
                curBullet.physics.velocity   = bulletSpeed * direction.PolarToCartesian().normalized;

                childrenBullets.Add(curBullet);

                curAngle += radDelta;
            }

            //Moving the bullets
            while (timeInShell < timeBetweenEachShellForm)
            {
                timeInShell += Time.deltaTime;
                float percent = timeInShell / timeBetweenEachShellForm;

                List <ParentedBullet> bulletsToRemoveFromGroup = new List <ParentedBullet>();
                foreach (var bullet in childrenBullets)
                {
                    if (bullet.curState == BulletState.parented)
                    {
                        bullet.physics.velocity = (bullet.physics.velocity.normalized) * Mathf.Lerp(bulletSpeed, 0, percent);
                    }
                    else
                    {
                        bulletsToRemoveFromGroup.Add(bullet);
                    }
                }
                foreach (var bullet in bulletsToRemoveFromGroup)
                {
                    childrenBullets.Remove(bullet);
                }

                transform.Rotate(new Vector3(0, 0, 180 * Time.deltaTime));
                yield return(null);
            }
        }

        StartCoroutine(FireTowardsTarget());
    }