コード例 #1
0
    public void Start()
    {
        TiledFiletype type = TiledType.GetAssetType(TextAssetName);

        if (type == TiledFiletype.Map)
        {
            TiledMap map = TiledMap.ReadMap(TextAssetName);
            foreach (TiledLayer layer in map.layers)
            {
                TiledLayerTile[] tiles = layer.GetTiles();
                if (tiles != null)
                {
                    foreach (TiledLayerTile tile in tiles)
                    {
                        // Debug.LogFormat("Tile({0},{1}) = {2} H={3} V={4} D={5}", tile.X, tile.Y, tile.Gid, tile.IsFlippedHorz, tile.IsFlippedVert, tile.IsFlippedDiag);
                    }
                }
            }
        }
        else if (type == TiledFiletype.Tileset)
        {
            TiledTileset tileset = TiledTileset.ReadTileset(TextAssetName);
            tileset.PrintSummary();
        }
    }
コード例 #2
0
        public static void ReadTilesets(TiledMap map, XElement root)
        {
            foreach (var tilesetElement in root.GetElements("tileset"))
            {
                var tileset = new TiledTileset();

                // Read mandatory attributes.
                tileset.FirstId = tilesetElement.ReadAttribute("firstgid", 0);
                tileset.Name = tilesetElement.ReadAttribute("name", String.Empty);
                tileset.TileWidth = tilesetElement.ReadAttribute("tilewidth", 0);
                tileset.TileHeight = tilesetElement.ReadAttribute("tileheight", 0);

                // Read optional attributes.
                tileset.Spacing = tilesetElement.ReadAttribute("spacing", 0);
                tileset.Margin = tilesetElement.ReadAttribute("margin", 0);

                // Read the tileset image.
                tileset.Image = ReadImage(tilesetElement);

                // Read the tileset offset.
                var offset = ReadTileOffset(tilesetElement);
                tileset.OffsetX = offset.Item1;
                tileset.OffsetY = offset.Item2;

                // Read tile metadata.
                var tileMetadata = ReadTilesetMetadata(tilesetElement);
                if (tileMetadata.Count > 0)
                {
                    tileset.Tiles.AddRange(tileMetadata);
                }

                // Add the tileset to the map.
                map.Tilesets.Add(tileset);
            }
        }
コード例 #3
0
        private void SetupTemplatedMap()
        {
            var w         = 70;
            var h         = 70;
            var ts        = 32;
            var templates = LoadRoomTemplatesFromFile(Path.Combine(content.RootDirectory, "Templates.txt"));

            //tData = string.Empty;
            //tData += "........................";
            //tData += "........................";
            //tData += "........................";
            //tData += "........xxxxxxxx........";
            //tData += "........xxxxxxxx........";
            //tData += "........xxxxxxxx........";
            //templates.Add(new RoomTemplate(24, 6, tData, "tooth"));

            var gen = new TemplatedMapGenerator()
            {
                DesiredRoomCount = 40
            };

            gen.AddTemplates(templates.ToArray());

            var map = gen.CreateMap(w, h);

            var custMap = new CustomTiledMap(0, map.Width, map.Height, ts, ts);
            var tileset = new TiledTileset(_texture, -1, ts, ts, 0, 0, 4, 4);

            custMap.loadFromArray("basic", map.GetMap().Select(x => (int)x).ToArray(), map.Width, map.Height, tileset, ts, ts);


            var mapEntity = createEntity("tiled-map");

            mapEntity.addComponent(new TiledMapComponent(custMap, shouldCreateColliders: false));
        }
