Ejemplo n.º 1
0
        private IEnumerator IntroWhiteSpiritPattern(LambdaShotPattern pattern, List <UDEAbstractBullet> bullets, UDEEnemy enemy)
        {
            var trResult = UDETransitionHelper.MoveAmount(enemy.gameObject, new Vector2(-7, 0.6f), 6, UDETransitionHelper.easeOutQuad, UDETime.TimeScale.ENEMY, true);

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.5f, UDETime.TimeScale.ENEMY)));

            for (int i = 0; i < 5; i++)
            {
                UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(bullets[0]);
                bullet.SummonTime = 0.08f;
                bullet.MoveBulletToDirection(enemy, pattern, enemy.transform.position, 0, new Vector2(-5, 0), true);

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.8f, UDETime.TimeScale.ENEMY)));
            }

            yield return(new WaitUntil(() => trResult.EndTransition));

            trResult = UDETransitionHelper.MoveAmount(enemy.gameObject, new Vector2(-6, 15), 6, UDETransitionHelper.easeInQuad, UDETime.TimeScale.ENEMY, true);
            yield return(new WaitUntil(() => trResult.EndTransition));

            ((EnemyBase)enemy).OnDestroy();
            Destroy(enemy);

            yield return(null);
        }
Ejemplo n.º 2
0
        private IEnumerator LeafFallSubPattern()
        {
            IUDERandom rand = new UDEXORRandom();

            UDECartesianMovementBuilder builder = UDECartesianMovementBuilder.Create();

            builder.Velocity(Vector2.zero)
            .Accel(t => new UDEMath.CartesianCoord(
                       6f * Mathf.Log10(t + 1f) * Mathf.Cos(2 * Mathf.PI * t / 2.0f),
                       -2.0f
                       ))
            .MinVelocity(new Vector2(float.MinValue, -6.0f))
            .DoNotFaceToMovingDirection();

            UDEBulletMovement leafFall = builder.Build();

            while (true)
            {
                UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(patternBullets[GreenLuminusBullet]);
                bullet.transform.localScale = new Vector3(0.82f, 0.82f);
                bullet.SummonTime           = 0f;

                Vector2 initPos = (Vector2)Camera.main.ViewportToWorldPoint(new Vector3(rand.NextFloat(0.01f, 0.99f), 1.05f, 0));
                bullet.Initialize(initPos, initPos, 0, originEnemy, this, leafFall);

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.25f, UDETime.TimeScale.ENEMY)));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create new pool of the bullet prefab
        /// </summary>
        /// <param name="prefab"><see cref="SansyHuman.UDE.Object.UDEAbstractBullet"/> prefab</param>
        /// <param name="initialNumber">Initial number of bullets</param>
        public void AddNewPool(UDEAbstractBullet prefab, int initialNumber)
        {
            try
            {
                _ = poolList[prefab];
            }
            catch (KeyNotFoundException) // When the pool of the prefab does not exist.
            {
                Stack <UDEAbstractBullet> pool = new Stack <UDEAbstractBullet>(initialNumber * 2);
                for (int j = 0; j < initialNumber; j++)
                {
                    UDEAbstractBullet instance = Instantiate <UDEAbstractBullet>(prefab, new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0));
#pragma warning disable CS0618 // Type or member is obsolete
                    instance.OriginPrefab = prefab;
#pragma warning restore CS0618 // Type or member is obsolete
                    GameObject instObj = instance.gameObject;
                    instObj.SetActive(false);
                    instObj.name             = prefab.gameObject.name;
                    instObj.transform.parent = this.transform;
                    pool.Push(instance);
                }
                poolList.Add(prefab, pool);
                return;
            }

            Debug.LogWarning("The pool of the prefab is already exist.");
        }
Ejemplo n.º 4
0
    private IEnumerator GravityBullets()
    {
        while (true)
        {
            UDEMath.CartesianCoord      accelDown = new UDEMath.CartesianCoord(0, -3);
            UDEMath.CartesianCoord      accelUp   = new UDEMath.CartesianCoord(0, 3);
            UDECartesianMovementBuilder builder   = UDECartesianMovementBuilder.Create().MaxMagnitude(6f);

            for (int i = 0; i < 23; i++)
            {
                float   angle    = 90f + Random.Range(-55f, 55f);
                var     velTuple = UDEMath.Polar2Cartesian(3f, angle);
                Vector2 velocity = new Vector2(velTuple.x, velTuple.y);


                Vector2 origin = originEnemy.transform.position;
                Vector2 player = GameObject.FindGameObjectWithTag("Player").transform.position;
                if (player.y > origin.y)
                {
                    builder.Velocity(-velocity).Accel(accelUp);
                }
                else
                {
                    builder.Velocity(velocity).Accel(accelDown);
                }
                UDEBulletMovement movement = builder.Build();

                UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                bullet.Initialize(origin, origin, 0, originEnemy, this, movement);
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.75f, UDETime.TimeScale.ENEMY)));
        }
    }
