コード例 #1
0
        /// <summary>
        /// Reads events which update game-lists. Excluding additions and removals
        /// </summary>
        /// <param name="queue"></param>
        private void ReadUpdateQueue(ConcurrentQueue <EventArgs> queue)
        {
            int count = queue.Count;

            for (int i = 0; i < count; i++)
            {
                EventArgs e;
                if (queue.TryDequeue(out e))
                {
                    if (e is RespawnEventArgs) //respawn
                    {
                        this.ReadRespawnEvent((RespawnEventArgs)e);
                        LogConsole.Log("Enitiy Respawn Event.");
                        continue;
                    }
                    if (e is GameOverEventArgs) //game over
                    {
                        this.ReadGameOverEvent((GameOverEventArgs)e);
                        LogConsole.Log("Game Over Event.");
                        continue;
                    }
                    throw new Exception("EntitiyManager: ReadUpdateQueue: Non-Recognized EventArgs");
                }
            }
        }
コード例 #2
0
ファイル: Grunt1.cs プロジェクト: diwashbiswa/487-Project
 public override void Collide(Sprite sender, EventArgs e)
 {
     if (sender is Bullet)
     {
         LogConsole.LogPosition("Grunt1 was hit by player", this.X, this.Y);
         this.TakeDamage(1);
     }
 }
