예제 #1
0
        //constructor takes a factory (because we have already created this in Game and dont want to create a second one)
        public EnemySpawner(Factory factory_, EnemySpawnRules esr_, uint timerIntervalMs_, uint startTimerms_, Circle spawnCircle_, int pointsToSpend_)
        {
            pointsToSpend = pointsToSpend_;

            //numEnemiesSpawned = 0;
            //numEnemiesToSpawn = numEnemiesToSpawn_;

            //assign classwide variables
            spawnCircle  = spawnCircle_;
            esr          = esr_;
            factoryOrder = factory_;

            //create the timer that will control when enemies are created.
            spawnTimer = new System.Timers.Timer(timerIntervalMs_);

            //the timer controlling when we stop spawning
            //stopTimer = new System.Timers.Timer(stopTimerMs_);

            //when do we kick it off?
            startTimer = new System.Timers.Timer(startTimerms_);

            //this line adds the SpawnEnemy envent handler (see SpawnEnemy function) that fires when the spawnTimer fires
            spawnTimer.Elapsed += SpawnEnemy;
            //stopTimer.Elapsed += StopSpawner;
            startTimer.Elapsed += Start;

            //where do we want to spawn them from?
            spawnPoint = spawnCircle.RandomPoint();

            //kick off the timer
            startTimer.Start();
            //spawnTimer.Start();

            timerStopped = false;
        }
예제 #2
0
        private void InitEnemySpawnRules()
        {
            Dice dice = new Dice(1, 100);

            {
                //50% Ghoul, 50% Running Ghoul
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.GHOUL);
                rules.SetEnemyRule(ENEMY_TYPE.RUNNING_GHOUL, 50, 50);
                spawnRulesList.Add(rules);
            }

            {
                //70% SKELETON_KNIGHT, 30% WEREWOLF
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.SKELETON_KNIGHT);
                rules.SetEnemyRule(ENEMY_TYPE.WEREWOLF, 70, 30);
                spawnRulesList.Add(rules);
            }

            {
                //10% Green Dragon, 40% HEAVY_ZOMBIE, 40% SKELETON KNIGHT
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.HEAVY_ZOMBIE);
                rules.SetEnemyRule(ENEMY_TYPE.GREEN_DRAGON, 0, 10);
                rules.SetEnemyRule(ENEMY_TYPE.SKELETON_KNIGHT, 10, 30);
                spawnRulesList.Add(rules);
            }

            {
                //100% RUNNING GHOUL
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.RUNNING_GHOUL);
                spawnRulesList.Add(rules);
            }
        }
예제 #3
0
        //public void CreateTestWave()
        //{
        //    uint spawnNumber = 0;
        //    const uint SPAWN_INTERVAL = 5000;
        //    const uint TIMER_INTERVAL = 350;
        //    const float ENEMIES_WAVE_ONE = 5.0f;
        //    const float ENEMIES_INCREMENTER = 0.6f;
        //    const float ENEMIES_WAVE_END = 50.0f;

        //    //const float ENEMIES_WAVE_ONE = 1.0f;
        //    //const float ENEMIES_INCREMENTER = 0.6f;
        //    //const float ENEMIES_WAVE_END = 1.5f;

        //    //had to move CreatePlayer here as the creation of the spawn circle needs it to exist.
        //    CreatePlayer();

        //    //even though these enemySpawner instances instantly go out of scope. they are not destroyed while their timers are running.
        //    for (float i = ENEMIES_WAVE_ONE; i < ENEMIES_WAVE_END; i += ENEMIES_INCREMENTER)
        //    {
        //        //grab a random rules
        //        EnemySpawnRules rules = spawnRulesList[spawnRulesSelector.Roll()];

        //        Circle circle = new Circle(new Vector2(gameAssets.TowerListItem(0).X, gameAssets.TowerListItem(0).Y), 400.0);
        //        EnemySpawner enemySpawner = new EnemySpawner(this, rules, TIMER_INTERVAL, (uint)(spawnNumber * SPAWN_INTERVAL) + 1, (uint)i * 2, circle);
        //        ++spawnNumber;
        //    }
        //}

        public List <EnemySpawner> GenerateWave(int pointsToSpendPerSpawner_, int numOfSpawners_, int timeBetweenSpawners_)
        {
            List <EnemySpawner> wave  = new List <EnemySpawner>();
            uint       spawnNumber    = 0;
            const uint TIMER_INTERVAL = 350;

            //even though these enemySpawner instances instantly go out of scope. they are not destroyed while their timers are running.
            for (float i = 1; i < numOfSpawners_; ++i)
            {
                //grab a random rules
                EnemySpawnRules rules = spawnRulesList[spawnRulesSelector.Roll()];

                Circle       circle       = new Circle(new Vector2(gameAssets.TowerListItem(0).X, gameAssets.TowerListItem(0).Y), 600.0);
                uint         startTimerMS = (uint)(spawnNumber * timeBetweenSpawners_) + 1;
                EnemySpawner enemySpawner = new EnemySpawner(this, rules, TIMER_INTERVAL, startTimerMS, circle, pointsToSpendPerSpawner_);
                wave.Add(enemySpawner);
                ++spawnNumber;
            }
            return(wave);
        }
예제 #4
0
        private void InitEnemySpawnRules()
        {
            Dice dice = new Dice(1, 100);

            {
                //50% Ghoul, 50% Running Ghoul
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.GHOUL);
                rules.SetEnemyRule(ENEMY_TYPE.RUNNING_GHOUL, 50, 50);
                spawnRulesList.Add(rules);
            }

            {
                //70% SKELETON_KNIGHT, 30% WEREWOLF
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.SKELETON_KNIGHT);
                rules.SetEnemyRule(ENEMY_TYPE.WEREWOLF, 70, 30);
                spawnRulesList.Add(rules);
            }

            {
                //10% Green Dragon, 40% HEAVY_ZOMBIE, 40% SKELETON KNIGHT
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.HEAVY_ZOMBIE);
                rules.SetEnemyRule(ENEMY_TYPE.GREEN_DRAGON, 0, 10);
                rules.SetEnemyRule(ENEMY_TYPE.SKELETON_KNIGHT, 10, 30);
                spawnRulesList.Add(rules);
            }

            {
                //100% RUNNING GHOUL
                EnemySpawnRules rules = new EnemySpawnRules(dice, ENEMY_TYPE.RUNNING_GHOUL);
                spawnRulesList.Add(rules);
            }
        }