Exemple #1
0
        //constructor
        public EnemyManager(Texture2D enemySprite, Rectangle enemytarget, Hive homeBase, int screenWidth, int screenHeight)
        {
            this.enemySprite = enemySprite;
            target           = enemytarget;
            this.homeBase    = homeBase;
            waveManager      = new WaveManager();
            enemies          = new List <Enemy>();

            spawnPhase = false;
            spawnRate  = 30;
            currentCD  = 0;

            maxWidth  = screenWidth;
            maxHeight = screenHeight;

            rng = new Random();
        }
Exemple #2
0
        //methods
        /// <summary>
        /// start spawnning the enemies
        /// </summary>
        public void Spawn()
        {
            //cooldown timer for spawning
            if (currentCD > 0)
            {
                currentCD--;
            }
            else
            {
                //is it currently not between waves (is it time to spawn a wave in)
                if (spawnPhase)
                {
                    //does the wave currently still have enemies to spawn
                    if (waveManager.enemyStack.Count > 0)
                    {
                        //spawn the enemies at locations the text file says
                        int intSpawnRNG = rng.Next(30, 71);

                        double spawnRNG = (double)intSpawnRNG / 100;

                        int       rngPos;
                        Rectangle spawnLocation;
                        switch (waveManager.enemyStack.Pop())
                        {
                        case 'T':
                            rngPos        = (int)(maxWidth * spawnRNG);
                            spawnLocation = new Rectangle(rngPos, 0, 75, 75);
                            enemies.Add(new Enemy(enemySprite, spawnLocation, target, 'T'));
                            break;

                        case 'B':
                            rngPos        = (int)(maxWidth * spawnRNG);
                            spawnLocation = new Rectangle(rngPos, maxHeight, 75, 75);
                            enemies.Add(new Enemy(enemySprite, spawnLocation, target, 'B'));
                            break;

                        case 'L':
                            rngPos        = (int)(maxHeight * spawnRNG);
                            spawnLocation = new Rectangle(0, rngPos, 75, 75);
                            enemies.Add(new Enemy(enemySprite, spawnLocation, target, 'L'));
                            break;

                        case 'R':
                            rngPos        = (int)(maxHeight * spawnRNG);
                            spawnLocation = new Rectangle(maxWidth, rngPos, 75, 75);
                            enemies.Add(new Enemy(enemySprite, spawnLocation, target, 'R'));
                            break;

                        default:
                            break;
                        }
                    }
                    else //no more enemies in this wave
                    {
                        spawnPhase = false;
                    }
                    //cooldown between each spawn
                    currentCD = spawnRate;
                }
                else
                {
                    //are there no more enemies in the current wave
                    if (enemies.Count <= 0)
                    {
                        currentCD  = waveCD;    //wave cooldown
                        spawnPhase = true;
                        WaveManager.NextWave(); //prepares next wave

                        //debug
                        Console.WriteLine("next wave");
                    }
                }
            }
        }