Esempio n. 1
0
        private IEnumerator EasyDifficulty()
        {
            EnemyPool _enemyNorm = Program.PoolManager.GetPool <EnemyPool>("Enemy_1");

            StateMachinePool poolNmy1Up   = Program.PoolManager.GetPool <StateMachinePool>("Enemy_1_1_Up");
            StateMachinePool poolNmy1Down = Program.PoolManager.GetPool <StateMachinePool>("Enemy_1_1_Down");


            StateMachinePool poolNmy2Up   = Program.PoolManager.GetPool <StateMachinePool>("Enemy_1_Sine_Up");
            StateMachinePool poolNmy2Down = Program.PoolManager.GetPool <StateMachinePool>("Enemy_1_Sine_Down");


            StateMachinePool poolNmyFinalUp   = Program.PoolManager.GetPool <StateMachinePool>("Enemy_1_Final_Up");
            StateMachinePool poolNmyFinalDown = Program.PoolManager.GetPool <StateMachinePool>("Enemy_1_Final_Down");

            yield return(Program.UpdateTime.WaitForSeconds(2.0f));

            float time          = 0;
            float spawnInterval = 0.15f;

            Enemy nmy;

            int squareX = 4;
            int squareY = 2;

            List <Enemy>   enemies   = new List <Enemy>();
            List <Vector2> positions = new List <Vector2>();

            for (int y = 0; y < squareY; y++)
            {
                for (int x = 0; x < squareX; x++)
                {
                    Vector2 pos = new Vector2(80 + x * 24.0f, (y + 0.65f) * 8.0f);

                    nmy = _enemyNorm.Get() as Enemy;
                    nmy.Setup(poolNmy1Up.Get() as StateMachine, 40, 1);
                    nmy.renderingOffset = 200 + (y + x);
                    enemies.Add(nmy);
                    positions.Add(pos);

                    pos.y = -pos.y;
                    nmy   = _enemyNorm.Get() as Enemy;
                    nmy.Setup(poolNmy1Down.Get() as StateMachine, 40, 1);
                    nmy.renderingOffset = 200 - (y + x);
                    enemies.Add(nmy);
                    positions.Add(pos);
                }
            }

            for (int i = 0; i < enemies.Count; i += 2)
            {
                enemies[i].Spawn(positions[i], Vector2.zero);
                enemies[i + 1].Spawn(positions[i + 1], Vector2.zero);
                yield return(Program.UpdateTime.WaitForSeconds(spawnInterval));
            }

            while (true)
            {
                bool breakThis = true;
                for (int i = enemies.Count - 1; i >= 0; i--)
                {
                    if (enemies[i].IsAlive)
                    {
                        breakThis = false; break;
                    }
                }

                if (breakThis)
                {
                    break;
                }
                yield return(null);
            }

            enemies.Clear();
            positions.Clear();

            yield return(Program.UpdateTime.WaitForSeconds(1.0f));

            spawnInterval = 0.25f;

            squareY *= 2;
            squareX *= 2;

            for (int y = 0; y < squareY; y++)
            {
                for (int x = 0; x < squareX; x++)
                {
                    Vector2 pos = new Vector2(80 + x * 8.0f, (y + 0.65f) * 4.0f);

                    nmy = _enemyNorm.Get() as Enemy;
                    nmy.Setup(poolNmy2Up.Get() as StateMachine, 40, 1);
                    nmy.renderingOffset = 200 + (y + x);
                    enemies.Add(nmy);
                    positions.Add(pos);

                    pos.y = -pos.y;
                    nmy   = _enemyNorm.Get() as Enemy;
                    nmy.Setup(poolNmy2Down.Get() as StateMachine, 40, 1);
                    nmy.renderingOffset = 200 - (y + x);
                    enemies.Add(nmy);
                    positions.Add(pos);
                }
            }

            for (int i = 0; i < enemies.Count; i += 2)
            {
                enemies[i].Spawn(positions[i], Vector2.zero);
                enemies[i + 1].Spawn(positions[i + 1], Vector2.zero);
                yield return(Program.UpdateTime.WaitForSeconds(spawnInterval));
            }

            while (true)
            {
                bool breakThis = true;
                for (int i = enemies.Count - 1; i >= 0; i--)
                {
                    if (enemies[i].IsAlive)
                    {
                        breakThis = false; break;
                    }
                }

                if (breakThis)
                {
                    break;
                }
                yield return(null);
            }

            enemies.Clear();
            positions.Clear();

            yield return(Program.UpdateTime.WaitForSeconds(1.0f));


            //Final Wave
            time = 0;
            float attackInterval   = 0.05f;
            float attackFrequency  = 2.0f;
            float attackAmplitudeY = 8;
            float attackAmplitudeX = 24f;
            int   enemyCount       = 16;
            int   countS           = 0;

            while (countS <= enemyCount)
            {
                if (time < attackInterval)
                {
                    time += Program.UpdateTime.DeltaTime;
                    yield return(null);

                    continue;
                }

                float nn = (countS / (float)enemyCount) * attackFrequency * Maths.PI;
                float x  = Maths.Cos(nn * 0.5f) * attackAmplitudeX * 2;
                float y  = Maths.Sin(nn) * attackAmplitudeY;

                Vector2 pos = new Vector2(100 + x, y);

                nmy = _enemyNorm.Get() as Enemy;
                nmy.Setup((pos.y < 0 ? poolNmyFinalDown.Get() : poolNmyFinalUp.Get()) as StateMachine, 20, 1);
                nmy.renderingOffset = 200 + (int)y;
                nmy.Spawn(pos, Vector2.zero);
                enemies.Add(nmy);

                pos = new Vector2(100 + x, -y);

                nmy = _enemyNorm.Get() as Enemy;
                nmy.Setup((pos.y < 0 ? poolNmyFinalDown.Get() : poolNmyFinalUp.Get()) as StateMachine, 20, 1);
                nmy.renderingOffset = 200 + (int)y;
                nmy.Spawn(pos, Vector2.zero);
                enemies.Add(nmy);

                countS++;
                time = 0;
                yield return(null);
            }

            while (true)
            {
                bool breakThis = true;
                for (int i = enemies.Count - 1; i >= 0; i--)
                {
                    if (enemies[i].IsAlive)
                    {
                        breakThis = false; break;
                    }
                }

                if (breakThis)
                {
                    break;
                }
                yield return(null);
            }

            enemies.Clear();

            yield return(Program.UpdateTime.WaitForSeconds(1.0f));

            _boss.Spawn(new Vector2(100, 0), Vector2.zero);
            yield return(Program.UpdateTime.WaitForSeconds(13.0f));

            _background.StartScrollSpeedFade(0.35f, 3.0f, FadingType.FADE_IN);

            while (true)
            {
                if (!_boss.IsAlive)
                {
                    break;
                }
                yield return(null);
            }
        }
