Exemplo n.º 1
0
        public Gate(Game1 game, XmlTextReader reader)
            : base(game, reader)
        {
            string pxStr = reader.GetAttribute("px");
            string pyStr = reader.GetAttribute("py");
            string widthStr = reader.GetAttribute("width");
            string heightStr = reader.GetAttribute("height");

            float px = float.Parse(pxStr);
            float py = float.Parse(pyStr);
            int width = int.Parse(widthStr);
            int height = int.Parse(heightStr);

            this.position = new Vector2(px, py);
            this.Width = width;
            this.Height = height;

            XmlReader subtree = reader.ReadSubtree();
            while (subtree.Read())
            {
                if (subtree.NodeType == XmlNodeType.Element)
                {
                    if (subtree.Name == "bound")
                    {
                        string leftStr = reader.GetAttribute("left");
                        string rightStr = reader.GetAttribute("right");
                        string topStr = reader.GetAttribute("top");
                        string bottomStr = reader.GetAttribute("bottom");
                        float left = float.Parse(leftStr);
                        float right = float.Parse(rightStr);
                        float top = float.Parse(topStr);
                        float bottom = float.Parse(bottomStr);
                        this.blockInfo = new BlockInfo(left, right, top, bottom, true);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Block(Game1 game, XmlTextReader reader)
            : base(game, reader)
        {
            string pxStr = reader.GetAttribute("px");
            string pyStr = reader.GetAttribute("py");
            string widthStr = reader.GetAttribute("width");
            string heightStr = reader.GetAttribute("height");
            string typeStr = reader.GetAttribute("type");

            float px = float.Parse(pxStr);
            float py = float.Parse(pyStr);
            int width = int.Parse(widthStr);
            int height = int.Parse(heightStr);

            this.position = new Vector2(px, py);
            this.Width = width;
            this.Height = height;

            if (typeStr == "ground")
            {
                type = BlockType.Ground;
            }
            else if (typeStr == "floor")
            {
                type = BlockType.Floor;
            }
            else if (typeStr == "wall")
            {
                type = BlockType.Wall;
            }
            else if (typeStr == "movableBlock")
            {
                type = BlockType.MovableBlock;
            }

            XmlReader subtree = reader.ReadSubtree();
            while (subtree.Read())
            {
                if (subtree.NodeType == XmlNodeType.Element)
                {
                    if (subtree.Name == "bound")
                    {
                        string leftStr = reader.GetAttribute("left");
                        string rightStr = reader.GetAttribute("right");
                        string topStr = reader.GetAttribute("top");
                        string bottomStr = reader.GetAttribute("bottom");
                        string positiveStr = reader.GetAttribute("positive");

                        float left = float.Parse(leftStr);
                        float right = float.Parse(rightStr);
                        float top = float.Parse(topStr);
                        float bottom = float.Parse(bottomStr);

                        bool positive = (positiveStr == "true") ? true : false;
                        this.blockInfo = new BlockInfo(left, right, top, bottom, positive);
                    }
                }
            }

            LoadContent();
        }