public void AddDoor(Door door) { doors.Add(door); }
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; }
public void AddDoor(Vector2 position) { Door door = new Door(); door.Animations.Add("Closed", new FrameAnimation(1, 96, 64, 0, 0)); FrameAnimation Opening = new FrameAnimation(4, 96, 64, 0, 0); Opening.FramesPerSecond = 5; door.Animations.Add("Opening", Opening); door.Animations.Add("Open", new FrameAnimation(1, 96, 64, 0, 192)); door.CurrentAnimationName = "Closed"; door.Postition = position; doors.Add(door); }