コード例 #4
0
ファイル: Level.cs プロジェクト: ZaydQumsieh/CaveGame
        public TiledMap bake()
        {
            // initializing
            TiledMap     map            = new TiledMap(0, Constants.LEVEL_ROWS, Constants.LEVEL_COLUMNS, Constants.TILE_WIDTH, Constants.TILE_HEIGHT);
            Texture2D    tilesetTexture = GlintCore.contentSource.Load <Texture2D>("spritesheet");
            TiledTileset tiledTileset   = map.createTileset(tilesetTexture, 0, Constants.TILE_WIDTH, Constants.TILE_HEIGHT, true, 0, 0, 5, 5);

            // creating the background
            TiledTile[] backgroundTiles = new TiledTile[data.GetLength(0) * data.GetLength(1)];
            int         mw = data.GetLength(0);
            int         mh = data.GetLength(1);

            for (int j = 0; j < mh; j++)
            {
                for (int i = 0; i < mw; i++)
                {
                    backgroundTiles[j * mw + i] = new TiledTile((int)Constants.Id.Air)
                    {
                        tileset = tiledTileset
                    };
                }
            }

            // creating the collidable tiledtile[]
            TiledTile[] collidableTiles = new TiledTile[data.GetLength(0) * data.GetLength(1)];
            for (int j = 0; j < mh; j++)
            {
                for (int i = 0; i < mw; i++)
                {
                    if (data[i, j].id == (int)Constants.Id.Solid)
                    {
                        collidableTiles[j * mw + i] = new TiledTile(data[i, j].id)
                        {
                            tileset = tiledTileset
                        }
                    }
                    ;
                }
            }

            // creating the water tiledtile[]
            TiledTile[] waterTiles = new TiledTile[data.GetLength(0) * data.GetLength(1)];
            for (int i = 0; i < mw; i++)
            {
                for (int j = mh - waterLevel; j < mh; j++)
                {
                    waterTiles[j * mw + i] = new TiledTile((int)Constants.Id.Water)
                    {
                        tileset = tiledTileset
                    };
                }
            }

            // adding the layers together
            map.createTileLayer("background", map.width, map.height, backgroundTiles);
            map.createTileLayer("water", map.width, map.height, waterTiles);
            map.createTileLayer("walls", map.width, map.height, collidableTiles);

            return(map);
        }
コード例 #5
0
        private void ReadTilesets(ContentReader reader, TiledMap tiledMap)
        {
            var tilesetCount = reader.ReadInt32();

            for (var i = 0; i < tilesetCount; i++)
            {
                var tileset = new TiledTileset();
                tileset.Image.Source        = reader.ReadString();
                tileset.Image.Width         = reader.ReadInt32();
                tileset.Image.Height        = reader.ReadInt32();
                tileset.Image.SpriteTexture = reader.ContentManager.Load <Texture2D>(tileset.Image.Source);
                tileset.FirstGid            = reader.ReadInt32();
                tileset.TileWidth           = reader.ReadInt32();
                tileset.TileHeight          = reader.ReadInt32();
                tileset.Spacing             = reader.ReadInt32();
                tileset.Margin    = reader.ReadInt32();
                tileset.Tilecount = reader.ReadInt32();
                tileset.Columns   = reader.ReadInt32();

                var tileSetTileCount = reader.ReadInt32();
                for (var j = 0; j < tileSetTileCount; j++)
                {
                    var tileId = reader.ReadInt32();
                    tileId = tileset.FirstGid + tileId - 1;

                    var tiledTile = new TiledTile();
                    tiledTile.Id = tileId;
                    // ISSUE #25
                    tileset.Tiles.Add(tiledTile);
                }

                tiledMap.Tilesets.Add(tileset);
            }
        }