コード例 #3
0
        /// <summary>
        /// Add Reward lives during the game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void RewardEvent(Player invoker)
        {
            Random random = new Random();

            if (invoker.Health <= 4 && (1 % random.Next(1, 3) == 0))
            {
                TextureManager text   = TextureManager.Textures;
                Reward         reward = new Reward(new Vector2(500, 300), text.Get(TextureManager.Type.Reward), 5, 5);
                int            x      = random.Next(0, 720);
                int            y      = random.Next(0, 400);

                reward.Position = new Vector2(x, y);
                reward.Dispose += this.Dispose;
                this.ReadyEnqueue(reward, new AddRewardEventArgs(reward));

                LogConsole.Log("Random Reward Event");
            }
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: diwashbiswa/487-Project
        public override void Collide(Sprite sender, EventArgs e)
        {
            if (sender is Bullet)
            {
                this.TakeDamage(1);
                base.InvokeCollide(this, new EntityCollideEventArgs(this, (Bullet)sender));
            }

            if (sender is Entity)
            {
                Entity k = (Entity)sender;
                this.Position += ((k.Position - this.Position) * (float)(-0.5f * k.Speed));
            }

            if (sender is Reward)
            {
                this.Health += 1;
                LogConsole.Log("Player collided with reward - health + 1!");

                Reward r = (Reward)sender;
                r.InvokeDispose(r, new DisposeEventArgs(r));
            }
        }
コード例 #6
0
        /// <summary>
        /// Handles Collision events invoked from Entitiy types
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Collided(object sender, EntityCollideEventArgs e)
        {
            if (e.Victim is Player)
            {
                Player player = (Player)e.Victim;

                if (e.Attacker is Bullet)
                {
                    if (!player.Invincible)
                    {
                        this.updateQueue.Enqueue(new RespawnEventArgs(player, new Vector2(600, 600)));

                        this.RewardEvent(player);
                    }

                    LogConsole.Log("Player has been hit");
                    return;
                }

                throw new NotImplementedException("EntitiyManager: Collided(): Non-Bullet Attacker");
            }

            throw new NotImplementedException("EntityManager: Collided(): Non-Player Victim");
        }
コード例 #7
0
 /// <summary>
 /// All enemies are dead in the final wave
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void FinalWaveFinished(object sender, WaveFinishedEventArgs e)
 {
     LogConsole.Log("Final wave has been completed.");
     // No more enemies in the final wave.. player wins.
     this.updateQueue.Enqueue(new GameOverEventArgs(true));
 }
コード例 #8
0
 /// <summary>
 /// All enemies are dead in some wave
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void WaveFinished(object sender, WaveFinishedEventArgs e)
 {
     LogConsole.Log("Wave: " + e.WaveID.ToString() + " has been completed.");
     // all enemies in current wave are dead.. start next wave.
     this.waveManager.StartNextWave();
 }
コード例 #9
0
 /// <summary>
 /// Final wave has finished spawning
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void FinalWaveSpawnFinished(object sender, SpawnFinishedEventArgs e)
 {
     LogConsole.Log("Final Wave spawn finished.");
 }
コード例 #10
0
 /// <summary>
 /// Some wave has finished spawning
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void WaveSpawnFinished(object sender, SpawnFinishedEventArgs e)
 {
     LogConsole.Log("Wave: " + e.WaveID.ToString() + " finished spawning.");
 }
コード例 #11
0
        /// <summary>
        /// Insert sprites into game-lists from a concurrent queue
        /// </summary>
        /// <param name="queue"></param>
        private void ReadReadyQueue(ConcurrentQueue <EventArgs> queue)
        {
            int TESTING_bullets = 0;

            int count = queue.Count;

            for (int i = 0; i < count; i++)
            {
                EventArgs e;
                if (queue.TryDequeue(out e))
                {
                    if (e is AddBulletEventArgs) //add bullet
                    {
                        this.ReadBullet((AddBulletEventArgs)e);
                        TESTING_bullets++;
                        continue;
                    }
                    if (e is AddPlayerEventArgs) //add player
                    {
                        var p = (AddPlayerEventArgs)e;
                        this.SubscribeAll(p.Player);
                        this.players.Add(p.Player);
                        LogConsole.Log("New Player added.");
                        continue;
                    }
                    if (e is AddEnemyEventArgs) //add enemy
                    {
                        var p = (AddEnemyEventArgs)e;
                        // subscribe and add enemy
                        this.SubscribeAll(p.Enemy);
                        this.entities.Add(p.Enemy);
                        LogConsole.Log("New Enemy added.");
                        // Add the health bar
                        HealthBarComponent hbc = new HealthBarComponent(p.Enemy);
                        eventManager.ReadyEnqueue(hbc, new AddGUIEventArgs(hbc, p.Enemy));
                        hbc.Dispose += this.eventManager.Dispose;
                        LogConsole.Log("New Health Bar Component added.");
                        continue;
                    }
                    if (e is AddSpawnerEventArgs) //add spawner
                    {
                        var p = (AddSpawnerEventArgs)e;
                        p.Spawner.parent = p.Parent;
                        this.SubscribeAll(p.Spawner);
                        this.spawners.Add(p.Spawner);
                        LogConsole.Log("New Spawner added.");
                        continue;
                    }
                    if (e is AddRewardEventArgs) //add reward
                    {
                        var p = (AddRewardEventArgs)e;
                        this.SubscribeAll(p.Reward);
                        this.rewards.Add(p.Reward);
                        LogConsole.Log("New Reward added.");
                        continue;
                    }
                    if (e is AddGUIEventArgs)
                    {
                        this.ReadGUIComponent((AddGUIEventArgs)e);
                        LogConsole.Log("GUI component added.");
                        continue;
                    }
                    throw new Exception("EntitiyQueueManager: ReadReadyQueue(): Unrecognized EventArgs");
                }
            }
            if (TESTING_bullets > 0)
            {
                LogConsole.Log(TESTING_bullets.ToString() + " Bullets were fired.");
            }
        }
コード例 #12
0
        /// <summary>
        /// Remove sprites from game-lists from a concurrent queue
        /// </summary>
        /// <param name="queue"></param>
        private void ReadDisposeQueue(ConcurrentQueue <DisposeEventArgs> queue)
        {
            int TESTING_bullets = 0;
            int count           = queue.Count;

            for (int i = 0; i < count; i++)
            {
                DisposeEventArgs e;
                Sprite           s;
                if (queue.TryDequeue(out e))
                {
                    s = e.Sprite;
                    if (s == PlayerOne)
                    {
                        return;
                    }
                    if (this.entities.Contains(s)) //entities
                    {
                        this.entities.Remove((Entity)s);
                        LogConsole.Log("Entitiy Disposed");

                        if (this.spawners.RemoveAll(x => x.parent == s) > 0)
                        {
                            LogConsole.Log("Spawner(s) Disposed.");
                        }
                    }
                    if (this.players.Contains(s)) // players
                    {
                        this.players.Remove((Entity)s);
                        LogConsole.Log("Player Disposed.");
                    }
                    if (s is Bullet) // bullets
                    {
                        if (this.player_bullets.Contains(s))
                        {
                            this.player_bullets.Remove((Bullet)s);
                        }

                        if (this.enemy_bullets.Contains(s))
                        {
                            this.enemy_bullets.Remove((Bullet)s);
                        }
                        TESTING_bullets++;
                    }
                    if (s is Reward)
                    {
                        if (this.rewards.Contains(s))
                        {
                            this.rewards.Remove((Reward)s);
                            LogConsole.Log("Reward live Disposed.");
                        }
                    }
                    if (s is HealthBar)
                    {
                        HealthBar h = (HealthBar)s;
                        this.gui_components.Remove(h.Parent);
                    }
                }
            }
            if (TESTING_bullets > 0)
            {
                LogConsole.Log(TESTING_bullets.ToString() + " Bullets Disposed.");
            }
        }
コード例 #13
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);
            }
        }