Ejemplo n.º 5
0
    protected override IEnumerator ShotPattern()
    {
        originEnemy.CanBeDamaged = false;
        var result = UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f)), 2f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);

        yield return(new WaitUntil(() => result.EndTransition));

        originEnemy.CanBeDamaged = true;

        UDEPolarMovementBuilder builder = UDEPolarMovementBuilder.Create().DoNotFaceToMovingDirection();
        float angleDiff = 360f / numberOfBullets;

        bool  lowHealth      = false;
        float summonInterval = 2f;

        while (true)
        {
            if (!lowHealth && originEnemy.Health < 200f)
            {
                lowHealth      = true;
                summonInterval = 1.4f;
                moveIn.RemoveAll(tr => !tr.gameObject.activeSelf);
                UDEBulletPool.Instance.ReleaseBullets(shottedBullets.ToArray());
                moveIn.Clear();
            }

            for (int i = 0; i < numberOfBullets; i++)
            {
                float angle = angleDiff * i;

                UDEAbstractBullet moveOut     = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                UDEBulletMovement movementOut = builder.RadialSpeed(radialSpeed).AngularSpeed(angularSpeed).RotationAngularSpeed(angularSpeed).Build();

                Vector2 origin  = enemyTr.position;
                Vector2 formLoc = origin + UDEMath.Polar2Cartesian(0.3f, angle).ToVector2();

                moveOut.Initialize(formLoc, origin, angle, originEnemy, this, movementOut, setOriginToCharacter: true);

                UDEAbstractBullet moveIn     = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                UDEBulletMovement movementIn = builder.RadialSpeed(-radialSpeed).AngularSpeed(-angularSpeed).RotationAngularSpeed(-angularSpeed).Build();

                formLoc = origin + UDEMath.Polar2Cartesian(8.3f, angle).ToVector2();

                moveIn.Initialize(formLoc, origin, angle, originEnemy, this, movementIn, setOriginToCharacter: true);
                this.moveIn.Add(moveIn.transform);

                Vector3 moveOutScale = moveOut.transform.localScale;
                Vector3 moveInScale  = moveIn.transform.localScale;
                moveOutScale *= 2.5f;
                moveInScale  *= 2.5f;
                moveOut.transform.localScale = moveOutScale;
                moveIn.transform.localScale  = moveInScale;
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(summonInterval, UDETime.TimeScale.ENEMY)));
        }
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a bullet to the map. If the bullet already exists, then ignored.
        /// </summary>
        /// <param name="bullet">Bullet to add</param>
        public void AddBullet(UDEAbstractBullet bullet)
        {
            if (bulletMap.ContainsKey(bullet.gameObject.name))
            {
                Debug.LogError("Bullet map already has the bullet.");
                return;
            }

            bulletMap.Add(bullet.gameObject.name, bullet);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Removes a bullet from the map. If the bullet does not exist, then ignored.
 /// </summary>
 /// <param name="bullet">Bullet to remove</param>
 public void RemoveBullet(UDEAbstractBullet bullet)
 {
     if (bulletMap.ContainsKey(bullet.gameObject.name))
     {
         bulletMap.Remove(bullet.gameObject.name);
     }
     else
     {
         Debug.LogError("Bullet map does not have the bullet.");
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the bullet object to the pool.
        /// <para>If you try to release the bullet that already released, it will be ignored.</para>
        /// </summary>
        /// <param name="target">Bullet object to release</param>
        public void ReleaseBullet(UDEAbstractBullet target)
        {
            if (!target.gameObject.activeSelf)
            {
                Debug.LogWarning("You tried to release bullet that already released. The release is ignored.");
                return;
            }
            target.gameObject.SetActive(false);
#pragma warning disable CS0618 // Type or member is obsolete
            poolList[target.OriginPrefab].Push(target);
#pragma warning restore CS0618 // Type or member is obsolete
        }
Ejemplo n.º 9
0
        private IEnumerator Wave1FairyPattern(LambdaShotPattern pattern, List <UDEAbstractBullet> bullets, UDEEnemy enemy)
        {
            var trResult = UDETransitionHelper.MoveAmount(enemy.gameObject, new Vector2(-3, 0), 0.3f, UDETransitionHelper.easeOutQuad, UDETime.TimeScale.ENEMY, true);

            yield return(new WaitUntil(() => trResult.EndTransition));

            Transform enemyTr   = enemy.transform;
            Transform player    = GameManager.player.transform;
            Vector2   direction = player.position - enemyTr.position;

            direction /= direction.magnitude;

            (_, float angle) = UDEMath.Cartesian2Polar(direction);

            UDECartesianPolarMovementBuilder builder = UDECartesianPolarMovementBuilder.Create().Speed(9.0f).MinSpeed(3.0f).TangentialAccel(-17.0f);

            int   bulletCnt = 25;
            float delta     = 360f / bulletCnt;

            for (int i = 0; i < bulletCnt; i++)
            {
                float moveAngle = angle + delta * i;
                (float x, float y) = UDEMath.Polar2Cartesian(0.4f, moveAngle);

                UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(bullets[0]);
                bullet.SummonTime = 0.12f;
                bullet.Initialize(enemyTr.position + new Vector3(x, y), enemyTr.position, 0, enemy, pattern, builder.Angle(moveAngle).Build());
            }

            builder.Angle(angle);
            for (int i = 1; i < 6; i++)
            {
                (float x, float y) = UDEMath.Polar2Cartesian(0.4f, angle);

                UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(bullets[0]);
                bullet.SummonTime = 0.12f;
                bullet.Initialize(enemyTr.position + new Vector3(x, y), enemyTr.position, 0, enemy, pattern, builder.MinSpeed(3.0f + 0.6f * i).Build());
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.5f, UDETime.TimeScale.ENEMY)));

            Vector2 movePoint = Camera.main.ViewportToWorldPoint(new Vector3(-0.1f, 0));

            movePoint.y = enemyTr.position.y;

            trResult = UDETransitionHelper.MoveTo(enemy.gameObject, movePoint, 10f, UDETransitionHelper.easeInCubic, UDETime.TimeScale.ENEMY, true);
            yield return(new WaitUntil(() => trResult.EndTransition));

            ((EnemyBase)enemy).OnDestroy();
            Destroy(enemy);

            yield return(null);
        }
Ejemplo n.º 10
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.tag == "Bullet")
     {
         UDEAbstractBullet bullet = collision.gameObject.GetComponent <UDEAbstractBullet>();
         if (bullet == null || !bullet.gameObject.activeSelf)
         {
             return;
         }
         UDEBulletPool.Instance.ReleaseBullet(bullet);
     }
 }
