Ejemplo n.º 1
0
        public void initPropConfig(ContentManager content, String PropConfigFile)
        {
            var doc         = XDocument.Load(PropConfigFile);
            var Props       = doc.Element("Props").Elements("Prop");
            var Doors       = doc.Element("Props").Elements("Door");
            var Potions     = doc.Element("Props").Elements("Potion");
            var Keys        = doc.Element("Props").Elements("Key");
            var WeaponItems = doc.Element("Props").Elements("Weapon");

            String    PropClass;
            Texture2D PropTexture;
            int       PropWidth;
            int       PropHeight;

            String    DoorClass;
            Texture2D DoorTexture;
            int       DoorWidth;
            int       DoorHeight;

            String    PotionClass;
            Texture2D PotionTexture;
            int       PotionWidth;
            int       PotionHeight;
            int       PotionRestore;

            String    KeyClass;
            Texture2D KeyTexture;
            int       KeyWidth;
            int       KeyHeight;

            String    WeaponClass;
            Texture2D WeaponTexture;
            int       WeaponX;
            int       WeaponY;
            int       WeaponWidth;
            int       WeaponHeight;

            int texWidth;
            int texHeight;

            foreach (XElement Prop in Props)
            {
                PropClass   = Prop.Attribute("className").Value;
                PropTexture = content.Load <Texture2D>(Prop.Attribute("texture").Value);
                PropWidth   = int.Parse(Prop.Attribute("width").Value);
                PropHeight  = int.Parse(Prop.Attribute("height").Value);
                texWidth    = int.Parse(Prop.Attribute("texWidth").Value);
                texHeight   = int.Parse(Prop.Attribute("texHeight").Value);

                this.PropPrototypes[PropClass]           = new Prop(PropTexture, PropWidth, PropHeight, texWidth, texHeight);
                this.PropPrototypes[PropClass].className = PropClass;
            }
            foreach (XElement Door in Doors)
            {
                DoorClass   = Door.Attribute("className").Value;
                DoorTexture = content.Load <Texture2D>(Door.Attribute("texture").Value);
                DoorWidth   = int.Parse(Door.Attribute("width").Value);
                DoorHeight  = int.Parse(Door.Attribute("height").Value);
                texWidth    = int.Parse(Door.Attribute("texWidth").Value);
                texHeight   = int.Parse(Door.Attribute("texHeight").Value);

                this.DoorPrototypes[DoorClass]           = new Door(DoorTexture, DoorWidth, DoorHeight, texWidth, texHeight);
                this.DoorPrototypes[DoorClass].className = DoorClass;
            }
            foreach (XElement Potion in Potions)
            {
                PotionClass   = Potion.Attribute("className").Value;
                PotionTexture = content.Load <Texture2D>(Potion.Attribute("texture").Value);
                PotionWidth   = int.Parse(Potion.Attribute("width").Value);
                PotionHeight  = int.Parse(Potion.Attribute("height").Value);
                texWidth      = int.Parse(Potion.Attribute("texWidth").Value);
                texHeight     = int.Parse(Potion.Attribute("texHeight").Value);
                PotionRestore = int.Parse(Potion.Attribute("restore").Value);

                this.PotionPrototypes[PotionClass] = new Potion(PotionTexture,
                                                                PotionWidth, PotionHeight,
                                                                texWidth, texHeight, PotionRestore);
                this.PotionPrototypes[PotionClass].className = PotionClass;
            }
            foreach (XElement Key in Keys)
            {
                KeyClass   = Key.Attribute("className").Value;
                KeyTexture = content.Load <Texture2D>(Key.Attribute("texture").Value);
                KeyWidth   = int.Parse(Key.Attribute("width").Value);
                KeyHeight  = int.Parse(Key.Attribute("height").Value);
                texWidth   = int.Parse(Key.Attribute("texWidth").Value);
                texHeight  = int.Parse(Key.Attribute("texHeight").Value);

                this.KeyPrototypes[KeyClass] = new Key(KeyTexture,
                                                       KeyWidth, KeyHeight,
                                                       texWidth, texHeight);
                this.KeyPrototypes[KeyClass].className = KeyClass;
            }
            foreach (XElement Weapon in WeaponItems)
            {
                WeaponClass   = Weapon.Attribute("className").Value;
                WeaponTexture = content.Load <Texture2D>(Weapon.Attribute("texture").Value);
                WeaponX       = int.Parse(Weapon.Attribute("offsetX").Value);
                WeaponY       = int.Parse(Weapon.Attribute("offsetY").Value);
                WeaponWidth   = int.Parse(Weapon.Attribute("width").Value);
                WeaponHeight  = int.Parse(Weapon.Attribute("height").Value);
                texWidth      = int.Parse(Weapon.Attribute("texWidth").Value);
                texHeight     = int.Parse(Weapon.Attribute("texHeight").Value);

                this.WeaponItemPrototypes[WeaponClass] = new WeaponItem(WeaponTexture, WeaponClass,
                                                                        WeaponWidth, WeaponHeight,
                                                                        WeaponX, WeaponY,
                                                                        texWidth, texHeight);
            }
        }