Beispiel #1
0
        public XmlTag(XmlTag tag)
        {
            // C# doesn't have the idea of copy constructor!
            Tag = tag.Tag;
            tagId = tag.tagId;

            if (tag.Attributes != null)
            {
                Attributes = new Dictionary<string, string>();
                foreach (KeyValuePair<string, string> attrib in tag.Attributes)
                    Attributes.Add(attrib.Key, attrib.Value);
            }

            if (tag.Children != null)
            {
                Children = new List<XmlTag>();
                foreach (XmlTag child in tag.Children)
                    Children.Add(child);
            }

            if (tag.EssentialAttributes != null)
            {
                EssentialAttributes = new List<string>();
                foreach (string attrib in tag.EssentialAttributes)
                    EssentialAttributes.Add(attrib);
            }

            Initialized = true;
        }
Beispiel #2
0
        /* Recursively prints the whole xml */
        public void printXmlStruct(XmlTag tag, String append, String frontAppend)
        {
            tag.printTag(frontAppend);
            Console.WriteLine(); // Line break

            for (int i = 0; tag.Children != null && i < tag.Children.Count; ++i)
                printXmlStruct(tag.Children[i], append, frontAppend += append);
        }
Beispiel #3
0
 /* Should be improved to use polymorphism, such that tags[element.tagId].setValue(value) is possible */
 private void setElementValue(XmlTag element, string value)
 {
     switch ((TagID)element.tagId)
     {
         case TagID.Body:
             break;
         case TagID.Head:
             break;
         case TagID.Title:
             title = value;
             break;
         case TagID.Meta:
             break;
         case TagID.Obj:
             break;
         case TagID.MoveableSpriteObj:
             break;
         case TagID.PlaneObj:
             break;
         case TagID.BulletObj:
             break;
         case TagID.Details:
             break;
         case TagID.BulletType:
             setBulletType(value);
             break;
         case TagID.EnemyPlaneObj:
             break;
         case TagID.Behaviors:
             setBehaviors(value);
             break;
         case TagID.HeroPlaneObj:
             break;
         case TagID.Object:
             break;
         case TagID.EnemyPlaneObject:
             break;
         case TagID.HeroPlaneObject:
             break;
         case TagID.Map:
             break;
         case TagID.Event:
             break;
         case TagID.CreateObj:
             break;
         case TagID.Path:
             setPath(value);
             break;
     }
 }
Beispiel #4
0
 /* Should be improved to use polymorphism, such that tags[element.tagId].convertTag() is possible. */
 private void convertTagToValue(XmlTag element)
 {
     switch ((TagID)element.tagId)
     {
         case TagID.Body:
             convertBody(element);
             break;
         case TagID.Head:
             break;
         case TagID.Title:
             break;
         case TagID.Meta:
             convertMeta(element);
             break;
         case TagID.Obj:
             convertObj(element);
             break;
         case TagID.MoveableSpriteObj:
             convertMoveableSpriteObj(element);
             break;
         case TagID.PlaneObj:
             convertPlaneObj(element);
             break;
         case TagID.BulletObj:
             break;
         case TagID.Details:
             convertDetails(element);
             break;
         case TagID.BulletType:
             break;
         case TagID.EnemyPlaneObj:
             convertEnemyPlaneObj(element);
             break;
         case TagID.Behaviors:
             convertBehaviors(element);
             break;
         case TagID.HeroPlaneObj:
             convertHeroPlaneObj(element);
             break;
         case TagID.Object:
             convertObject(element);
             break;
         case TagID.EnemyPlaneObject:
             convertEnemyPlaneObject(element);
             break;
         case TagID.HeroPlaneObject:
             convertHeroPlaneObject(element);
             break;
         case TagID.Map:
             break;
         case TagID.Event:
             break;
         case TagID.CreateObj:
             convertCreateObj(element);
             break;
         case TagID.Path:
             convertPath(element);
             break;
     }
 }
