Exemple #1
0
        private void SpawnEnemy(int id, SpawnPatternsInfo patternInfo)
        {
            EnemyInfo enemyInfo = DataManager.LoadEnemyInfo(id);

            switch (enemyInfo.Type)
            {
            case "Basic":
                Enemy enemy = new BasicEnemy(enemyInfo);
                enemy.Died += AwardPoints;
                enemy.SetPath(HelperClass.GetPoints(patternInfo));
                lock (EnemyListLock)
                {
                    CurrentEnemies.Add(enemy);
                }
                break;

            case "Boss":
                Boss boss = new Boss(enemyInfo);
                boss.Died += AwardPoints;
                boss.SetPath(HelperClass.GetPoints(patternInfo));
                boss.SetAllowedPath(new Point[] { HelperClass.ConvertTupleToPointWithOffset(DataManager.RetrieveLocation("UpperLeft")), HelperClass.ConvertTupleToPointWithOffset(DataManager.RetrieveLocation("UpperRight")) });
                lock (EnemyListLock)
                {
                    CurrentEnemies.Add(boss);
                }
                break;

            default:
                break;
            }
        }
Exemple #2
0
        private static Queue <Point> LineQueue(SpawnPatternsInfo info)
        {
            Queue <Point> queue = new Queue <Point>(2);

            EnqueueStringPoint(queue, info.StartPosition);
            EnqueueStringPoint(queue, info.EndPosition);
            return(queue);
        }
Exemple #3
0
        private static Queue <Point> LTopQueue(SpawnPatternsInfo info)
        {
            Queue <Point> queue = new Queue <Point>(3);

            EnqueueStringPoint(queue, info.StartPosition);
            queue.Enqueue(new Point(DataManager.RetrieveLocation(info.EndPosition).Item1 + ConstantManager.LeftOffset, DataManager.RetrieveLocation(info.StartPosition).Item2 + ConstantManager.TopOffset));
            EnqueueStringPoint(queue, info.EndPosition);
            return(queue);
        }
Exemple #4
0
        private static void PreloadSpawnPatterns()
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(SpawnPatternsLocation);
            XmlNodeList patterns = xml.SelectNodes("/Catalog/Pattern");

            AllPatterns = new SpawnPatternsInfo[patterns.Count];
            foreach (XmlNode pattern in patterns)
            {
                int id = int.Parse(pattern.Attributes["id"].Value);
                SpawnPatternsInfo info = new SpawnPatternsInfo();
                info.Id = id;
                foreach (XmlNode childNode in pattern.ChildNodes)
                {
                    switch (childNode.Name)
                    {
                    case "Amount":
                        info.EnemyCount = int.Parse(childNode.Attributes["value"].Value);
                        break;

                    case "Delay":
                        info.Delay = 1000 * (int)Math.Round(float.Parse(childNode.Attributes["value"].Value), 0);
                        break;

                    case "Type":
                        info.Type = childNode.Attributes["value"].Value;
                        break;

                    case "StartPoint":
                        info.StartPosition = childNode.Attributes["value"].Value;
                        break;

                    case "EndPoint":
                        info.EndPosition = childNode.Attributes["value"].Value;
                        break;

                    case var name when new Regex(@"_[0..9]*").IsMatch(name):
                        info.Subpatterns = info.Subpatterns ?? new List <int>();
                        info.Subpatterns.Add(int.Parse(childNode.Attributes["id"].Value));
                        break;

                    default:
                        break;
                    }
                }
                AllPatterns[id] = info;
            }
        }
Exemple #5
0
        public static Queue <Point> GetPoints(SpawnPatternsInfo info)
        {
            switch (info.Type)
            {
            case "Line":
                return(LineQueue(info));

            case "LBottom":
                return(LBottomQueue(info));

            case "LTop":
                return(LTopQueue(info));

            default:
                throw new Exception("Unknown pattern type");
            }
        }
Exemple #6
0
        private void SpawnWave(int waveCounter)
        {
            SpawnPatternsInfo patternInfo = DataManager.LoadSpawnPatternInfo(CurrentLevel.SpawnPatterns[waveCounter]);

            for (int i = 0; i < patternInfo.EnemyCount; i++)
            {
                if (!Running)
                {
                    return;
                }
                if (patternInfo.Type == "Combined")
                {
                    using (ManualResetEvent reset = new ManualResetEvent(false))
                    {
                        int remainingSubwaves = patternInfo.Subpatterns.Count;
                        var list = new List <Tuple <SpawnPatternsInfo, int> >(patternInfo.Subpatterns.Count);
                        foreach (int subpatternId in patternInfo.Subpatterns)
                        {
                            list.Add(new Tuple <SpawnPatternsInfo, int>(DataManager.LoadSpawnPatternInfo(subpatternId), waveCounter));
                        }
                        for (int j = 0; j < patternInfo.Subpatterns.Count; j++)
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback(x =>
                            {
                                SpawnSubWave((Tuple <SpawnPatternsInfo, int>)x);
                                if (Interlocked.Decrement(ref remainingSubwaves) == 0)
                                {
                                    reset.Set();
                                }
                            }), list[j]);
                        }
                        reset.WaitOne();
                    }
                }
                else
                {
                    SpawnEnemy(CurrentLevel.Enemies[waveCounter], patternInfo);
                }
                Thread.Sleep(patternInfo.Delay);
            }
        }