Ejemplo n.º 11
0
    protected override IEnumerator ShotPattern()
    {
        originEnemy.CanBeDamaged = false;
        var result = UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.85f)), 2f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);

        yield return(new WaitUntil(() => result.EndTransition));

        originEnemy.CanBeDamaged = true;

        float angleDiff = 360f / (float)bulletNumber;

        float angleClockwise     = 0;
        float angleAntiClockwise = 0;

        UDEPolarMovementBuilder builder = UDEPolarMovementBuilder.Create().RadialSpeed(bulletSpeed);

        while (true)
        {
            for (int i = 0; i < bulletNumber; i++)
            {
                float angle = angleDiff * i + angleClockwise;
                builder.InitialAngle(angle);

                UDEAbstractBullet bullet  = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                Vector2           origin  = originEnemy.transform.position;
                Vector2           formLoc = origin + (UDEMath.CartesianCoord) new UDEMath.PolarCoord(0.35f, angle);
                bullet.Initialize(formLoc, origin, 0, originEnemy, this, builder.Build());

                angle = angleDiff * i + angleAntiClockwise;
                builder.InitialAngle(angle);

                UDEAbstractBullet bullet2 = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                formLoc = origin + (UDEMath.CartesianCoord) new UDEMath.PolarCoord(0.35f, angle);
                bullet2.Initialize(formLoc, origin, 0, originEnemy, this, builder.Build());
            }

            angleClockwise     -= angularSpeed;
            angleAntiClockwise += angularSpeed;
            while (angleClockwise < 0)
            {
                angleClockwise += 360f;
            }
            while (angleAntiClockwise > 360)
            {
                angleAntiClockwise -= 360f;
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.12f, UDETime.TimeScale.ENEMY)));
        }
    }
Ejemplo n.º 12
0
    protected override IEnumerator ShotPattern()
    {
        originEnemy.CanBeDamaged = false;
        var result = UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f)), 2f, UDETransitionHelper.easeInOutCubic, UDETime.TimeScale.ENEMY, true);

        yield return(new WaitUntil(() => result.EndTransition));

        originEnemy.CanBeDamaged = true;

        UDEMath.PolarFunction bulletPosition        = (deg, err) => 0.3f + 2.5f * (deg - err) / 360f;
        UDEMath.PolarFunction bulletPositionInverse = (deg, err) => 0.3f + 2.5f * (err - deg) / 360f;

        UDEPolarMovementBuilder first  = UDEPolarMovementBuilder.Create().DoNotFaceToMovingDirection();
        UDEPolarMovementBuilder second = UDEPolarMovementBuilder.Create(true).MinAngularSpeed(-30f).MinRadialSpeed(-2.2f).AngularAccel(-25f).RadialAccel(-1.8f).StartTime(1000);

        Vector2 origin = originEnemy.transform.position;

        int cnt = 0;

        while (true)
        {
            float error = Random.Range(-10f, 10f);
            UDEMath.PolarCoord[] coords = cnt % 2 == 0 ?
                                          UDEMath.GetPolarCoordStructs(bulletPosition, error, 3 * 360 + error, error, 500) :
                                          UDEMath.GetPolarCoordStructs(bulletPositionInverse, -error, -error - 3 * 360, -error, 500);
            for (int i = 0; i < coords.Length; i++)
            {
                UDEAbstractBullet   bullet    = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                Vector2             formLoc   = origin + (UDEMath.CartesianCoord)coords[i];
                float               angle     = coords[i].degree - 90f;
                UDEBulletMovement[] movements = new UDEBulletMovement[] { first.Build(), second.Build() };
                bullet.Initialize(formLoc, origin, angle, originEnemy, this, movements);
                bullets.Add(bullet);
                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.012f, UDETime.TimeScale.ENEMY)));
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(1f, UDETime.TimeScale.ENEMY)));

            for (int i = bullets.Count - 1; i > -1; i--)
            {
                ((dynamic)bullets[i]).ForceMoveToPhase(1);
                bullets.RemoveAt(i);
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(7f, UDETime.TimeScale.ENEMY)));

            cnt++;
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// Deletes bullets in the pool that are inactive and leaves the pool.
        /// </summary>
        /// <param name="prefab"><see cref="SansyHuman.UDE.Object.UDEAbstractBullet"/> prefab to destroy</param>
        public void ClearPool(UDEAbstractBullet prefab)
        {
            Stack <UDEAbstractBullet> pool;

            if (!poolList.TryGetValue(prefab, out pool))
            {
                Debug.LogWarning("The pool of the prefab does not exist. Pool deletion will be ignored.");
                return;
            }

            for (int i = 0; i < pool.Count; i++)
            {
                UDEAbstractBullet bullet = pool.Pop();
                Destroy(bullet.gameObject);
            }
        }
