Ejemplo n.º 1
0
 public ShootingTrap(Level level, Point pos, FaceDirection dir)
 {
     if (dir == FaceDirection.Left)
         effects = SpriteEffects.FlipHorizontally;
     tex = level.Content.LoadTexture2D("Traps/Shooting");
     this.pos = new Vector2(pos.X + (dir == FaceDirection.Left ? 35 : 0), pos.Y + 6);
     this.level = level;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new gem.
        /// </summary>
        public Gem(Level level, Vector2 position, int pointVal, Color tint)
        {
            this.level = level;
            basePosition = position;
            PointValue = pointVal;
            Color = tint;

            LoadContent();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a new gem.
        /// </summary>
        public HealthPack(Level level, Vector2 position, int pointVal, Color tint, string heal)
        {
            this.level = level;
            basePosition = position;
            PointValue = pointVal;
            Color = tint;
            Heal = heal;

            LoadContent();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructs a new Enemy.
        /// </summary>
        public Enemy(Level level, Vector2 position, string spriteSet, int health)
        {
            this.level = level;
            this.position = position;

            LoadContent(spriteSet);
            this.IsAlive = true;
            Health = health;
            MaxHealth = health;
        }
Ejemplo n.º 5
0
        public EnemyGenerator(Level lvl)
        {
            m_lvl = lvl;

            #region LoadData
            using (XmlReader reader = XmlReader.Create("Content/default-enemy.xml"))
            {
                string name;
                bool started = false;
                while (reader.Read())
                {
                    XmlNodeType type = reader.MoveToContent();
                    if (type == XmlNodeType.Element)
                    {
                        name = reader.Name.ToLower();

                        if (name == "enemies")
                        {
                            if (started)
                                throw new Exception("'enemies' nodes cannot be nested");
                            started = true;
                        }
                        else if (!started)
                            throw new Exception("The 'enemies' node must be instantiated.");
                        else if (name == "enemy")
                        {
                            string eName = reader.GetAttribute("name").ToLower();
                            int hp, pts, dmg;
                            if (!int.TryParse(reader.GetAttribute("health"), out hp))
                                throw new Exception("The attribute 'health' of node 'enemy' must be an integer.");
                            if (!int.TryParse(reader.GetAttribute("points"), out pts))
                                throw new Exception("The attribute 'points' of node 'enemy' must be an integer.");
                            if (!int.TryParse(reader.GetAttribute("damage"), out dmg))
                                throw new Exception("The attribute 'damage' of node 'enemy' must be an integer.");
                            m_enemySpriteSet.Add(eName, reader.GetAttribute("spriteSet").ToLower());
                            m_enemyHealth.Add(eName, hp);
                            m_enemyPoints.Add(eName, pts);
                            m_enemyDamage.Add(eName, dmg);
                            m_enemyTint.Add(eName, ContentLoader.ParseColor(reader.GetAttribute("tint")));
                        }
                        else
                            throw new NotSupportedException("Node '" + name + "' is not supported.");
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 6
0
 public ContentLoader(Level lvl)
 {
     m_mngr = lvl.ContentManager;
     m_lvl = lvl;
 }
Ejemplo n.º 7
0
        private void LoadNextLevel()
        {
            // Find the path of the next level.
            string levelPath;

            // Loop here so we can try again when we can't find a level.
            if (level != null && level.NextLevel != null)
            {
                levelPath = level.NextLevel;
                currentLevel = levelPath;
            }
            else if (currentLevel != null)
                levelPath = currentLevel;
            else
            {
                while (true)
                {
                    // Try to find the next level. They are sequentially numbered txt files.
                    levelPath = String.Format("Levels/{0}.txt", ++levelIndex);
                    levelPath = Path.Combine(StorageContainer.TitleLocation, "Content/" + levelPath);
                    if (File.Exists(levelPath))
                        break;

                    // If there isn't even a level 0, something has gone wrong.
                    if (levelIndex == 0)
                        throw new Exception("No levels found.");

                    // Whenever we can't find a level, start over again at 0.
                    levelIndex = -1;
                }
            }

            // Unloads the content for the current level before loading the next one.
            if (level != null)
                level.Dispose();

            // Load the level.
            SaveGame();
            level = new Level(Services, levelPath, this.score, playerHealth, playerMaxHealth);
        }
Ejemplo n.º 8
0
        public TrapGenerator(Level lvl)
        {
            m_lvl = lvl;
            #region LoadData
            using (XmlReader reader = XmlReader.Create("Content/default-trap.xml"))
            {
                string name;
                bool started = false;
                while (reader.Read())
                {
                    XmlNodeType type = reader.MoveToContent();
                    if (type == XmlNodeType.Element)
                    {
                        name = reader.Name.ToLower();

                        if (name == "traps")
                        {
                            if (started)
                                throw new Exception("'traps' nodes cannot be nested");
                            started = true;
                        }
                        else if (!started)
                            throw new Exception("The 'traps' node must be instantiated.");
                        else if (name == "trap")
                        {
                            string tName = reader.GetAttribute("type").ToLower();
                            int dmg;
                            if (!int.TryParse(reader.GetAttribute("damage"), out dmg))
                                throw new Exception("The attribute 'damage' of node 'trap' must be an integer.");
                            m_trapDmg.Add(tName, dmg);
                            m_trapClr.Add(tName, ContentLoader.ParseColor(reader.GetAttribute("tint")));
                        }
                        else
                            throw new NotSupportedException("Node '" + name + "' is not supported.");
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 9
0
        public ItemGenerator(Level lvl)
        {
            m_lvl = lvl;
            #region LoadData
            using (XmlReader reader = XmlReader.Create("Content/default-item.xml"))
            {
                string name;
                bool started = false;
                while (reader.Read())
                {
                    XmlNodeType type = reader.MoveToContent();
                    if (type == XmlNodeType.Element)
                    {
                        name = reader.Name.ToLower();

                        if (name == "items")
                        {
                            if (started)
                                throw new Exception("'items' nodes cannot be nested");
                            started = true;
                        }
                        else if (!started)
                            throw new Exception("The 'items' node must be instantiated.");
                        else if (name == "gem")
                        {
                            string gName = "gem-" + reader.GetAttribute("type").ToLower();
                            m_itemPoints.Add(gName, int.Parse(reader.GetAttribute("points")));
                            m_itemClr.Add(gName, ContentLoader.ParseColor(reader.GetAttribute("tint")));
                            m_itemAttributes.Add(gName, new List<string>());
                            if (!reader.IsEmptyElement)
                                LoadAttributes(gName, reader.ReadSubtree());
                        }
                        else if (name == "timebonus")
                        {
                            string gName = "timeBonus-" + reader.GetAttribute("type").ToLower();
                            m_itemPoints.Add(gName, int.Parse(reader.GetAttribute("points")));
                            m_itemClr.Add(gName, ContentLoader.ParseColor(reader.GetAttribute("tint")));
                            m_itemTimeBonus.Add(gName, int.Parse(reader.GetAttribute("bonus")));
                            m_itemAttributes.Add(gName, new List<string>());
                            if (!reader.IsEmptyElement)
                                LoadAttributes(gName, reader.ReadSubtree());
                        }
                        else if (name == "healthpack")
                        {
                            string gName = "healthPack-" + reader.GetAttribute("type").ToLower();
                            m_itemPoints.Add(gName, int.Parse(reader.GetAttribute("points")));
                            m_itemClr.Add(gName, ContentLoader.ParseColor(reader.GetAttribute("tint")));
                            m_itemHeal.Add(gName, reader.GetAttribute("heal"));
                            m_itemHealMax.Add(gName, reader.GetAttribute("maxHeal"));
                            m_itemAttributes.Add(gName, new List<string>());
                            if (!reader.IsEmptyElement)
                                LoadAttributes(gName, reader.ReadSubtree());
                        }
                        else
                            throw new NotSupportedException("Node '" + name + "' is not supported.");
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructors a new player.
        /// </summary>
        public Player(Level level, Vector2 position, int health, int maxHealth)
        {
            Health = health;
            MaxHealth = maxHealth;
            effects = new Dictionary<string, AnimationPlayer>();

            this.level = level;

            LoadContent();

            Reset(position);
        }