Beispiel #5
0
        private void convertPlaneObj(XmlTag element)
        {
            string key = "";
            MoveableSpriteObj baseObj = null;
            PlaneObj value = null;
            int hp = 0;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "moveablespriteobj")
                    baseObj = moveableSpriteObjs[attrib.Value];
                else if (attrib.Key == "hp")
                    hp = Int32.Parse(attrib.Value);
            }

            value = new PlaneObj(baseObj.sprite, 0, 0, (int)baseObj.velocity.X, (int)baseObj.velocity.Y, baseObj.srcRect.Width, baseObj.srcRect.Height, baseObj.MoveRate, hp);
            value.ID = key;
            planeObjs.Add(key, value);
        }
Beispiel #6
0
        private void convertBody(XmlTag element)
        {
            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "background")
                    background = (attrib.Value != "") ?
                        (Texture2D)Texture.FromFile(_GLOBAL.Graphics.GraphicsDevice, attrib.Value) : // This allows for dynamic loading of Texture
                        _GLOBAL.ContentManager.Load<Texture2D>(@"sprites/background"); // Default value

                else if (attrib.Key == "bgmusic")
                    BGM = (attrib.Value != "") ?
                        _GLOBAL.ContentManager.Load<SoundEffect>(attrib.Value) : // Needs to find a way to load dynamic soundeffects
                        _GLOBAL.ContentManager.Load<SoundEffect>(@"audio/effect/onCursorMoveEffect"); // Default value

                else if (attrib.Key == "scrollspeed")
                    scrollSpeed = (attrib.Value != "") ? float.Parse(attrib.Value) : 0.65f; // default value
            }
        }
Beispiel #7
0
 public XmlStruct(XmlTag root)
 {
     Root = root;
 }
Beispiel #8
0
        private bool readChildren(XmlTag tag, XmlTextReader reader, XmlTag element)
        {
            int i;
            for (i = 0; tag.Children != null && i < tag.Children.Count; ++i)
                if (element.Tag == tag.Children[i].Tag)
                    return true;

            if (tag.Children == null || i >= tag.Children.Count)
                throw new Exception("Error 4: " + tag.Tag + " does not have a child tag called '" + reader.Name.ToLower() + "'. " + "Line " + reader.LineNumber + ", position " + reader.LinePosition);

            return false;
        }
Beispiel #9
0
 private void convertMeta(XmlTag element)
 {
     foreach (KeyValuePair<string, string> attrib in element.Attributes)
         if (attrib.Key == "content")
             objective = attrib.Value;
 }
Beispiel #10
0
        private void convertHeroPlaneObject(XmlTag element)
        {
            Texture2D img = null;
            int x, y, vx, vy, moverate, hp, width, height;
            x = y = vx = vy = moverate = hp = width = height = 0;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "src")
                    img = (Texture2D)Texture.FromFile(_GLOBAL.Graphics.GraphicsDevice, attrib.Value); // dynamic loading
                else if (attrib.Key == "x")
                    x = Int32.Parse(attrib.Value);
                else if (attrib.Key == "y")
                    y = Int32.Parse(attrib.Value);
                else if (attrib.Key == "vx")
                    vx = Int32.Parse(attrib.Value);
                else if (attrib.Key == "vy")
                    vy = Int32.Parse(attrib.Value);
                else if (attrib.Key == "width")
                    width = (attrib.Value == "default") ? img.Width : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "height")
                    height = (attrib.Value == "default") ? img.Height : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "moverate")
                    moverate = Int32.Parse(attrib.Value);
                else if (attrib.Key == "hp")
                    hp = Int32.Parse(attrib.Value);
            }

            hero = new HeroPlaneObj(img, x, y, vx, vy, width, height, moverate, hp);
        }
Beispiel #11
0
        // Not used
        private void convertHeroPlaneObj(XmlTag element)
        {
            string key = "";
            PlaneObj baseObj = null;
            int x, y;
            x = y = 0;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "planeobj")
                    baseObj = planeObjs[attrib.Value];
                else if (attrib.Key == "x")
                    x = Int32.Parse(attrib.Value);
                else if (attrib.Key == "y")
                    y = Int32.Parse(attrib.Value);
            }

            hero = new HeroPlaneObj(baseObj.sprite, x, y, (int)baseObj.velocity.X, (int)baseObj.velocity.Y, baseObj.srcRect.Width, baseObj.srcRect.Height, baseObj.MoveRate, baseObj.hp);
        }