Ejemplo n.º 14
0
        protected override void OnTriggerStay2D(Collider2D collision)
        {
            if (!invincible)
            {
                if (collision.CompareTag("Enemy"))
                {
                    StartCoroutine(DamageSelf(1));
                }
                else if (collision.CompareTag("Bullet"))
                {
                    UDEAbstractBullet bullet = collision.GetComponent <UDEAbstractBullet>();
                    if (bullet != null && bullet.gameObject.activeSelf && bullet.OriginCharacter is UDEEnemy)
                    {
                        UDEBulletPool.Instance.ReleaseBullet(bullet);
                        StartCoroutine(DamageSelf(1));
                    }
                }
                else if (collision.CompareTag("Laser"))
                {
                    UDELaser laser = collision.GetComponent <UDELaser>();
                    if (laser != null && laser.OriginCharacter is UDEEnemy)
                    {
                        StartCoroutine(DamageSelf(1));
                    }
                }
            }

            if (collision.CompareTag("Item"))
            {
                ItemBase item = collision.GetComponent <ItemBase>();

                if (item is Power power)
                {
                    AddScore(500);
                    AddPower(power.PowerPoint);
                }

                item.RemoveItem();
            }
        }
Ejemplo n.º 15
0
        protected override IEnumerator ShotPattern()
        {
            UDETransitionHelper.StopAllTransitions(originEnemy.gameObject);

            originalBackgroundColor = background.GetComponent <SpriteRenderer>().color;

            originEnemy.CanBeDamaged = false;
            UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.77f, 0.5f, 0)), 0.75f, UDETransitionHelper.easeOutCubic, UDE.Management.UDETime.TimeScale.ENEMY, true);
            UDETransitionHelper.ChangeScaleTo(background, new Vector3(1.2f, 1.2f, 1f), 1f, UDETransitionHelper.easeLinear, UDETime.TimeScale.ENEMY, false);
            UDETransitionHelper.ChangeColorTo(background, changeBackgroundColorTo, 1f, UDETransitionHelper.easeLinear, UDETime.TimeScale.ENEMY, false);
            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(2f, UDETime.TimeScale.ENEMY)));

            originEnemy.CanBeDamaged = true;

            IEnumerator leafFallPattern = LeafFallSubPattern();

            StartSubpattern(leafFallPattern);

            UDEPolarMovementBuilder builder  = UDEPolarMovementBuilder.Create().RadialSpeed(radialSpeed);
            UDEBulletMovement       movement = builder.Build();

            float currAngle = 0f;
            float dtheta    = 360f / numberOfBullets;

            while (true)
            {
                for (int i = 0; i < numberOfBullets; i++)
                {
                    UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(patternBullets[LightBlueCircleBullet]);
                    bullet.SummonTime = 0.1f;
                    Vector2 origin  = originEnemy.transform.position;
                    Vector2 initPos = UDEMath.Polar2Cartesian(0.1f, currAngle + dtheta * i).ToVector2() + origin;

                    bullet.Initialize(initPos, origin, 0, originEnemy, this, movement);
                }

                currAngle += angleDifference;
                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(1.5f, UDETime.TimeScale.ENEMY)));
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets <see cref="SansyHuman.UDE.Object.UDEAbstractBullet"/> instance of the target object.
        /// </summary>
        /// <param name="target">Bullet object to get</param>
        /// <returns><see cref="SansyHuman.UDE.Object.UDEAbstractBullet"/> instance</returns>
        public UDEAbstractBullet GetBullet(UDEAbstractBullet target)
        {
            UDEAbstractBullet returnInstance = null;

            Stack <UDEAbstractBullet> targetPool;

            if (poolList.TryGetValue(target, out targetPool))
            {
                if (targetPool.Count > 0)
                {
                    UDEAbstractBullet inst = targetPool.Pop();
                    inst.gameObject.SetActive(true);
                    returnInstance = inst;
                }
                else // When there is no more bullet in the pool.
                {
                    UDEAbstractBullet instance = Instantiate <UDEAbstractBullet>(target, new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0));
#pragma warning disable CS0618 // Type or member is obsolete
                    instance.OriginPrefab = target;
#pragma warning restore CS0618 // Type or member is obsolete
                    GameObject instObj = instance.gameObject;
                    instObj.name             = target.gameObject.name;
                    instObj.transform.parent = this.transform;
                    returnInstance           = instance;
                }
            }
            else // When there is no object pool of the target bullet.
            {
                Debug.LogWarning("The target bullet is not found. Create new pool for the bullet.");
                AddNewPool(target, 32);
                returnInstance = poolList[target].Pop();
                returnInstance.gameObject.SetActive(true);
            }

            return(returnInstance);
        }
Ejemplo n.º 17
0
 public void RemoveBullet(UDEAbstractBullet bullet)
 {
     bullets.Remove(bullet);
 }
Ejemplo n.º 18
0
 public void AddBullet(UDEAbstractBullet bullet)
 {
     bullets.Add(bullet);
 }
