コード例 #1
0
        public void Spawn(GameTime gametime)
        {
            if (mSpawnIntervalMillis <= 0)
            {
                mSpawnIntervalMillis = mRandom.Next(1000, 10000);
            }

            if ((int)gametime.TotalGameTime.TotalMilliseconds % mSpawnIntervalMillis != 0)
            {
                return;
            }

            var index = mRandom.Next(mAi.GetSpawners().Count);

            foreach (var spawner in mAi.GetSpawners()[index])
            {
                var enemyUnit = spawner.SpawnEnemy(EEnemyType.Attack,
                                                   mDirector.GetStoryManager.Level.Camera,
                                                   mDirector.GetStoryManager.Level.Map,
                                                   mDirector.GetStoryManager.Level.GameScreen);

                mEnemyUnits.Add(enemyUnit);
            }

            mSpawnIntervalMillis = 0;
        }
コード例 #2
0
        public void Spawn(GameTime gametime)
        {
            if ((int)gametime.TotalGameTime.TotalMilliseconds % SpawnIntervalMillis != 0)
            {
                return;
            }

            foreach (var spawner in mAi.GetSpawners())
            {
                var enemyUnit = spawner.SpawnEnemy(mDirector.GetStoryManager.Level.Camera,
                                                   mDirector.GetStoryManager.Level.Map,
                                                   mDirector.GetStoryManager.Level.GameScreen);

                mEnemyUnits.Add(enemyUnit);
            }
        }
コード例 #3
0
        public void CreateNewBase(GameTime gametime)
        {
            if (mBaseCount > 0 && !mActive)
            {
                // don't build any further bases when the AI isn't active.
                return;
            }

            if (!(mDirector.GetMilitaryManager.PlayerPlatformCount > PlatformCountNewBaseTrigger * mBaseCount ||
                  mDirector.GetMilitaryManager.PlayerDefensePlatformCount > DefensePlatformCountNewBaseTrigger * mBaseCount))
            {
                return;
            }

            var requestNewPlatform = false;

            Pair <Triple <CommandCenter, List <PlatformBlank>, List <Road> >, Rectangle> baseToAdd;

            do
            {
                baseToAdd = StructureLayoutHolder.GetStructureOnMap(mAi.Difficulty, ref mDirector);

                // make sure the base is atleast a certain distance away from the player at start
                if (Vector2.Distance(
                        mDirector.GetStoryManager.StructureMap.GetPlatformList().First().AbsolutePosition,
                        new Vector2(baseToAdd.GetSecond().Center.X, baseToAdd.GetSecond().Center.Y)) < FirstBaseDistance)
                {
                    requestNewPlatform = true;
                    continue;
                }

                // make sure the new structure doesn't overlap with an existing enemy structure
                if (mBaseCount <= 0)
                {
                    break;
                }

                foreach (var rect in mCollidingRects)
                {
                    if (!rect.Intersects(baseToAdd.GetSecond()))
                    {
                        continue;
                    }

                    requestNewPlatform = true;
                    break;
                }
            } while (requestNewPlatform);

            mAi.AddStructureToGame(baseToAdd.GetFirst(), baseToAdd.GetSecond());

            mCollidingRects.Add(baseToAdd.GetSecond());

            var spawners = mAi.GetSpawners();

            if (spawners.Count <= mBaseCount || spawners[mBaseCount].Count <= 0)
            {
                // we don't have any spawners available in the given structure thus not able to spawn any enemy units.
                mBaseCount++;
                return;
            }

            SpawnOneUnit(EEnemyType.Scout, mAi.GetSpawners()[mBaseCount][0]);

            // also generate some defending units, note that these don't move away from their base, but are more or less stationary defenders.
            SpawnOneUnit(EEnemyType.Defend, mAi.GetSpawners()[mBaseCount][0]);
            SpawnOneUnit(EEnemyType.Defend, mAi.GetSpawners()[mBaseCount][0]);
            SpawnOneUnit(EEnemyType.Defend, mAi.GetSpawners()[mBaseCount][0]);
            SpawnOneUnit(EEnemyType.Defend, mAi.GetSpawners()[mBaseCount][0]);
            SpawnOneUnit(EEnemyType.Defend, mAi.GetSpawners()[mBaseCount][0]);

            mBaseCount++;
        }