Esempio n. 1
0
        public TmxLayer(int zIndex, XElement layer)
        {
            ZIndex = zIndex;
            Width  = new XValue(layer, "width").AsInt();
            Height = new XValue(layer, "height").AsInt();
            var textureIds = new IntegersInText(layer.Element(XName.Get("data")).Value).Get().ToList();

            for (var i = 0; i < textureIds.Count; i++)
            {
                Tiles.Add(new TmxTile(i % Width, (int)Math.Floor((double)i / Width), textureIds[i]));
            }
        }
Esempio n. 2
0
        public Tsx(GraphicsDevice device, int firstId, string tsxPath)
        {
            FirstId = firstId;
            var doc     = XDocument.Load($"Content/{tsxPath}");
            var tileset = doc.Element(XName.Get("tileset"));

            TileWidth  = new XValue(tileset, "tilewidth").AsInt();
            TileHeight = new XValue(tileset, "tileheight").AsInt();
            Spacing    = new XValue(tileset, "spacing").AsInt();
            TileCount  = new XValue(tileset, "tilecount").AsInt();
            Columns    = new XValue(tileset, "columns").AsInt();
            TileSource = new Texture2DFromPath(device, Path.Combine("Content", new XValue(tileset.Element(XName.Get("image")), "source").AsString())).Get();
        }
Esempio n. 3
0
        public Tsx(GraphicsDevice device, int firstId, string tsxDir, XElement tileset)
        {
            FirstId    = firstId;
            TileWidth  = new XValue(tileset, "tilewidth").AsInt();
            TileHeight = new XValue(tileset, "tileheight").AsInt();
            Spacing    = new XValueWithDefault(tileset, "spacing").AsInt();
            Columns    = new XValue(tileset, "columns").AsInt();
            TileSource = new Texture2DFromPath(device, Path.Combine("Content", tsxDir, new XValue(tileset.Element(XName.Get("image")), "source").AsString())).Get();

            var tileElements = tileset.Elements(XName.Get("tile")).ToList();
            var tiles        = tileElements.Select(x => new TsxTile(new XValue(x, "id").AsInt(), GetTileRectangle(new XValue(x, "id").AsInt()), x)).ToList();
            var tileMap      = new Dictionary <int, TsxTile>();

            tiles.ForEach(x => tileMap[x.ID] = x);
            for (var i = 0; i < new XValue(tileset, "tilecount").AsInt(); i++)
            {
                Tiles.Add(tileMap.ContainsKey(i) ? tileMap[i] : new TsxTile(i, GetTileRectangle(i)));
            }
        }
Esempio n. 4
0
        public Tmx(GraphicsDevice device, string tmxPath)
        {
            var doc = XDocument.Load(Path.Combine("Content", tmxPath));
            var map = doc.Element(XName.Get("map"));

            Width      = new XValue(map, "width").AsInt();
            Height     = new XValue(map, "height").AsInt();
            TileWidth  = new XValue(map, "tilewidth").AsInt();
            TileHeight = new XValue(map, "tileheight").AsInt();
            Tilesets   = map.Elements(XName.Get("tileset"))
                         .Select(x => new Tsx(device, new XValue(x, "firstgid").AsInt(), new XValue(x, "source").AsString()))
                         .ToList();
            var layers = map.Elements(XName.Get("layer")).ToList();

            for (var i = 0; i < layers.Count; i++)
            {
                Layers.Add(new TmxLayer(i, layers[i]));
            }
        }