public static Room Parse(XElement elem) { #if DEBUG1 try { #endif if (elem.Attribute("FloorType") != null && elem.Attribute("Collision") != null) { return(new Room( Index2D.Parse(elem.Attribute("StartCell").Value), Index2D.Parse(elem.Attribute("EndCell").Value), //(TileTypes)Enum.Parse(typeof(TileTypes), elem.Attribute("Type").Value), (Element)Enum.Parse(typeof(Element), elem.Attribute("Theme").Value), (TileTypes)Enum.Parse(typeof(TileTypes), elem.Attribute("FloorType").Value), bool.Parse(elem.Attribute("Collision").Value) )); } else if (elem.Attribute("FloorType") != null) { return(new Room( Index2D.Parse(elem.Attribute("StartCell").Value), Index2D.Parse(elem.Attribute("EndCell").Value), //(TileTypes)Enum.Parse(typeof(TileTypes), elem.Attribute("Type").Value), (Element)Enum.Parse(typeof(Element), elem.Attribute("Theme").Value), (TileTypes)Enum.Parse(typeof(TileTypes), elem.Attribute("FloorType").Value) )); } else { return(new Room( Index2D.Parse(elem.Attribute("StartCell").Value), Index2D.Parse(elem.Attribute("EndCell").Value), //(TileTypes)Enum.Parse(typeof(TileTypes), elem.Attribute("Type").Value), (Element)Enum.Parse(typeof(Element), elem.Attribute("Theme").Value) )); } #if DEBUG1 } catch (Exception e) { Console.WriteLine(e.GetBaseException().Message); return(null); } #endif }
public static Tile Parse(XElement elem) { #if DEBUG1 try { #endif Tile t = new Tile(); foreach (XAttribute attr in elem.Attributes()) { if (attr.Name == "Type") { t.Type = (TileTypes)Enum.Parse(typeof(TileTypes), attr.Value); } else if (attr.Name == "InstanceName") { t.InstanceName = attr.Value; } else if (attr.Name == "Collision") { t.Traversable = bool.Parse(attr.Value); } else if (attr.Name == "Theme") { t.Theme = (Element)Enum.Parse(typeof(Element), attr.Value); } else if (attr.Name == "Orientation") { t.Orientation = (Orientations)Enum.Parse(typeof(Orientations), attr.Value); } else if (attr.Name == "GridCell") { t.GridCell = Index2D.Parse(attr.Value); } } return(t); #if DEBUG1 } catch (Exception e) { Console.WriteLine(e.GetBaseException().Message); return(null); } #endif }
public static BorderWalls Parse(XElement elem) { #if DEBUG1 try { #endif return(new BorderWalls( Index2D.Parse(elem.Attribute("StartCell").Value), Index2D.Parse(elem.Attribute("EndCell").Value), (TileTypes)Enum.Parse(typeof(TileTypes), elem.Attribute("Type").Value), (Element)Enum.Parse(typeof(Element), elem.Attribute("Theme").Value), bool.Parse(elem.Attribute("Collision").Value) )); #if DEBUG1 } catch (Exception e) { Console.WriteLine(e.GetBaseException().Message); return(null); } #endif }
internal void Load(XDocument doc) { TileMap = new TileList(doc); foreach (XElement elem in doc.Descendants("Enemy")) { string type = elem.Attribute("Type").Value; Type t = Type.GetType(type); var obj = Activator.CreateInstance(t, new object[] { elem.Attribute("Name").Value, Index2D.Parse(elem.Attribute("Pos").Value).Vector }); } foreach (XElement elem in doc.Descendants("Object")) { string type = elem.Attribute("Type").Value; Type t = Type.GetType(type); if (elem.Attribute("Orientation") != null) { var obj = Activator.CreateInstance(t, new object[] { elem.Attribute("Name").Value, Index2D.Parse(elem.Attribute("Pos").Value).Vector, (Orientations)Enum.Parse(typeof(Orientations), elem.Attribute("Orientation").Value) }); } else { var obj = Activator.CreateInstance(t, new object[] { elem.Attribute("Name").Value, Index2D.Parse(elem.Attribute("Pos").Value).Vector }); } } }
/// <summary> /// Loads the animations from a file. /// </summary> /// <param name="filename">Name of animfile</param> /// <param name="contentSubfolder">Folder where content is stored</param> private void LoadAnimation(string filename, string contentSubfolder) { filename = String.Format("Content/{0}/{1}", contentSubfolder, filename); if (!File.Exists(filename)) { throw new Exception(String.Format("Animation file {0} does not exist.", filename)); } XDocument doc = XDocument.Load(filename); foreach (var frame in doc.Descendants("Frame")) { SpriteFrame sf = new SpriteFrame(); string[] sp = frame.Attribute("TLPos").Value.Split(','); sf.StartPos = new Vector2(float.Parse(sp[0]), float.Parse(sp[1])); ///image string file = frame.Attribute("SpriteSheet").Value; sf.Image = This.Game.Content.Load <Texture2D>(String.Format("{0}/{1}", contentSubfolder, file)); /** sets frame delay */ sf.Pause = int.Parse(frame.Attribute("FrameDelay").Value); //Image's width and height sf.Width = int.Parse(frame.Attribute("Width").Value); sf.Height = int.Parse(frame.Attribute("Height").Value); /** Set the animation Peg*/ sf.AnimationPeg = Index2D.Parse(frame.Attribute("AnimationPeg").Value).Vector; //add the mirror offset if there is one if (frame.Attribute("MirrorOffset") != null) { sf.MirrorOffset = Index2D.Parse(frame.Attribute("MirrorOffset").Value).Vector; } foreach (var hotspot in frame.Descendants("HotSpot")) { sf.HotSpots.Add(Index2D.Parse(hotspot.Value).Vector); } int idCount = 0; foreach (var collision in frame.Descendants("Collision")) { if (collision.Attribute("Type").Value == "Circle") { string[] pt = collision.Attribute("Pos").Value.Split(','); sf.CollisionData.Add(new Collision_BoundingCircle( idCount++, new Vector2(float.Parse(pt[0]), float.Parse(pt[1])), float.Parse(collision.Attribute("Radius").Value))); } else if (collision.Attribute("Type").Value == "Rectangle") { string[] tl = collision.Attribute("TLPos").Value.Split(','); float tlx = float.Parse(tl[0]); float tly = float.Parse(tl[1]); string[] br = collision.Attribute("BRPos").Value.Split(','); float brx = float.Parse(br[0]); float bry = float.Parse(br[1]); sf.CollisionData.Add(new Collision_AABB( idCount++, new Vector2(tlx, tly), new Vector2(brx, bry) )); } else if (collision.Attribute("Type").Value == "OBB") { string[] c1 = collision.Attribute("Corner1").Value.Split(','); float c1x = float.Parse(c1[0]); float c1y = float.Parse(c1[1]); string[] c2 = collision.Attribute("Corner2").Value.Split(','); float c2x = float.Parse(c2[0]); float c2y = float.Parse(c2[1]); float thickness = float.Parse(collision.Attribute("Thickness").Value.ToString()); sf.CollisionData.Add(new Collision_OBB( idCount++, new Vector2(c1x, c1y), new Vector2(c2x, c2y), thickness )); } } Frames.Add(sf); } }