Ejemplo n.º 19
0
    protected override IEnumerator ShotPattern()
    {
        originEnemy.CanBeDamaged = false;
        var result = UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.85f)), 2f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);

        yield return(new WaitUntil(() => result.EndTransition));

        originEnemy.CanBeDamaged = true;

        UDEPolarMovementBuilder[] builders = new UDEPolarMovementBuilder[3];

        builders[0] = UDEPolarMovementBuilder.Create().RadialSpeed(4.5f);
        builders[1] = UDEPolarMovementBuilder.Create(true).RadialAccel(25f).MaxRadialSpeed(10f).StartTime(0.3f);
        builders[2] = UDEPolarMovementBuilder.Create(true).RadialAccel(-22f).MinRadialSpeed(0.6f).StartTime(0.65f);

        float angleInterval      = 360f / groupCount;
        float smallAngleInterval = angleInterval / bulletsPerGroup * 1.25f;
        int   flag = 0;

        while (true)
        {
            float deviation = Random.Range(-15f, 15f);
            for (int i = 0; i < bulletsPerGroup; i++)
            {
                UDEAbstractBullet[] bullets = new UDEAbstractBullet[groupCount];
                for (int n = 0; n < bullets.Length; n++)
                {
                    bullets[n] = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                }

                for (int j = 0; j < groupCount; j++)
                {
                    float angle;
                    if (flag % 2 == 0)
                    {
                        angle = deviation + angleInterval * j + smallAngleInterval * i;
                    }
                    else
                    {
                        angle = deviation + angleInterval * j + smallAngleInterval * (bulletsPerGroup - 1 - i);
                    }

                    UDEBulletMovement[] movements = new UDEBulletMovement[builders.Length];
                    for (int k = 0; k < builders.Length; k++)
                    {
                        builders[k].InitialAngle(angle);
                        movements[k] = builders[k].Build();
                    }

                    Vector2 origin  = originEnemy.transform.position;
                    Vector2 formLoc = origin + UDEMath.Polar2Cartesian(0.45f, angle).ToVector2();

                    bullets[j].Initialize(formLoc, origin, 0, originEnemy, this, movements);
                }

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.18f, UDETime.TimeScale.ENEMY)));
            }

            flag++;
            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.7f, UDETime.TimeScale.ENEMY)));
        }
    }
Ejemplo n.º 20
0
        private IEnumerator Wave2FairyPattern(LambdaShotPattern pattern, List <UDEAbstractBullet> bullets, UDEEnemy enemy)
        {
            UDETransitionHelper.MoveAmount(enemy.gameObject, new Vector2(-3, 0), 1f, UDETransitionHelper.easeOutQuad, UDETime.TimeScale.ENEMY, true);
            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.3f, UDETime.TimeScale.ENEMY)));

            Transform enemyTr = enemy.transform;

            float angle     = 25;
            var   easeInOut = UDETransitionHelper.easeInOutQuad.Composite(t => t / 4);
            float dt        = 0.4f;

            UDECartesianPolarMovementBuilder builder = UDECartesianPolarMovementBuilder.Create().Speed(4.5f).Angle(180);
            UDEBulletMovement central = builder.Build();

            float accTime = 0;

            for (int i = 0; i < (int)(8 / dt); i++)
            {
                if (accTime <= 4)
                {
                    angle = 25 - 50 * easeInOut(accTime);
                }
                else
                {
                    angle = -25 + 50 * easeInOut(accTime - 4);
                }

                UDEBulletMovement upper = builder.Angle(180 - angle).Build();
                UDEBulletMovement lower = builder.Angle(180 + angle).Build();

                UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(bullets[0]); // Upper
                bullet.SummonTime           = 0.05f;
                bullet.transform.localScale = new Vector3(0.85f, 0.85f);
                bullet.Initialize(enemyTr.position, enemyTr.position, 0, enemy, pattern, upper);

                bullet                      = UDEBulletPool.Instance.GetBullet(bullets[1]); // Lower
                bullet.SummonTime           = 0.05f;
                bullet.transform.localScale = new Vector3(0.85f, 0.85f);
                bullet.Initialize(enemyTr.position, enemyTr.position, 0, enemy, pattern, lower);

                float accTimeD = accTime + 1f;
                if (accTimeD >= 8)
                {
                    accTimeD -= 8;
                }

                if (accTimeD <= 4)
                {
                    angle = 25 - 50 * easeInOut(accTimeD);
                }
                else
                {
                    angle = -25 + 50 * easeInOut(accTimeD - 4);
                }

                upper.angle                 = 180 - angle * 2f;
                bullet                      = UDEBulletPool.Instance.GetBullet(bullets[2]);
                bullet.SummonTime           = 0.05f;
                bullet.transform.localScale = new Vector3(0.85f, 0.85f);
                bullet.Initialize(enemyTr.position, enemyTr.position, 0, enemy, pattern, upper);

                lower.angle                 = 180 + angle * 2f;
                bullet                      = UDEBulletPool.Instance.GetBullet(bullets[2]);
                bullet.SummonTime           = 0.05f;
                bullet.transform.localScale = new Vector3(0.85f, 0.85f);
                bullet.Initialize(enemyTr.position, enemyTr.position, 0, enemy, pattern, lower);

                accTime += dt;
                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(dt, UDETime.TimeScale.ENEMY)));
            }

            Vector2 movePoint = Camera.main.ViewportToWorldPoint(new Vector3(-0.1f, 0));

            movePoint.y = enemyTr.position.y;

            var trResult = UDETransitionHelper.MoveTo(enemy.gameObject, movePoint, 6f, UDETransitionHelper.easeInQuad, UDETime.TimeScale.ENEMY, true);

            yield return(new WaitUntil(() => trResult.EndTransition));

            ((EnemyBase)enemy).OnDestroy();
            Destroy(enemy);

            yield return(null);
        }