コード例 #14
0
        /// <summary>
        /// Parse the spawners attribute of a wave
        /// </summary>
        /// <param name="spawners"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private static List <BulletSpawner> ParseSpawners(XmlNode spawners, Entity e)
        {
            List <BulletSpawner>    new_spawners = new List <BulletSpawner>();
            StandardSpawnerFactory  sf           = new StandardSpawnerFactory();
            StandardMovementFactory mf           = new StandardMovementFactory();

            SpawnerFactory.SpawnerType   stype         = SpawnerFactory.SpawnerType.None;
            MovementFactory.MovementType spawner_mtype = MovementFactory.MovementType.Mirror;
            SpawnerFactory.BulletType    btype         = SpawnerFactory.BulletType.Green;
            Movement      spawnermovement = null;
            double        firerate        = 1.0d;
            double        bulletspeed     = 7.0f;
            double        bulletlifespan  = 10.0f;
            int           timesec         = e.WaveTimeSeconds;
            BulletSpawner s = null;

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

                    case "spawnertype":
                        stype = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner type: " + stype.ToString());
                        break;

                    case "firerate":
                        firerate = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Firerate: " + firerate.ToString());
                        break;

                    case "bullettype":
                        btype = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Bullet type: " + btype.ToString());
                        break;

                    case "spawnermovement":
                        spawner_mtype = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner movement type: " + spawner_mtype.ToString());
                        break;

                    case "bulletspeed":
                        bulletspeed = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner bullet speed: " + bulletspeed.ToString());
                        break;

                    case "bulletlifespan":
                        bulletlifespan = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner bullet lifespan: " + bulletlifespan.ToString());
                        break;
                    }
                }
                if (stype != SpawnerFactory.SpawnerType.None)
                {
                    s = sf.CreateSpawner(stype, e, btype);
                    s.BulletLifeSpan           = (float)bulletlifespan;
                    s.FireRateSeconds          = firerate;
                    s.BulletSpeed              = (float)bulletspeed;
                    s.WaveTimeSeconds          = timesec;
                    spawnermovement            = mf.CreateMovement(spawner_mtype, e);
                    spawnermovement.ThisSprite = s;
                    s.Movement = spawnermovement;
                    new_spawners.Add(s);
                }
            }
            return(new_spawners);
        }