Example #1
0
        public void ParseBlocks(Room roomobj, XElement roomxml, XDocument doc)
        {
            XName blocksName = XName.Get("blocks", doc.Root.Name.NamespaceName);

            XElement        blocks    = roomxml.Element(blocksName);
            List <XElement> blockList = blocks.Elements("block").ToList();

            foreach (XElement block in blockList)
            {
                XElement typeName = block.Element("type");
                XElement xloc     = block.Element("xloc");
                XElement yloc     = block.Element("yloc");
                XElement push     = block.Element("push");

                float x         = float.Parse(xloc.Value);
                float y         = float.Parse(yloc.Value);
                int   numBlocks = Int32.Parse(push.Value);

                Vector2 truePos = RoomUtilities.CalculateBlockCenter(roomobj.RoomPos, new Vector2(x, y));

                IBlock blockAdd = CreateBlock(typeName.Value, truePos, numBlocks);
                if (blockAdd != null)
                {
                    roomobj.AddBlock(blockAdd);
                }
            }
        }
Example #2
0
        public Room CreateRoom()
        {
            Room room = new Room(this);
            TileLayer structureLayer = this.Tilemap.GetLayer("structure");

            foreach (Tile tile in structureLayer.Tiles)
            {
                if (tile.tileset.GetPropertiesOfGid(tile.gid) != null)
                {
                    BlockType type = Block.GetBlockTypeFromString(tile.tileset.GetPropertiesOfGid(tile.gid)["type"]);
                    room.AddBlock((int)tile.Position.X, (int)tile.Position.Y, type);
                }
            }

            return room;
        }