Ejemplo n.º 21
0
    protected override IEnumerator ShotPattern()
    {
        var result = UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f)), 2, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);

        originEnemy.CanBeDamaged = false;
        yield return(new WaitUntil(() => result.EndTransition));

        originEnemy.CanBeDamaged = true;

        StartCoroutine(GravityBullets());

        UDECartesianPolarMovementBuilder builder = UDECartesianPolarMovementBuilder.Create().Speed(4f);

        while (true)
        {
            for (int i = 0; i < 3; i++)
            {
                Vector2 playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
                Vector2 enemyPosition  = originEnemy.transform.position;
                float   angle          = UDEMath.Deg(playerPosition - enemyPosition);

                Vector2 origin          = enemyPosition;
                Vector2 formOriginDispl = UDEMath.Polar2Cartesian(0.3f, angle).ToVector2();
                Vector2 formOrigin      = origin + formOriginDispl;
                builder.Angle(angle);
                UDEBulletMovement movement = builder.Build();

                Vector2 formHalfDispl = UDEMath.Polar2Cartesian(0.105f, angle + 90).ToVector2();

                for (int n = 1; n <= 6; n++)
                {
                    if (n % 2 == 0)
                    {
                        for (int j = 0; j < n / 2; j++)
                        {
                            UDEAbstractBullet negBullet = UDEBulletPool.Instance.GetBullet(patternBullets[1]);
                            UDEAbstractBullet posBullet = UDEBulletPool.Instance.GetBullet(patternBullets[1]);
                            negBullet.Initialize(formOrigin - (formHalfDispl * (j * 2 + 1)), origin, 0, originEnemy, this, movement);
                            posBullet.Initialize(formOrigin + (formHalfDispl * (j * 2 + 1)), origin, 0, originEnemy, this, movement);
                        }
                    }
                    else
                    {
                        UDEAbstractBullet middleBullet = UDEBulletPool.Instance.GetBullet(patternBullets[1]);
                        middleBullet.Initialize(formOrigin, origin, 0, originEnemy, this, movement);
                        for (int j = 0; j < n / 2; j++)
                        {
                            UDEAbstractBullet negBullet = UDEBulletPool.Instance.GetBullet(patternBullets[1]);
                            UDEAbstractBullet posBullet = UDEBulletPool.Instance.GetBullet(patternBullets[1]);
                            negBullet.Initialize(formOrigin - (formHalfDispl * (j + 1) * 2), origin, 0, originEnemy, this, movement);
                            posBullet.Initialize(formOrigin + (formHalfDispl * (j + 1) * 2), origin, 0, originEnemy, this, movement);
                        }
                    }

                    yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.11f, UDETime.TimeScale.ENEMY)));
                }

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.24f, UDETime.TimeScale.ENEMY)));
            }

            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(2f, UDETime.TimeScale.ENEMY)));
        }
    }