コード例 #6
0
ファイル: TiledExporter.cs プロジェクト: nculwell/Wandrix
        public static TiledMap Parse(string tiledMapFilename)
        {
            var tilemapDoc = new XmlDocument();

            tilemapDoc.Load(tiledMapFilename);
            var mapElt = tilemapDoc.DocumentElement;

            RequireAttributeValue(mapElt, "orientation", "orthogonal");
            // TODO: Support other render orders. (We will always output right-down order,
            // so the generator just needs to iterate diferently while writing tiles.)
            RequireAttributeValue(mapElt, "renderorder", "right-down");
            int width               = GetIntAttribute(mapElt, "width");
            int height              = GetIntAttribute(mapElt, "height");
            int tileWidth           = GetIntAttribute(mapElt, "tilewidth");
            int tileHeight          = GetIntAttribute(mapElt, "tileheight");
            var tilesetElements     = mapElt.SelectNodes("tileset");
            var tilesets            = MapElements(tilesetElements, e => TiledTileset.ParseRef(e, tileWidth, tileHeight));
            var layerElements       = mapElt.SelectNodes("layer");
            var layers              = MapElements(layerElements, e => TiledLayer.Parse(e, width, height));
            var objectGroupElements = mapElt.SelectNodes("objectgroup");
            var objectGroups        = MapElements(objectGroupElements, e => TiledObjectGroup.Parse(e, tileWidth, tileHeight));

            return(new TiledMap()
            {
                MapFilename = tiledMapFilename,
                Width = width,
                Height = height,
                TileWidth = tileWidth,
                TileHeight = tileHeight,
                Tilesets = tilesets.ToList(),
                Layers = layers.ToList(),
            });
        }
コード例 #7
0
        public static TiledTile[] generateWallMap(int width, int height, TiledTileset tileset)
        {
            var map      = new TiledTile[width * height];
            var wallTile = 0;

            for (var r = 0; r < height; r++)
            {
                for (var c = 0; c < width; c++)
                {
                    if (r == 0 || r == height - 1)
                    {
                        // map.push(wallTile);
                        map[r * width + c] = new TiledTile(wallTile);
                    }
                    else
                    {
                        if (c == 0 || c == (width - 1))
                        {
                            //map.push(wallTile);
                            map[r * width + c] = new TiledTile(wallTile);
                        }
                        else
                        {
                            //map.push(airTile);
                            map[r * width + c] = null;
                        }
                    }
                    if (map[r * width + c] != null)
                    {
                        map[r * width + c].tileset = tileset;
                    }
                }
            }
            return(map);
        }
コード例 #8
0
 private static void AssignProperties(TiledTileset tileset, int i, Tileset ts)
 {
     foreach (TiledTile tile in tileset.Tiles)
     {
         if (tile.Id == i)
         {
             ts.tileproperties.Add((tile.Properties.Count > 0) ? tile.Properties : null); return;
         }
     }
     ts.tileproperties.Add(null);
 }
コード例 #9
0
 private string GetTilesetName(TiledTileset set)
 {
     if (!_loadedTilesets.TryGetValue(set, out var name))
     {
         var load = (string)set.Properties.FirstOrDefault(p => p.Name == "fname")?.Value ?? set.Name;
         name = $"set{_sets++}";
         Write($"var {name} = load_texture(\"{load}\");");
         _loadedTilesets.Add(set, name);
     }
     return(name);
 }