Beispiel #12
0
        private void convertEnemyPlaneObject(XmlTag element)
        {
            Texture2D img = null;
            int x, y, vx, vy, moverate, hp, width, height;
            x = y = vx = vy = moverate = hp = width = height = 0;
            EnemyPlaneObj value = null;
            Path enemyPath = null;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "src")
                    img = (Texture2D)Texture.FromFile(_GLOBAL.Graphics.GraphicsDevice, attrib.Value);// dynamic loading
                else if (attrib.Key == "x")
                    x = Int32.Parse(attrib.Value);
                else if (attrib.Key == "y")
                    y = Int32.Parse(attrib.Value);
                else if (attrib.Key == "vx")
                    vx = Int32.Parse(attrib.Value);
                else if (attrib.Key == "vy")
                    vy = Int32.Parse(attrib.Value);
                else if (attrib.Key == "width")
                    width = (attrib.Value == "default") ? img.Width : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "height")
                    height = (attrib.Value == "default") ? img.Height : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "moverate")
                    moverate = Int32.Parse(attrib.Value);
                else if (attrib.Key == "hp")
                    hp = Int32.Parse(attrib.Value);
                else if (attrib.Key == "path")
                    enemyPath = paths[attrib.Value].createMirror(false, false);
            }

            value = new EnemyPlaneObj(img, x, y, vx, vy, width, height, moverate, hp, enemyPath);

            enemyPlaneObjs.Add(value.ID, value);
        }
Beispiel #13
0
        private void convertEnemyPlaneObj(XmlTag element)
        {
            string key = "";
            PlaneObj baseObj = null;
            EnemyPlaneObj value = null;
            int x, y;
            x = y = 0;
            Path enemyPath = null;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "planeobj")
                    baseObj = planeObjs[attrib.Value];
                else if (attrib.Key == "x")
                    x = Int32.Parse(attrib.Value);
                else if (attrib.Key == "y")
                    y = Int32.Parse(attrib.Value);
                else if (attrib.Key == "path")
                    if(paths.ContainsKey(attrib.Value))
                        enemyPath = paths[attrib.Value].createMirror(false, false);
            }

            value = new EnemyPlaneObj(baseObj.sprite, x, y, (int)baseObj.velocity.X, (int)baseObj.velocity.Y, baseObj.srcRect.Width, baseObj.srcRect.Height, baseObj.MoveRate, baseObj.hp, enemyPath);

            foreach (BulletObj bullet in baseObj.BulletType)
                value.addBulletType(bullet);

            value.ID = key;
            enemyPlaneObjs.Add(key, value);
        }
Beispiel #14
0
        private void convertDetails(XmlTag element)
        {
            XmlTag details = stack.Pop();
            string key = stack.Peek().Attributes["id"];
            MoveableSpriteObj baseObj = moveableSpriteObjs[stack.Peek().Attributes["moveablespriteobj"]];

            bool killable = bool.Parse(stack.Peek().Attributes["killable"]),
                bounceable = bool.Parse(stack.Peek().Attributes["bounceable"]);

            BulletObj value = new BulletObj(baseObj.sprite, 0, 0, (int)baseObj.velocity.X, (int)baseObj.velocity.Y, null, killable, bounceable, 0.0f, 1.0f);

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key += attrib.Value;
                else if (attrib.Key == "amount")
                    value.BulletAmount = Int32.Parse(attrib.Value);
                else if (attrib.Key == "separation")
                    value.BulletDensity = (Int32.Parse(attrib.Value) == 0) ? 0.5f : Int32.Parse(attrib.Value);
                else if (attrib.Key == "interval")
                    value.BulletInterval = Int32.Parse(attrib.Value);
            }

            value.ID = key;
            bulletObjs.Add(key, value);
            stack.Push(details);
        }
Beispiel #15
0
        private void convertCreateObj(XmlTag element)
        {
            int time = 0;
            string obj = "";

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "time")
                    time = Int32.Parse(attrib.Value);
                else if (attrib.Key == "obj")
                    obj = attrib.Value;
            }

            events.Add(new Event(time, obj));
        }
