public BlocksPattern(BlockPatternInfo info, IGameplayContainer container, IEntityPool entityPool) { this.info = info; length = info.Length; leftBoundary = info.LeftBoundary; rightBoundary = info.RightBoundary; blocks = new List <BlockInfo>(); running = false; frame = 0; this.container = container; this._entityPool = entityPool; }
private ScreenInfo LoadScreenXml(XElement node, FilePath stagePath, Tileset tileset) { string id = node.RequireAttribute("id").Value; var screen = new ScreenInfo(id, tileset); screen.Layers.Add(LoadScreenLayer(node, stagePath.Absolute, id, tileset, 0, 0, false)); foreach (var overlay in node.Elements("Overlay")) { var name = overlay.RequireAttribute("name").Value; var x = overlay.TryAttribute <int>("x"); var y = overlay.TryAttribute <int>("y"); bool foreground = overlay.TryAttribute <bool>("foreground"); bool parallax = overlay.TryAttribute <bool>("parallax"); var layer = LoadScreenLayer(overlay, stagePath.Absolute, name, tileset, x, y, foreground); layer.Parallax = parallax; screen.Layers.Add(layer); } foreach (XElement teleport in node.Elements("Teleport")) { TeleportInfo info; int from_x = teleport.TryAttribute <int>("from_x"); int from_y = teleport.TryAttribute <int>("from_y"); int to_x = teleport.TryAttribute <int>("to_x"); int to_y = teleport.TryAttribute <int>("to_y"); info.From = new Point(from_x, from_y); info.To = new Point(to_x, to_y); info.TargetScreen = teleport.Attribute("to_screen").Value; screen.Teleports.Add(info); } var blocks = new List <BlockPatternInfo>(); foreach (XElement blockNode in node.Elements("Blocks")) { BlockPatternInfo pattern = _blockReader.FromXml(blockNode); screen.BlockPatterns.Add(pattern); } screen.Commands = _commandReader.LoadCommands(node, stagePath.BasePath); return(screen); }
public void Save(XmlTextWriter writer, BlockPatternInfo blockPattern) { writer.WriteStartElement("Blocks"); writer.WriteAttributeString("left", blockPattern.LeftBoundary.ToString()); writer.WriteAttributeString("right", blockPattern.RightBoundary.ToString()); writer.WriteAttributeString("length", blockPattern.Length.ToString()); writer.WriteAttributeString("entity", blockPattern.Entity); foreach (BlockInfo block in blockPattern.Blocks) { writer.WriteStartElement("Block"); writer.WriteAttributeString("x", block.pos.X.ToString()); writer.WriteAttributeString("y", block.pos.Y.ToString()); writer.WriteAttributeString("on", block.on.ToString()); writer.WriteAttributeString("off", block.off.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); }
public BlockPatternInfo FromXml(XElement xmlNode) { var info = new BlockPatternInfo(); info.Entity = xmlNode.RequireAttribute("entity").Value; info.LeftBoundary = xmlNode.GetAttribute <int>("left"); info.RightBoundary = xmlNode.GetAttribute <int>("right"); info.Length = xmlNode.GetAttribute <int>("length"); info.Blocks = new List <BlockInfo>(); foreach (XElement blockInfo in xmlNode.Elements("Block")) { BlockInfo block = new BlockInfo(); block.pos = new PointF(blockInfo.GetAttribute <float>("x"), blockInfo.GetAttribute <float>("y")); block.on = blockInfo.GetAttribute <int>("on"); block.off = blockInfo.GetAttribute <int>("off"); info.Blocks.Add(block); } return(info); }