This is a game component that implements IUpdateable.
Inheritance: Microsoft.Xna.Framework.DrawableGameComponent, ISpellHandler
Example #1
0
        public LevelState(Game game)
            : base(game)
        {
            // TODO: Construct any child components here

            player = new Player(game);
            camera = new Camera(game);
            scenery = new Scenery(game);
            castleHandler = new CastleHandler(game);
            spellHandler = new SpellHandler(game);
            enemyHandler = new EnemyHandler(game);

            fireBallParticles = new FireParticleSystem(game, game.Content);
            slowEnemyParticles = new SlowParticleSystem(game, game.Content);
            poisonEnemyParticles = new PoisonParticleSystem(game, game.Content);
            magicMissilePartilces = new MagicMissileParticleSystem(game, game.Content);
            dirtPartilces = new DirtParticleSystem(game, game.Content);

            spellIcons = new List<Texture2D>();
        }
 public void LearnSpell(SpellHandler.Spells learn)
 {
     learnedSpells.Add(learn);
 }
        public void IsCollidingWithSpell(SpellHandler spellHandler)
        {
            IPlayer player = (IPlayer)Game.Services.GetService(typeof(IPlayer));

            foreach (Enemy e in enemies)
            {
                foreach (Spell s in spellHandler.SpellList)
                {
                    if (e.IsColliding(s))
                    {
                        if (s.Active)
                        {
                            // is player immune to the spells alignment?
                            bool isImune = false;
                            foreach (Spell.Alignments immune in e.ImuneAlignments)
                            {
                                if (immune == s.Alignment)
                                {
                                    isImune = true;
                                }
                            }

                            if (!isImune)
                            {
                                switch (s.Alignment)
                                {
                                    case Spell.Alignments.Damage:
                                        {
                                            e.Health -= Convert.ToInt32((s.BaseDamage * (player.Intelligence * 0.1f)));
                                            break;
                                        }
                                    case Spell.Alignments.Poison:
                                        {

                                            e.AlignmentsList.Add(Spell.Alignments.Poison);
                                            break;
                                        }
                                    case Spell.Alignments.Slow:
                                        {
                                            e.AlignmentsList.Add(Spell.Alignments.Slow);
                                            break;
                                        }
                                }
                            }

                            if (!s.DestoryOnHit)
                            {
                                s.BaseDamage = 0;
                                s.Active = false;
                            }
                        }

                        if (e.Health <= 0)
                        {
                            e.Active = false;
                            if (!s.DestoryOnHit)
                            {
                                s.Active = false;
                            }
                            player.Score += e.Score;
                            player.Xp += e.Xp;
                            player.Gold += e.Loot;
                        }
                    }
                }
            }
        }
        public void IsCollidingWithSpell(SpellHandler spellHandler)
        {
            IPlayer player = (IPlayer)Game.Services.GetService(typeof(IPlayer));

            foreach (Enemy e in enemies)
            {
                foreach (Spell s in spellHandler.SpellList)
                {
                    if (e.IsColliding(s))
                    {
                        if (s.Active)
                        {
                            // is player immune to the spells alignment?
                            bool isImune = false;
                            foreach (Spell.Alignments immune in e.ImuneAlignments)
                            {
                                if (immune == s.Alignment)
                                {
                                    isImune = true;
                                }
                            }

                            if (!isImune)
                            {
                                switch (s.Alignment)
                                {
                                case Spell.Alignments.Damage:
                                {
                                    e.Health -= Convert.ToInt32((s.BaseDamage * (player.Intelligence * 0.1f)));
                                    break;
                                }

                                case Spell.Alignments.Poison:
                                {
                                    e.AlignmentsList.Add(Spell.Alignments.Poison);
                                    break;
                                }

                                case Spell.Alignments.Slow:
                                {
                                    e.AlignmentsList.Add(Spell.Alignments.Slow);
                                    break;
                                }
                                }
                            }

                            if (!s.DestoryOnHit)
                            {
                                s.BaseDamage = 0;
                                s.Active     = false;
                            }
                        }

                        if (e.Health <= 0)
                        {
                            e.Active = false;
                            if (!s.DestoryOnHit)
                            {
                                s.Active = false;
                            }
                            player.Score += e.Score;
                            player.Xp    += e.Xp;
                            player.Gold  += e.Loot;
                        }
                    }
                }
            }
        }