Beispiel #16
0
        private void initialized()
        {
            xml = new Dictionary<string, XmlTag>();
            Root = new XmlTag("map");
            Root.tagId = (int)TagID.Map;
                Head = new XmlTag("head");
                Head.tagId = (int)TagID.Head;

                    Title = new XmlTag("title");
                    Title.tagId = (int)TagID.Title;
                Head.Children.Add(Title);

                    Meta = new XmlTag("meta");
                    Meta.tagId = (int)TagID.Meta;
                    Meta.Attributes.Add("content","untitled");
                    Meta.EssentialAttributes.Add("content");
                Head.Children.Add(Meta);

            Root.Children.Add(Head);

                Body = new XmlTag("body");
                Body.tagId = (int)TagID.Body;
                Body.Attributes.Add("background", "");
                Body.Attributes.Add("bgmusic", "");
                Body.Attributes.Add("scrollspeed", "");

                    Obj = new XmlTag("obj");
                    Obj.tagId = (int)TagID.Obj;
                    Obj.Attributes.Add("id", "");
                    Obj.Attributes.Add("src", "");
                    Obj.EssentialAttributes.Add("id");
                    Obj.EssentialAttributes.Add("src");
                Body.Children.Add(Obj);

                    MoveableSpriteObj = new XmlTag("moveablespriteobj");
                    MoveableSpriteObj.tagId = (int)TagID.MoveableSpriteObj;
                    MoveableSpriteObj.Attributes.Add("id", "");
                    MoveableSpriteObj.Attributes.Add("obj", "");
                    MoveableSpriteObj.Attributes.Add("vx", "");
                    MoveableSpriteObj.Attributes.Add("vy", "");
                    MoveableSpriteObj.Attributes.Add("width", "default");
                    MoveableSpriteObj.Attributes.Add("height", "default");
                    MoveableSpriteObj.Attributes.Add("moverate", "15");
                    MoveableSpriteObj.EssentialAttributes.Add("id");
                    MoveableSpriteObj.EssentialAttributes.Add("obj");
                    MoveableSpriteObj.EssentialAttributes.Add("vx");
                    MoveableSpriteObj.EssentialAttributes.Add("vy");
                Body.Children.Add(MoveableSpriteObj);

                        BulletType = new XmlTag("bullettype");
                        BulletType.tagId = (int)TagID.BulletType;

                    PlaneObj = new XmlTag("planeobj");
                    PlaneObj.tagId = (int)TagID.PlaneObj;
                    PlaneObj.Attributes.Add("id", "");
                    PlaneObj.Attributes.Add("moveablespriteobj", "");
                    PlaneObj.Attributes.Add("hp", "1");
                    PlaneObj.EssentialAttributes.Add("id");
                    PlaneObj.EssentialAttributes.Add("moveablespriteobj");
                    PlaneObj.Children.Add(BulletType);
                Body.Children.Add(PlaneObj);

                    Path = new XmlTag("path");
                    Path.tagId = (int)TagID.Path;
                    Path.Attributes.Add("id", "");
                    Path.Attributes.Add("path", "");
                    Path.Attributes.Add("xreverse", "false");
                    Path.Attributes.Add("yreverse", "false");
                    Path.EssentialAttributes.Add("id");
                Body.Children.Add(Path);

                    BulletObj = new XmlTag("bulletobj");
                    BulletObj.tagId = (int)TagID.BulletObj;
                    BulletObj.Attributes.Add("id", "");
                    BulletObj.Attributes.Add("moveablespriteobj", "");
                    BulletObj.Attributes.Add("killable", "false");
                    BulletObj.Attributes.Add("bounceable", "false");
                    BulletObj.EssentialAttributes.Add("id");
                    BulletObj.EssentialAttributes.Add("moveablespriteobj");
                        Details = new XmlTag("details");
                        Details.tagId = (int)TagID.Details;
                        Details.Attributes.Add("id", "");
                        Details.Attributes.Add("amount", "");
                        Details.Attributes.Add("separation", "");
                        Details.Attributes.Add("interval", "250");
                        Details.EssentialAttributes.Add("id");
                        Details.EssentialAttributes.Add("amount");
                        Details.EssentialAttributes.Add("separation");
                    BulletObj.Children.Add(Details);

                Body.Children.Add(BulletObj);

                    EnemyPlaneObj = new XmlTag("enemyplaneobj");
                    EnemyPlaneObj.tagId = (int)TagID.EnemyPlaneObj;
                    EnemyPlaneObj.Attributes.Add("id", "");
                    EnemyPlaneObj.Attributes.Add("planeobj", "");
                    EnemyPlaneObj.Attributes.Add("x", "");
                    EnemyPlaneObj.Attributes.Add("y", "");
                    EnemyPlaneObj.Attributes.Add("path", "");
                    EnemyPlaneObj.EssentialAttributes.Add("id");
                    EnemyPlaneObj.EssentialAttributes.Add("planeobj");
                    EnemyPlaneObj.EssentialAttributes.Add("x");
                    EnemyPlaneObj.EssentialAttributes.Add("y");
                        Behaviors = new XmlTag("behaviors");
                        Behaviors.tagId = (int)TagID.Behaviors;
                    EnemyPlaneObj.Children.Add(Behaviors);

                Body.Children.Add(EnemyPlaneObj);

                    HeroPlaneObj = new XmlTag("heroplaneobj");
                    HeroPlaneObj.tagId = (int)TagID.HeroPlaneObj;
                    HeroPlaneObj.Attributes.Add("id", "");
                    HeroPlaneObj.Attributes.Add("planeobj", "");
                    HeroPlaneObj.Attributes.Add("x", "");
                    HeroPlaneObj.Attributes.Add("y", "");
                    HeroPlaneObj.EssentialAttributes.Add("id");
                    HeroPlaneObj.EssentialAttributes.Add("planeobj");
                    HeroPlaneObj.EssentialAttributes.Add("x");
                    HeroPlaneObj.EssentialAttributes.Add("y");
                Body.Children.Add(HeroPlaneObj);

                    Object = new XmlTag("object");
                    Object.tagId = (int)TagID.Object;
                    Object.Attributes.Add("id", "");
                    Object.Attributes.Add("src", "");
                    Object.Attributes.Add("x", "");
                    Object.Attributes.Add("y", "");
                    Object.Attributes.Add("width", "default");
                    Object.Attributes.Add("height", "default");
                    Object.EssentialAttributes.Add("src");
                    Object.EssentialAttributes.Add("x");
                    Object.EssentialAttributes.Add("y");
                Body.Children.Add(Object);

                    EnemyPlaneObject = new XmlTag("enemyplaneobject");
                    EnemyPlaneObject.tagId = (int)TagID.EnemyPlaneObject;
                    EnemyPlaneObject.Attributes.Add("src", "");
                    EnemyPlaneObject.Attributes.Add("x", "");
                    EnemyPlaneObject.Attributes.Add("y", "");
                    EnemyPlaneObject.Attributes.Add("vx", "");
                    EnemyPlaneObject.Attributes.Add("vy", "");
                    EnemyPlaneObject.Attributes.Add("width", "default");
                    EnemyPlaneObject.Attributes.Add("height", "default");
                    EnemyPlaneObject.Attributes.Add("moverate", "15");
                    EnemyPlaneObject.Attributes.Add("hp", "1");

                    EnemyPlaneObject.EssentialAttributes.Add("src");
                    EnemyPlaneObject.EssentialAttributes.Add("x");
                    EnemyPlaneObject.EssentialAttributes.Add("y");
                    EnemyPlaneObject.EssentialAttributes.Add("vx");
                    EnemyPlaneObject.EssentialAttributes.Add("vy");
                Body.Children.Add(EnemyPlaneObject);

                    HeroPlaneObject = new XmlTag("heroplaneobject");
                    HeroPlaneObject.tagId = (int)TagID.HeroPlaneObject;
                    HeroPlaneObject.Attributes.Add("src", "");
                    HeroPlaneObject.Attributes.Add("x", "");
                    HeroPlaneObject.Attributes.Add("y", "");
                    HeroPlaneObject.Attributes.Add("vx", "");
                    HeroPlaneObject.Attributes.Add("vy", "");
                    HeroPlaneObject.Attributes.Add("width", "default");
                    HeroPlaneObject.Attributes.Add("height", "default");
                    HeroPlaneObject.Attributes.Add("moverate", "15");
                    HeroPlaneObject.Attributes.Add("hp", "1");

                    HeroPlaneObject.EssentialAttributes.Add("src");
                    HeroPlaneObject.EssentialAttributes.Add("x");
                    HeroPlaneObject.EssentialAttributes.Add("y");
                    HeroPlaneObject.EssentialAttributes.Add("vx");
                    HeroPlaneObject.EssentialAttributes.Add("vy");
                    HeroPlaneObject.Children.Add(BulletType);
                Body.Children.Add(HeroPlaneObject);

                    Event = new XmlTag("event");
                    Event.tagId = (int)TagID.Event;

                        CreateObj = new XmlTag("createobj");
                        CreateObj.tagId = (int)TagID.CreateObj;
                        CreateObj.Attributes.Add("time", "0");
                        CreateObj.Attributes.Add("obj", "");
                        CreateObj.EssentialAttributes.Add("time");
                        CreateObj.EssentialAttributes.Add("obj");
                    Event.Children.Add(CreateObj);
                Body.Children.Add(Event);

            Root.Children.Add(Body);
            Map = Root;
            Map.tagId = Root.tagId;

            EssentialTags = new List<TagID>();
            EssentialTags.Add((TagID)Map.tagId);
            EssentialTags.Add((TagID)Head.tagId);
            EssentialTags.Add((TagID)Title.tagId);
            EssentialTags.Add((TagID)Body.tagId);

            xml.Add("map", Map);
            xml.Add("head", Head);
            xml.Add("title", Title);
            xml.Add("meta", Meta);
            xml.Add("body", Body);
            xml.Add("obj", Obj);
            xml.Add("moveablespriteobj", MoveableSpriteObj);
            xml.Add("moveablespriteobject", MoveableSpriteObject);
            xml.Add("bulletobj", BulletObj);
            xml.Add("bullettype", BulletType);
            xml.Add("details", Details);
            xml.Add("planeobj", PlaneObj);
            xml.Add("planeobject", PlaneObject);
            xml.Add("enemyplaneobj", EnemyPlaneObj);
            xml.Add("enemyplaneobject", EnemyPlaneObject);
            xml.Add("behaviors", Behaviors);
            xml.Add("object", Object);
            xml.Add("heroplaneobject", HeroPlaneObject);
            xml.Add("heroplaneobj", HeroPlaneObj);
            xml.Add("event", Event);
            xml.Add("createobj", CreateObj);
            xml.Add("path", Path);
        }
