Esempio n. 1
0
        /// <summary>
        /// Concurrently run the next wave in the queue
        /// </summary>
        /// <returns></returns>
        public bool StartNextWave()
        {
            if (this.waveQueue.Count < 1)
            {
                return(false);
            }
            this.lockmanager = true;
            SpriteWave next = this.waveQueue.Dequeue();

            next.StartConcurrent();
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Enqueue a wave
        /// </summary>
        /// <param name="wave"></param>
        /// <param name="begin_time_seconds"></param>
        public void Enqueue(SpriteWave wave)
        {
            if (lockmanager)
            {
                throw new Exception("You cannot add waves once they have started spawning!");
            }

            wave.WaveID = this.cid;
            this.cid++;
            wave.Spawn         += spawnEnemy;
            wave.SpawnFinished += this.waveSpawnFinished;
            wave.WaveFinished  += this.waveFinished;
            this.waveQueue.Enqueue(wave);
        }
Esempio n. 3
0
        public static SpriteWave Load(string file, string solution_directory = null)
        {
            XmlDocument doc = new XmlDocument();

            // Attempt to load the xml document, or throw an exception
            if (solution_directory == null)
            {
                try { doc.Load(VisualStudioProvider.TryGetSolutionDirectoryInfo() + exepath + file); }
                catch { throw new Exception("WaveScriptParser: Error Loading: " + file + " at: " + Environment.NewLine + VisualStudioProvider.TryGetSolutionDirectoryInfo() + exepath + file + Environment.NewLine); }
            }
            else
            {
                try { doc.Load(solution_directory + exepath + file); }
                catch { throw new Exception("WaveScriptParser: Error Loading: " + file + " at: " + Environment.NewLine + " " + solution_directory + " " + exepath + file + Environment.NewLine); }
            }

            // Validate the structure of all Waves
            foreach (XmlNode entity in doc.DocumentElement.ChildNodes)
            {
                string e;
                if (!ValidateWaveStructure(entity, out e))
                {
                    throw new Exception("WaveScriptParser: Wave structure invalid." + Environment.NewLine + e + Environment.NewLine);
                }
            }

            SpriteWave wave = new SpriteWave();

            LogConsole.Log("PARSER: --------------------------------");
            // Parse each entity and add to the Sprite Wave
            foreach (XmlNode entity in doc.DocumentElement.ChildNodes)
            {
                ParseEntity(entity, ref wave);
                LogConsole.Log(Environment.NewLine);
            }
            LogConsole.Log("----------------------------------------");
            return(wave);
        }
 public WaveFinishedEventArgs(SpriteWave wave, int waveID)
 {
     this.wave = wave; this.waveID = waveID;
 }
Esempio n. 5
0
        /// <summary>
        /// Parse an entity entry and add to the wave.
        /// </summary>
        /// <param name="ef"></param>
        /// <param name="sf"></param>
        /// <param name="wave"></param>
        private static void ParseEntity(XmlNode entity, ref SpriteWave wave)
        {
            // Spawners for this entity
            List <BulletSpawner> new_spawners = null;
            // Factories
            StandardEntityFactory   ef = new StandardEntityFactory();
            StandardMovementFactory mf = new StandardMovementFactory();
            // Default Values
            int     timesec = 0, lifespan = 0, speed = 0, health = 1;
            Vector2 pos = Vector2.Zero;

            EntityFactory.EntitiyType    etype = EntityFactory.EntitiyType.Grunt1;
            MovementFactory.MovementType mtype = MovementFactory.MovementType.None;
            // Sprites
            Entity e = null;

            foreach (XmlNode att in entity.ChildNodes)
            {
                switch (att.Name)
                {
                case "timeseconds":
                    timesec = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Wave time seconds: " + timesec.ToString());
                    break;

                case "movement":
                    mtype = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Movement type: " + mtype.ToString());
                    break;

                case "lifespan":
                    lifespan = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Lifespan seconds: " + lifespan.ToString());
                    break;

                case "speed":
                    speed = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Speed: " + speed.ToString());
                    break;

                case "health":
                    health = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Health: " + health.ToString());
                    break;

                case "position":
                    pos = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Initial position: " + pos.ToString());
                    break;

                case "type":
                    etype = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Entity type: " + etype.ToString());
                    break;

                default:
                    break;
                }
            }
            e                 = ef.CreateEnemy(etype);
            e.Speed           = (uint)speed;
            e.LifeSpan        = (uint)lifespan;
            e.Health          = health;
            e.Position        = pos;
            e.WaveTimeSeconds = timesec;
            e.Movement        = mf.CreateMovement(mtype, e);
            wave.AddEntitiy(e);

            foreach (XmlNode att in entity.ChildNodes)
            {
                if (att.Name == "spawners")
                {
                    new_spawners = ParseSpawners(att, e);
                    break;
                }
            }
            foreach (BulletSpawner s in new_spawners)
            {
                wave.AddSpawner(s);
            }
        }