Exemple #1
0
 public void AddChest(TreasureChest chest)
 {
     chests.Add(chest);
 }
Exemple #2
0
        private static TileLayer ProcessFile(string filename, List<string> textureNames)
        {
            TileLayer tileLayer;
            List<TreasureChest> treasurech = new List<TreasureChest>();
            List<Door> dooor = new List<Door>();
            List<int> tempLayout = new List<int>();
            Dictionary<string, string> properties = new Dictionary<string, string>();
            int width = 0;
            int height = 0;

            XmlTextReader reader = new XmlTextReader(filename);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Texture")
                    {
                        string file = reader["File"];
                        textureNames.Add(file);
                    }

                    if (reader.Name == "Layout")
                    {
                        List<int> row = new List<int>();
                        width = int.Parse(reader["Width"]);
                        height = int.Parse(reader["Height"]);

                        reader.Read();

                        string[] cells = reader.Value.Split(' ');

                        foreach (string c in cells)
                                {
                                    if (!string.IsNullOrEmpty(c))
                                    {
                                        if (c.Contains("\r\n"))
                                            continue;

                                        tempLayout.Add(int.Parse(c));
                                    }
                                }
                    }

                    if (reader.Name == "Properties")
                    {
                        reader.Read();
                        string key = reader.Name;
                        string value = reader.ReadInnerXml();

                        properties.Add(key, value);
                    }

                    if (reader.Name == "TreasureChest")
                    {
                        TreasureChest tc = new TreasureChest();
                        tc.Postition.X = float.Parse(reader["LocationX"]);
                        tc.Postition.Y = float.Parse(reader["LocationY"]);
                        reader.Read();
                        tc.ItemType = reader["ItemType"];
                        tc.Item = reader["Item"];
                        tc.Quantity = int.Parse(reader["Quantity"]);
                        tc.Animations.Add("Closed", new FrameAnimation(1, 32, 48, 0, 0));
                        tc.CurrentAnimationName = "Closed";
                        treasurech.Add(tc);
                    }

                    if (reader.Name == "Door")
                    {
                        Door d = new Door();
                        d.Postition.X = float.Parse(reader["LocationX"]);
                        d.Postition.Y = float.Parse(reader["LocationY"]);
                        d.Animations.Add("Closed", new FrameAnimation(1, 96, 64, 0, 0));
                        d.CurrentAnimationName = "Closed";
                        dooor.Add(d);
                    }
                }
            }
            reader.Close();

            tileLayer = new TileLayer(width, height);
            int next = 0;

            for (int y = 0; y < height; y++)
                for (int x = 0; x < width; x++)
                {
                    tileLayer.SetCellIndex(x, y, tempLayout[next]);
                    next++;
                }

            foreach (KeyValuePair<string, string> property in properties)
            {
               switch (property.Key)
               {
                   case "Alpha":
                       tileLayer.Alpha = float.Parse(property.Value);
                       break;
               }
            }

            foreach (TreasureChest trech in treasurech)
            {
                tileLayer.chests.Add(trech);
            }

            foreach (Door d in dooor)
            {
                tileLayer.doors.Add(d);
            }

            return tileLayer;
        }
Exemple #3
0
 public void AddChest(Vector2 position, string itemType, int quantity, string item)
 {
     TreasureChest tC = new TreasureChest();
     tC.Postition = position;
     tC.ItemType = itemType;
     tC.Item = item;
     tC.Animations.Add("Closed", new FrameAnimation(1, 32, 48, 0, 0));
     tC.Animations.Add("Openening", new FrameAnimation(2, 32, 48, 0, 96));
     tC.Animations.Add("Open", new FrameAnimation(1, 32, 48, 0, 144));
     tC.CurrentAnimationName = "Closed";
     if (quantity > 0)
         tC.Quantity = quantity;
     else
         tC.Quantity = 1;
     chests.Add(tC);
 }