Beispiel #17
0
 public MapXml(XmlTag root)
     : base(root)
 {
 }
Beispiel #18
0
        private void convertMoveableSpriteObj(XmlTag element)
        {
            string key = "";
            Obj baseObj = null;
            MoveableSpriteObj value;
            int vx, vy, width, height, moverate;
            vx = vy = width = height = moverate = 0;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "obj")
                    baseObj = objs[attrib.Value];
                else if (attrib.Key == "vx")
                    vx = Int32.Parse(attrib.Value);
                else if (attrib.Key == "vy")
                    vy = Int32.Parse(attrib.Value);
                else if (attrib.Key == "width")
                    width = (attrib.Value == "default") ? baseObj.srcRect.Width : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "height")
                    height = (attrib.Value == "default") ? baseObj.srcRect.Height : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "moverate")
                    moverate = Int32.Parse(attrib.Value);
            }

            value = new MoveableSpriteObj(baseObj.sprite, 0, 0, vx, vy, width, height, moverate);
            value.ID = key;
            moveableSpriteObjs.Add(key, value);
        }
Beispiel #19
0
        private void readAttribute(XmlTag tag, XmlTextReader reader, XmlTag element)
        {
            List<string> essentialAttributes = null; //C# doesn't have copy constructor
            if (tag.EssentialAttributes != null)
            {
                essentialAttributes = new List<string>();
                foreach (string attrib in tag.EssentialAttributes)
                    essentialAttributes.Add(attrib);
            }

            while (reader.MoveToNextAttribute())
            {
                if (tag.Attributes != null && tag.Attributes.Count > 0 && tag.Attributes.ContainsKey(reader.Name.ToLower()))
                {
                    if (_GLOBAL.Debug) Console.Write(" " + reader.Name.ToLower() + "=\"" + reader.Value.ToLower() + "\"");
                    if (essentialAttributes != null)
                        essentialAttributes.Remove(reader.Name.ToLower()); // Doesn't check for dupe attribs, C# checks it for us
                    continue;
                }
                throw new Exception("Error 3: " + tag.Tag + " does not have an Attribute called '" + reader.Name.ToLower() + "'. " + "Line " + reader.LineNumber + ", position " + reader.LinePosition);
            }
            if (essentialAttributes != null && essentialAttributes.Count > 0)
                throw new Exception("Error 6: Not all required attributes for '" + tag.Tag + "' are satisified. " + "Line " + reader.LineNumber + ", position " + reader.LinePosition);
        }