Ejemplo n.º 22
0
        private void ShotBullet()
        {
            UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(mainBullet);

            bullet.Damage = mainCenterBulletDamage;
            bullet.MoveBulletToDirection(this, null, mainShotPoint.position, 0, new Vector2(arrowBulletSpeed, 0));
            if (powerLevel >= 1)
            {
                bullet        = UDEBulletPool.Instance.GetBullet(mainBullet);
                bullet.Damage = mainSubBulletDamage;
                var vel = UDEMath.Polar2Cartesian(arrowBulletSpeed, mainShotAngle * (isSlowMode ? mainShotAngleMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, mainShotPoint.position, 0, new Vector2(vel.x, vel.y));

                bullet        = UDEBulletPool.Instance.GetBullet(mainBullet);
                bullet.Damage = mainSubBulletDamage;
                vel           = UDEMath.Polar2Cartesian(arrowBulletSpeed, -mainShotAngle * (isSlowMode ? mainShotAngleMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, mainShotPoint.position, 0, new Vector2(vel.x, vel.y));
            }
            if (powerLevel >= 2)
            {
                bullet        = UDEBulletPool.Instance.GetBullet(subBullet);
                bullet.Damage = subBulletDamage;
                var vel = UDEMath.Polar2Cartesian(arrowBulletSpeed, subWeaponShotAngle * (isSlowMode ? subWeaponShotAngleSlowMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, subWeapons[0].position, 0, new Vector2(vel.x, vel.y));

                bullet        = UDEBulletPool.Instance.GetBullet(subBullet);
                bullet.Damage = subBulletDamage;
                vel           = UDEMath.Polar2Cartesian(arrowBulletSpeed, subWeaponShotAngle * (isSlowMode ? subWeaponShotAngleSlowMultiplier : 1.0f) + subArrowAngle * (isSlowMode ? subArrowAngleSlowMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, subWeapons[0].position, 0, new Vector2(vel.x, vel.y));

                bullet        = UDEBulletPool.Instance.GetBullet(subBullet);
                bullet.Damage = subBulletDamage;
                vel           = UDEMath.Polar2Cartesian(arrowBulletSpeed, subWeaponShotAngle * (isSlowMode ? subWeaponShotAngleSlowMultiplier : 1.0f) - subArrowAngle * (isSlowMode ? subArrowAngleSlowMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, subWeapons[0].position, 0, new Vector2(vel.x, vel.y));

                bullet        = UDEBulletPool.Instance.GetBullet(subBullet);
                bullet.Damage = subBulletDamage;
                vel           = UDEMath.Polar2Cartesian(arrowBulletSpeed, -subWeaponShotAngle * (isSlowMode ? subWeaponShotAngleSlowMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, subWeapons[1].position, 0, new Vector2(vel.x, vel.y));

                bullet        = UDEBulletPool.Instance.GetBullet(subBullet);
                bullet.Damage = subBulletDamage;
                vel           = UDEMath.Polar2Cartesian(arrowBulletSpeed, -subWeaponShotAngle * (isSlowMode ? subWeaponShotAngleSlowMultiplier : 1.0f) + subArrowAngle * (isSlowMode ? subArrowAngleSlowMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, subWeapons[1].position, 0, new Vector2(vel.x, vel.y));

                bullet        = UDEBulletPool.Instance.GetBullet(subBullet);
                bullet.Damage = subBulletDamage;
                vel           = UDEMath.Polar2Cartesian(arrowBulletSpeed, -subWeaponShotAngle * (isSlowMode ? subWeaponShotAngleSlowMultiplier : 1.0f) - subArrowAngle * (isSlowMode ? subArrowAngleSlowMultiplier : 1.0f));
                bullet.MoveBulletToDirection(this, null, subWeapons[1].position, 0, new Vector2(vel.x, vel.y));
            }
            if (powerLevel >= 3 && shotCnt == 0)
            {
                UDEHomingBullet homingBullet = UDEBulletPool.Instance.GetBullet(subHomingBullet) as UDEHomingBullet;
                homingBullet.Damage = subHomingBulletDamage;
                homingBullet.Initialize(subWeapons[2].position, this, isSlowMode ? homingMoveSlow1 : homingMove1);

                homingBullet        = UDEBulletPool.Instance.GetBullet(subHomingBullet) as UDEHomingBullet;
                homingBullet.Damage = subHomingBulletDamage;
                homingBullet.Initialize(subWeapons[3].position, this, isSlowMode ? homingMoveSlow2 : homingMove2);
            }
        }
Ejemplo n.º 23
0
        protected override IEnumerator ShotPattern()
        {
            originEnemy.transform.SetPositionAndRotation(Camera.main.ViewportToWorldPoint(new Vector3(1.1f, 0.5f, 0)), Quaternion.Euler(0, 0, 0));
            var trResult = UDETransitionHelper.MoveTo(originEnemy.gameObject, Camera.main.ViewportToWorldPoint(new Vector3(0.8f, 0.5f, 0)), 0.5f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);

            originEnemy.CanBeDamaged = false;
            yield return(new WaitUntil(() => trResult.EndTransition));

            originEnemy.CanBeDamaged = true;

            IUDERandom random     = new UDEXORRandom();
            Vector2    moveVector = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.65f, 0));

            moveVector = new Vector2(0, moveVector.y);

            while (true)
            {
                float dtheta = 360f / numberOfGreenBullets;
                for (int i = 0; i < numberOfGreenBullets; i++)
                {
                    UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(patternBullets[GreenLuminusBullet]);
                    bullet.transform.localScale = new Vector3(0.7f, 0.7f);
                    bullet.SummonTime           = 0.08f;
                    (float x, float y)          = UDEMath.Polar2Cartesian(greenBulletSpeed, i * dtheta);
                    bullet.MoveBulletToDirection(originEnemy, this, originEnemy.transform.position, 0, new Vector2(x, y));
                }

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.35f, UDETime.TimeScale.ENEMY)));

                Vector2 playerPos = GameManager.player.transform.position;
                Vector2 direction = playerPos - (Vector2)originEnemy.transform.position;
                (_, float angle) = UDEMath.Cartesian2Polar(direction);

                Vector2 vel1 = UDEMath.Polar2Cartesian(blueBulletSpeed, angle).ToVector2();
                Vector2 vel2 = UDEMath.Polar2Cartesian(blueBulletSpeed, angle + blueBulletAngle).ToVector2();
                Vector2 vel3 = UDEMath.Polar2Cartesian(blueBulletSpeed, angle - blueBulletAngle).ToVector2();

                for (int i = 0; i < 5; i++)
                {
                    UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(patternBullets[LightBlueLuminusBullet]);
                    bullet.transform.localScale = new Vector3(0.7f, 0.7f);
                    bullet.SummonTime           = 0.08f;
                    bullet.MoveBulletToDirection(originEnemy, this, originEnemy.transform.position, 0, vel1);

                    bullet = UDEBulletPool.Instance.GetBullet(patternBullets[LightBlueLuminusBullet]);
                    bullet.transform.localScale = new Vector3(0.7f, 0.7f);
                    bullet.SummonTime           = 0.08f;
                    bullet.MoveBulletToDirection(originEnemy, this, originEnemy.transform.position, 0, vel2);

                    bullet = UDEBulletPool.Instance.GetBullet(patternBullets[LightBlueLuminusBullet]);
                    bullet.transform.localScale = new Vector3(0.7f, 0.7f);
                    bullet.SummonTime           = 0.08f;
                    bullet.MoveBulletToDirection(originEnemy, this, originEnemy.transform.position, 0, vel3);

                    yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.15f, UDETime.TimeScale.ENEMY)));
                }

                int     flag   = random.NextInt(0, 100);
                Vector2 curPos = Camera.main.WorldToViewportPoint(originEnemy.transform.position);
                if (flag < 50)             // Move up
                {
                    if (curPos.y >= 0.79f) // Move down
                    {
                        UDETransitionHelper.MoveAmount(originEnemy.gameObject, -moveVector, 1f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);
                    }
                    else
                    {
                        UDETransitionHelper.MoveAmount(originEnemy.gameObject, moveVector, 1f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);
                    }
                }
                else // Move down
                {
                    if (curPos.y <= 0.21f) // Move up
                    {
                        UDETransitionHelper.MoveAmount(originEnemy.gameObject, moveVector, 1f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);
                    }
                    else
                    {
                        UDETransitionHelper.MoveAmount(originEnemy.gameObject, -moveVector, 1f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);
                    }
                }

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.3f, UDETime.TimeScale.ENEMY)));

                for (int i = 0; i < numberOfGreenBullets; i++)
                {
                    UDEAbstractBullet bullet = UDEBulletPool.Instance.GetBullet(patternBullets[GreenLuminusBullet]);
                    bullet.transform.localScale = new Vector3(0.7f, 0.7f);
                    bullet.SummonTime           = 0.08f;
                    (float x, float y)          = UDEMath.Polar2Cartesian(greenBulletSpeed, i * dtheta);
                    bullet.MoveBulletToDirection(originEnemy, this, originEnemy.transform.position, 0, new Vector2(x, y));
                }

                yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.7f, UDETime.TimeScale.ENEMY)));
            }
        }