Esempio n. 2
0
        private IEnumerator LaserBullets()
        {
            float interval;
            float intervalHalf;
            int   count;

            switch (CurrentAttack)
            {
            case 0:
                Program.BulletPatternManager.TryGetPattern("Boss_Laser_Up_Easy", out BulletPattern patternUp);
                Program.BulletPatternManager.TryGetPattern("Boss_Laser_Up_Easy_Rev", out BulletPattern patternDown);

                yield return(Program.UpdateTime.WaitForSeconds(1.0f));

                count = 6;

                interval     = 0.35f;
                intervalHalf = interval * 0.5f;

                bool revUp   = false;
                bool revDown = false;

                int upC   = 0;
                int downC = 0;

                float offsetPerLoop = (1.0f / count) * 2.0f;
                float offsetUp      = 0;
                float offsetDown    = offsetPerLoop;

                float angleMax  = 15.0f;
                float frequency = 0.5f;

                Vector2 dirUp   = Vector2.up;
                Vector2 dirDown = -Vector2.up;

                while (true)
                {
                    Vector2 root = _laserOffsets[0] + Position;
                    root.x -= 32;
                    float sin = Maths.Sin((Program.UpdateTime.RunTime / frequency) * Maths.PI) * angleMax;

                    Vector2 from   = root;
                    Vector2 target = new Vector2(-70, root.y);
                    float   n      = upC / (float)count;
                    patternUp?.SpawnBullets <Bullet>(this, true, Vector2.Lerp(from, target, n) + new Vector2(offsetUp, 0), dirUp.Rotate(sin), _smallBullet, 1, 0.075f, 1, 3.5f, 50);

                    upC += (revUp ? -1 : 1);
                    if (revUp ? upC <= 0 : upC >= count)
                    {
                        revUp = !revUp;
                        if (!revUp)
                        {
                            offsetUp += offsetPerLoop;
                        }
                    }
                    yield return(Program.UpdateTime.WaitForSeconds(intervalHalf));

                    root = _laserOffsets[0] + Position;
                    n    = downC / (float)count;
                    patternDown?.SpawnBullets <Bullet>(this, true, Vector2.Lerp(from, target, n) + new Vector2(offsetDown, 0), dirDown.Rotate(-sin), _smallBullet, 1, 0.075f, 1, 3.5f, 50);

                    downC += (revDown ? -1 : 1);
                    if (revDown ? downC <= 0 : downC >= count)
                    {
                        revDown = !revDown;
                        if (!revDown)
                        {
                            offsetDown += offsetPerLoop;
                        }
                    }
                    yield return(Program.UpdateTime.WaitForSeconds(intervalHalf));
                }

            case 2:
                Program.BulletPatternManager.TryGetPattern("Boss_Attack_Laser_2", out patternUp);
                //Program.BulletPatternManager.TryGetPattern("Boss_Laser_Up_Easy_Rev", out patternDown);

                yield return(Program.UpdateTime.WaitForSeconds(1.0f));

                count = 3;

                interval = 0.15f;

                intervalHalf = interval * 0.75f;

                revUp   = false;
                revDown = false;

                upC   = 0;
                downC = 0;

                offsetPerLoop = 1.25f;
                offsetUp      = 0;
                offsetDown    = offsetPerLoop;

                frequency = 0.25f;

                dirUp   = Vector2.up;
                dirDown = -Vector2.up;

                while (true)
                {
                    Vector2 root = _laserOffsets[1] + Position;
                    root.x -= 32;

                    Vector2 from   = root;
                    Vector2 target = new Vector2(-70, root.y);
                    float   n      = upC / (float)count;
                    patternUp?.SpawnBullets <Bullet>(this, true, Vector2.Lerp(from, target, n) + new Vector2(offsetUp, 0), dirUp, _smallBullet, 1, 0.075f, 1, 3.5f, 50, 1);

                    upC += (revUp ? -1 : 1);
                    if (revUp ? upC <= 0 : upC >= count)
                    {
                        revUp     = !revUp;
                        offsetUp += offsetPerLoop;
                        offsetUp  = offsetUp > 15 ? -5.0f : offsetUp;
                    }

                    yield return(Program.UpdateTime.WaitForSeconds(intervalHalf));

                    from   = root = _laserOffsets[2] + Position;
                    target = new Vector2(-70, root.y);
                    n      = 1.0f - (downC / (float)count);
                    patternUp?.SpawnBullets <Bullet>(this, true, Vector2.Lerp(from, target, n) + new Vector2(offsetDown, 0), dirDown, _smallBullet, 1, 0.075f, 1, 3.5f, 50, 1);
                    downC += (revDown ? -1 : 1);
                    if (revDown ? downC <= 0 : downC >= count)
                    {
                        revDown     = !revDown;
                        offsetDown -= offsetPerLoop;
                        offsetDown  = offsetDown < 15 ? 5.0f : offsetDown;
                    }
                    yield return(Program.UpdateTime.WaitForSeconds(intervalHalf));
                }

            case 1:
            case 3:

                Program.BulletPatternManager.TryGetPattern("Boss_Attack_Laser_2", out patternUp);
                //Program.BulletPatternManager.TryGetPattern("Boss_Laser_Up_Easy_Rev", out patternDown);

                yield return(Program.UpdateTime.WaitForSeconds(1.0f));

                count = CurrentAttack == 3 ? 10 : 8;

                interval = 0.4f;

                if (CurrentAttack == 3)
                {
                    interval *= 0.35f;
                }

                intervalHalf = interval * 0.25f;

                revUp   = false;
                revDown = false;

                upC   = 0;
                downC = 0;

                offsetPerLoop = 2.25f;
                offsetUp      = 0;
                offsetDown    = offsetPerLoop;

                angleMax  = 25.0f;
                frequency = 0.25f;

                dirUp   = Vector2.up;
                dirDown = -Vector2.up;

                while (true)
                {
                    Vector2 root = _laserOffsets[1] + Position;
                    root.x -= 32;

                    Vector2 from   = root;
                    Vector2 target = new Vector2(-70, root.y);
                    float   n      = upC / (float)count;
                    patternUp?.SpawnBullets <Bullet>(this, true, Vector2.Lerp(from, target, n) + new Vector2(offsetUp, 0), dirUp, _smallBullet, 1, 0.075f, 1, 3.5f, 50, 1);

                    upC += (revUp ? -1 : 1);
                    if (revUp ? upC <= 0 : upC >= count)
                    {
                        revUp     = !revUp;
                        offsetUp += offsetPerLoop;
                        offsetUp  = offsetUp > 15 ? -5.0f : offsetUp;
                    }

                    yield return(Program.UpdateTime.WaitForSeconds(intervalHalf));

                    from   = root = _laserOffsets[2] + Position;
                    target = new Vector2(-70, root.y);
                    n      = 1.0f - (downC / (float)count);
                    patternUp?.SpawnBullets <Bullet>(this, true, Vector2.Lerp(from, target, n) + new Vector2(offsetDown, 0), dirDown, _smallBullet, 1, 0.075f, 1, 3.5f, 50, 1);
                    downC += (revDown ? -1 : 1);
                    if (revDown ? downC <= 0 : downC >= count)
                    {
                        revDown     = !revDown;
                        offsetDown -= offsetPerLoop;
                        offsetDown  = offsetDown < 15 ? 5.0f : offsetDown;
                    }
                    yield return(Program.UpdateTime.WaitForSeconds(intervalHalf));
                }
            }
        }