Beispiel #20
0
        private void convertObj(XmlTag element)
        {
            string key = "";
            Texture2D baseObj = null;
            Obj value;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "src")
                    baseObj = (Texture2D)Texture.FromFile(_GLOBAL.Graphics.GraphicsDevice, attrib.Value); // dynamic loading
            }

            value = new Obj(baseObj, 0, 0);
            value.ID = key;
            objs.Add(key, value);
        }
Beispiel #21
0
 private void readElement(XmlStruct xmlStruct, XmlTextReader reader, XmlTag element)
 {
     /* If the stack is emepty, push only the root tag */
     if (stack.Count == 0 && element.Tag == xmlStruct.Root.Tag)
     {
         stack.Push(element);
         readAttribute(xmlStruct.Root, reader, element);
     }
     else if (stack.Count > 0 && readChildren(stack.Peek(), reader, element)) // else push, if the tag is a child of the stack.Peek().
     {
         stack.Push(element);
         readAttribute(stack.Peek(), reader, element);
     }
     else
         throw new Exception("Error 5: Invalid Tag '" + element.Tag + "'. " + "Line " + reader.LineNumber + ", position " + reader.LinePosition);
 }
Beispiel #22
0
        private void convertObject(XmlTag element)
        {
            string key = "";
            Texture2D img = null;
            int x, y, width, height;
            x = y = width = height = 0;
            Obj value = null;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "src")
                    img = (Texture2D)Texture.FromFile(_GLOBAL.Graphics.GraphicsDevice, attrib.Value); // dynamic loading
                else if (attrib.Key == "x")
                    x = Int32.Parse(attrib.Value);
                else if (attrib.Key == "y")
                    y = Int32.Parse(attrib.Value);
                else if (attrib.Key == "width")
                    width = (attrib.Value == "default") ? img.Width : Int32.Parse(attrib.Value); // default value
                else if (attrib.Key == "height")
                    height = (attrib.Value == "default") ? img.Height : Int32.Parse(attrib.Value); // default value
            }

            value = new Obj(img, x, y, img.Width, img.Height, width * height / (img.Width * img.Height));

            if (key != "")  // Key is not required for Object. If not specified, use the one generated by the Obj class
                value.ID = key;
            objects.Add(value.ID, value);
        }