Ejemplo n.º 24
0
    protected override IEnumerator ShotPattern()
    {
        /*
         * float AngleDeg = (360f / NumberOfBullets);
         * float AngleRef = 0f;
         * float RefOmega = 0f;
         * while (true)
         * {
         *  for (int i = 0; i < NumberOfBullets; i++)
         *  {
         *      UDEBaseBullet bullet = UDEBulletPool.Instance.GetBullet(baseBullets[0]);
         *      UDEBulletMovement movement = UDEPolarMovementBuilder.Create().RadialSpeed(BulletSpeed).InitialAngle(i * AngleDeg + AngleRef).Build();
         *      Vector2 origin = originEnemy.transform.position;
         *      var formLocTuple = UDEMath.Polar2Cartesian(0.7f, movement.angle);
         *      Vector2 formLocation = new Vector2(formLocTuple.x, formLocTuple.y) + origin;
         *      bullet.Initialize(formLocation, origin, 0, originEnemy, this, true, movement);
         *  }
         *  AngleRef += RefOmega;
         *  RefOmega += 0.2f;
         *  if (RefOmega >= 360)
         *      RefOmega -= 360;
         *  if (AngleRef >= 360)
         *      AngleRef -= 360;
         *  yield return StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.07f, UDETime.TimeScale.ENEMY));
         * }
         */

        float angle = 360f / NumberOfBullets;

        var result = UDETransitionHelper.MoveTo(originEnemy.gameObject, (Vector2)Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.85f)), 1.5f, UDETransitionHelper.easeOutCubic, UDETime.TimeScale.ENEMY, true);

        yield return(new WaitUntil(() => result.EndTransition));

        yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.5f, UDETime.TimeScale.ENEMY)));

        for (int i = 0; true; i++)
        {
            float extraAngle = Random.Range(-3f, 3f);

            UDECartesianPolarMovementBuilder builder       = UDECartesianPolarMovementBuilder.Create().Speed(BulletSpeed);
            UDECartesianPolarMovementBuilder builderSlower = UDECartesianPolarMovementBuilder.Create(true).TangentialAccel(-8).MinSpeed(BulletSpeed * 0.6f).StartTime(0.3f);
            for (int j = 0; j < NumberOfBullets; j++)
            {
                UDEAbstractBullet bullet       = UDEBulletPool.Instance.GetBullet(patternBullets[0]);
                UDEBulletMovement movement     = builder.Angle(extraAngle + angle * j).Build();
                UDEBulletMovement movementSlow = builderSlower.Angle(extraAngle + angle * j).Build();
                Vector2           origin       = originEnemy.transform.position;
                Vector2           formLocation = UDEMath.Polar2Cartesian(0.7f, movement.angle).ToVector2() + origin;
                bullet.Initialize(formLocation, origin, 0, originEnemy, this, new UDEBulletMovement[] { movement, movementSlow });
                if (i % 4 == 0)
                {
                    UDEAbstractBullet extraBullet = UDEBulletPool.Instance.GetBullet(patternBullets[1]);
                    UDEBulletMovement movement2   = builder.Speed(BulletSpeed * 0.35f).Angle(extraAngle + angle * j).Build();
                    builder.Speed(BulletSpeed);
                    extraBullet.Initialize(formLocation, origin, 0, originEnemy, this, movement2);
                }
            }
            if (i % 4 == 0)
            {
                switch ((i % 16) / 4)
                {
                case 0:
                case 3:
                    UDETransitionHelper.MoveAmount(originEnemy.gameObject, new Vector2(2, 0), 0.95f, UDETransitionHelper.easeOutQuad, UDETime.TimeScale.ENEMY, true);
                    break;

                case 1:
                case 2:
                    UDETransitionHelper.MoveAmount(originEnemy.gameObject, new Vector2(-2, 0), 0.95f, UDETransitionHelper.easeOutQuad, UDETime.TimeScale.ENEMY, true);
                    break;
                }
            }


            yield return(StartCoroutine(UDETime.Instance.WaitForScaledSeconds(0.25f, UDETime.TimeScale.ENEMY)));
        }
    }