Danmaku_no_Kyojin.BulletEngine.BulletPattern.ParseXML C# (CSharp) Method

ParseXML() public method

Parses a bulletml document into this bullet pattern
public ParseXML ( string xmlFileName ) : bool
xmlFileName string Xml file name.
return bool
        public bool ParseXML(string xmlFileName)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.DtdProcessing = DtdProcessing.Ignore;

            using (XmlReader reader = XmlReader.Create(xmlFileName, settings))
            {
                //Open the file.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode rootXmlNode = xmlDoc.DocumentElement;

                //make sure it is actually an xml node
                if (rootXmlNode.NodeType == XmlNodeType.Element)
                {
                    //eat up the name of that xml node
                    string strElementName = rootXmlNode.Name;
                    if (("bulletml" != strElementName) || !rootXmlNode.HasChildNodes)
                    {
                        //The first node HAS to be bulletml
                        Debug.Assert(false);
                        return false;
                    }

                    //Create the root node of the bulletml tree
                    RootNode = new BulletMLNode();

                    //Read in the whole bulletml tree
                    if (!RootNode.Parse(rootXmlNode, null))
                    {
                        //an error ocurred reading in the tree
                        return false;
                    }
                    Debug.Assert(ENodeName.bulletml == RootNode.Name);

                    //Find what kind of pattern this is: horizontal or vertical
                    XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                    for (int i = 0; i < mapAttributes.Count; i++)
                    {
                        //will only have the name attribute
                        string strName = mapAttributes.Item(i).Name;
                        string strValue = mapAttributes.Item(i).Value;
                        if ("type" == strName)
                        {
                            //if  this is a top level node, "type" will be veritcal or horizontal
                            Orientation = StringToPatternType(strValue);
                        }
                    }
                }
                else
                {
                    //should be an xml node!!!
                    Debug.Assert(false);
                    return false;
                }
            }

            //grab that filename
            Filename = xmlFileName;
            return true;
        }

Usage Example

示例#1
0
        protected override void LoadContent()
        {
            Sprite = Game.Content.Load<Texture2D>(@"Graphics/Entities/enemy");
            _healthBar = Game.Content.Load<Texture2D>(@"Graphics/Pictures/pixel");
            Center = new Vector2(Sprite.Width / 2f, Sprite.Height / 2f);

            // Audio
            if (_deadSound == null)
                _deadSound = Game.Content.Load<SoundEffect>(@"Audio/SE/boss_dead");

            List<Point> vertices = new List<Point>()
                {
                    new Point(0, (int)(Sprite.Height / 2.74f)),
                    new Point(Sprite.Width / 2, 0),
                    new Point(Sprite.Width, (int)(Sprite.Height / 2.74f)),
                    new Point(Sprite.Width / 2, Sprite.Height)
                };

            CollisionBox = new CollisionConvexPolygon(this, Vector2.Zero, vertices);

            Position = new Vector2(
                Config.GameArea.X / 2f,
                Config.GameArea.Y / 2f);

            //Get all the xml files
            foreach (var source in Directory.GetFiles(@"Content\XML", "*.xml", SearchOption.AllDirectories))
            {
                //store the name
                _patternNames.Add(source);

                //load the pattern
                BulletPattern pattern = new BulletPattern();
                pattern.ParseXML(source);
                _myPatterns.Add(pattern);
            }

            _currentPattern = GameplayScreen.Rand.Next(0, _patternNames.Count);
            AddBullet(true);

            base.LoadContent();
        }
All Usage Examples Of Danmaku_no_Kyojin.BulletEngine.BulletPattern::ParseXML