Beispiel #23
0
        private void convertPath(XmlTag element)
        {
            string key = "", pathId = "";
            bool xReverse = false,
                yReverse = false;

            Path value = null;

            foreach (KeyValuePair<string, string> attrib in element.Attributes)
            {
                if (attrib.Key == "id")
                    key = attrib.Value;
                else if (attrib.Key == "xreverse")
                    xReverse = bool.Parse(attrib.Value);
                else if (attrib.Key == "yreverse")
                    yReverse = bool.Parse(attrib.Value);
                else if (attrib.Key == "path")
                    pathId = attrib.Value;
            }

            if (pathId != "")
            {
                if (paths.ContainsKey(pathId)){
                    value = paths[pathId].createMirror(xReverse, yReverse);
                }
                else
                    throw new Exception("Invalid path id: " + pathId);
            }

            if (value == null)
                value = new Path();

            paths.Add(key, value);
        }
Beispiel #24
0
        private void convertBehaviors(XmlTag element)
        {
            XmlTag tag = stack.Pop();
            EnemyPlaneObj enemy = enemyPlaneObjs[stack.Peek().Attributes["id"]];
            string behavior = "behaviorcontroller";

            enemy.currentBehavior = getBehaviorFromString(behavior, ref enemy);
            stack.Push(tag);
        }