コード例 #10
0
        public void Load(NezContentManager content, Vector2 ScreenVector)
        {
            myMap = new TiledMap(0, (int)ScreenVector.X, (int)ScreenVector.Y, TileData.TileSize, TileData.TileSize, TiledMapOrientation.Orthogonal);
            //TODO: multilayer support
            TiledTileLayer Floors = (TiledTileLayer)myMap.createTileLayer("Floors", (int)ScreenVector.X, (int)ScreenVector.Y);

            Collidables = (TiledTileLayer)myMap.createTileLayer("Walls", (int)ScreenVector.X, (int)ScreenVector.Y);
            int          XOffset        = (int)Mathf.ceil(0.5f * (ScreenVector.X / TileData.TileSize));
            int          YOffset        = (int)Mathf.ceil(0.5f * (ScreenVector.Y / TileData.TileSize));
            TiledTileset BaseMapTileset = myMap.createTileset(content.Load <Texture2D>(this.MapTextureAtlas), 0, 64, 64, true, 0, 0, this.TextureAtlasTileWidth, this.TextureAtlasTileHeight);

            for (int x = 0; x < Mathf.ceil(ScreenVector.X / TileData.TileSize); x++)
            {
                for (int y = 0; y < Mathf.ceil(ScreenVector.X / TileData.TileSize); x++)
                {
                    TileData  myTileData;
                    TiledTile myTile;
                    Tuple <float, float, float> tuple = new Tuple <float, float, float>(x, y, (float)Math.Ceiling(TileData.MaxHeight * myNoise.GetNoise(x, y)));
                    if (myModifiedTiles.TryGetValue(tuple, out myTileData))
                    {
                        myTile         = new TiledTile(myTileData.TileSetID);
                        myTile.tileset = myMap.createTileset(content.Load <Texture2D>(myTileData.TilesetName), 0, TileData.TileSize, TileData.TileSize, true, 0, 0, myTileData.TextureAtlasTileWidth, myTileData.TextureAtlasTileHeight);
                        if (myTileData.isWall)
                        {
                            Collidables.setTile(myTile);
                        }
                        else
                        {
                            Floors.setTile(myTile);
                        }
                    }
                    else
                    {
                        if (tuple.Item3 > 0)
                        {
                            myTile         = new TiledTile(1);
                            myTile.tileset = BaseMapTileset;
                            Collidables.setTile(myTile);
                        }
                        else if (tuple.Item3 == 0)
                        {
                            myTile         = new TiledTile(0);
                            myTile.tileset = BaseMapTileset;
                            Floors.setTile(myTile);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }
コード例 #11
0
        public static TileSheet loadTsx(IModHelper modHelper, string path, string ts, Map xmap, out Dictionary <int, TileAnimation> animMapping)
        {
            TiledTileset ttileSheet = null;
            Stream       stream     = null;

            try
            {
                stream     = new FileStream(Path.Combine(modHelper.DirectoryPath, path), FileMode.Open);
                ttileSheet = ( TiledTileset )tilesheetSerializer.Deserialize(stream);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }

            animMapping = new Dictionary <int, TileAnimation>();

            // xTile wants things like "Mines/mine", not "Mines/mine.png"
            string image = ttileSheet.Image.Source;

            if (image.EndsWith(".png"))
            {
                image = Path.Combine(Path.GetDirectoryName(path), image);
                modHelper.Content.Load <Texture2D>(image);
                image = modHelper.Content.GetActualAssetKey(image);
            }

            var xtileSheet = new TileSheet(xmap, image, new Size(ttileSheet.Columns, ttileSheet.TileCount / ttileSheet.Columns), new Size(ttileSheet.TileWidth, ttileSheet.TileHeight));

            addTiledPropertiesToXTile(ttileSheet.Properties, xtileSheet.Properties);
            xtileSheet.Id      = ttileSheet.Name;
            xtileSheet.Spacing = new Size(ttileSheet.Spacing, ttileSheet.Spacing);
            xtileSheet.Margin  = new Size(ttileSheet.Margin, ttileSheet.Margin);
            foreach (var ttile in ttileSheet.Tiles)
            {
                addTiledPropertiesToXTile(ttile.Properties, xtileSheet.TileIndexProperties[ttile.Id]);

                if (ttile.Animation != null && ttile.Animation.Count > 0)
                {
                    List <int> tanimFrames = new List <int>();
                    foreach (var ttileAnim in ttile.Animation)
                    {
                        tanimFrames.Add(ttileSheet.FirstGlobalId + ttileAnim.TileId);
                    }
                    animMapping.Add(ttileSheet.FirstGlobalId + ttile.Id, new TileAnimation(tanimFrames.ToArray <int>(), ttile.Animation[0].Duration));
                }
            }

            return(xtileSheet);
        }
コード例 #12
0
        private async Task <Texture> getTexture(TiledTileset ts)
        {
            Texture t;

            if (!textures.TryGetValue(ts.FirstId, out t))
            {
                t = await pool.GetTexture();

                t.LoadImageFile(ts.Image.Source);
                textures[ts.FirstId] = t;
            }
            return(t);
        }
コード例 #13
0
        protected override void LoadContent()
        {
            this.camera             = new Camera(GraphicsDeviceManager, GraphicsDevice);
            this.camera.Zoom        = 10;
            this.camera.RenderPivot = RenderPivot.Center;

            var tiledTileSet = new TiledTileset(global::CraftEnd.CoreGame.Content.Content.FilePathTiled0x72DungenTileset, Content);
            var devLevelMap  = new TiledMap(global::CraftEnd.CoreGame.Content.Content.FilePathTiledLevelDev, tiledTileSet);
            var devLevel     = new Level(devLevelMap);

            this.camera.AddEntity(devLevel);

            foreach (var child in devLevel)
            {
                this.camera.AddEntity(child);
            }

            var dungeonTileSet0x72Loader = new DungenonTilesetII0x72Loader();

            dungeonTileSet0x72Loader.LoadContent(Content);

            this.player = new Player(
                dungeonTileSet0x72Loader,
                Content.Load <Texture2D>(global::CraftEnd.CoreGame.Content.Content.Texture2DCharacterShadow));
            this.player.Position = new Vector3(2, 2, 0);
            this.camera.AddEntity(this.player);

            var guiCamera = new Camera(GraphicsDeviceManager, GraphicsDevice);

            guiCamera.Zoom = 8;

            var uiLife = new Life(dungeonTileSet0x72Loader);

            guiCamera.AddEntity(uiLife);
            uiLife.NumberOfHearts = 5;
            uiLife.Position       = new Vector3(0.1f, 0, 0);

            var inventory = new Inventory(Content.Load <Texture2D>(global::CraftEnd.CoreGame.Content.Content.Texture2DInventoryTile), 10, 6);

            guiCamera.AddEntity(inventory);

            this.cursor = new Cursor(Content.Load <Texture2D>(global::CraftEnd.CoreGame.Content.Content.Texture2DCursor), guiCamera);
            guiCamera.AddEntity(this.cursor);
        }
コード例 #14
0
        private void SetupBspMap()
        {
            var w  = 70;
            var h  = 70;
            var ts = 32;

            var gen = new MessyBSPTreeMapGenerator(w, h);
            var map = gen.CreateMap();

            Debug.log(map.ToString());

            var custMap = new CustomTiledMap(0, map.Width, map.Height, ts, ts);
            var tileset = new TiledTileset(_texture, 0, ts, ts, 0, 0, 4, 4);

            custMap.loadFromArray("basic", map.GetMap().Select(x => (int)x).ToArray(), map.Width, map.Height, tileset, ts, ts);

            var mapEntity = createEntity("tiled-map");

            mapEntity.addComponent(new TiledMapComponent(custMap, shouldCreateColliders: false));
        }
コード例 #15
0
        private void load(TextureStore textures)
        {
            TiledTileset tileset = new TiledTileset("..\\..\\..\\Resources\\Tilesets\\default.tsx");

            FillFlowContainer tileContainer;

            Add(new FillFlowContainer
            {
                Direction        = FillDirection.Vertical,
                RelativeSizeAxes = Axes.Both,
                Children         = new Drawable[]
                {
                    new SpriteText
                    {
                        Text = tileset.Name,
                        Font = FontUsage.Default.With(size: 30)
                    },
                    tileContainer = new FillFlowContainer
                    {
                        Direction    = FillDirection.Full,
                        AutoSizeAxes = Axes.Both,
                    }
                }
            });

            foreach (var tile in tileset.Tiles)
            {
                // create sprites with tile.image.source
                tileContainer.Add(new Container
                {
                    Size  = new Vector2(50),
                    Child = new SpriteText
                    {
                        Text   = tile.id.ToString(),
                        Anchor = Anchor.Centre,
                        Origin = Anchor.Centre,
                    }
                });
            }
        }
コード例 #16
0
        public CustomTiledMap loadFromArray(string name, int[] tileData, int width, int height, TiledTileset tileset, int tileWidth,
            int tileHeight)
        {
            var tiles = tileData.Select(x => new TiledTile(x) { tileset = tileset }).ToArray();
            var tileLayer = createTileLayer(name, width, height, tiles);

            return this;
        }
コード例 #17
0
 public TutorialScreen()
     : base(true, true)
 {
     set = Assets.Levels[0].Tileset;
     tex = set.Texture;
 }
コード例 #18
0
ファイル: TiledMapReader.cs プロジェクト: kruzifix/Sokoban
        protected override TiledMap Read(ContentReader input, TiledMap existingInstance)
        {
            int width      = input.ReadInt32();
            int height     = input.ReadInt32();
            int tileWidth  = input.ReadInt32();
            int tileHeight = input.ReadInt32();

            // --- Property ---
            int propertyCount = input.ReadInt32();
            Dictionary <string, string> properties = new Dictionary <string, string>();

            for (int i = 0; i < propertyCount; i++)
            {
                properties.Add(input.ReadString(), input.ReadString());
            }

            // --- Tileset ---
            string tsName       = input.ReadString();
            int    tsTileWidth  = input.ReadInt32();
            int    tsTileHeight = input.ReadInt32();
            int    tsTileCount  = input.ReadInt32();
            int    tsColumns    = input.ReadInt32();
            string tsPath       = input.ReadString();

            // HACK!!! UGLY!!!
            // TODO: tileset texture gets loaded foreach level. cache already loaded tilesets!!!
            Texture2D tileSetTexture = input.ContentManager.Load <Texture2D>(tsPath);
            var       tileset        = new TiledTileset(tsName, tsTileWidth, tsTileHeight, tsTileCount, tsColumns, tileSetTexture);

            // --- Initial Room State ---
            IntVec playerPos = new IntVec(input.ReadInt32(), input.ReadInt32());

            // --- Entities ---
            List <Entity> ents     = new List <Entity>();
            int           entCount = input.ReadInt32();

            for (int i = 0; i < entCount; i++)
            {
                string type = input.ReadString();

                switch (type)
                {
                case "box":
                {
                    IntVec pos = new IntVec(input.ReadInt32(), input.ReadInt32());
                    ents.Add(new Box()
                        {
                            Pos = pos
                        });
                    break;
                }

                case "sbox":
                {
                    IntVec pos = new IntVec(input.ReadInt32(), input.ReadInt32());
                    ents.Add(new StickyBox()
                        {
                            Pos = pos
                        });
                    break;
                }

                case "hole":
                {
                    IntVec pos = new IntVec(input.ReadInt32(), input.ReadInt32());
                    ents.Add(new Hole()
                        {
                            Pos = pos
                        });
                    break;
                }
                }
            }

            // --- Room ---
            IntVec[] switches = new IntVec[input.ReadInt32()];
            for (int i = 0; i < switches.Length; i++)
            {
                switches[i] = new IntVec(input.ReadInt32(), input.ReadInt32());
            }

            Teleporter[] teles = new Teleporter[input.ReadInt32()];
            for (int i = 0; i < teles.Length; i++)
            {
                teles[i] = new Teleporter(new IntVec(input.ReadInt32(), input.ReadInt32()), new IntVec(input.ReadInt32(), input.ReadInt32()));
            }

            int roomWidth  = input.ReadInt32();
            int roomHeight = input.ReadInt32();

            Room room = new Room(roomWidth, roomHeight, switches, teles, new RoomState(playerPos, ents));

            for (int j = 0; j < roomHeight; j++)
            {
                for (int i = 0; i < roomWidth; i++)
                {
                    int f = input.ReadInt32();
                    room.SetObject(i, j, (FieldObject)f);
                }
            }

            var map = new TiledMap(width, height, tileWidth, tileHeight, tileset, room);

            foreach (KeyValuePair <string, string> kvp in properties)
            {
                map.Properties.Add(kvp.Key, kvp.Value);
            }

            // --- Layers ---
            int layerCount = input.ReadInt32();

            for (int i = 0; i < layerCount; i++)
            {
                string name        = input.ReadString();
                int    layerWidth  = input.ReadInt32();
                int    layerHeight = input.ReadInt32();
                var    layer       = new TiledLayer(map, name, layerWidth, layerHeight);

                for (int j = 0; j < layerWidth * layerHeight; j++)
                {
                    layer.SetData(j, input.ReadInt32());
                }
                map.AddLayer(layer);
            }

            return(map);
        }