コード例 #1
0
 public OgmoTileMapLayer(OgmoMap map, string name, JArray dataCoords2D, uint gridCellWidth, uint gridCellHeight, string tileset, Texture2D tileAtlas)
 {
     TileMap      = map;
     Name         = name;
     Tileset      = tileset;
     TileAtlas    = tileAtlas;
     TileWidth    = gridCellWidth;
     TileHeight   = gridCellHeight;
     DataCoords2D = dataCoords2D;
 }
コード例 #2
0
        public override void Load(OgmoMap map)
        {
            TileMap = map;

            TileAtlas = TileMap.Entity.Scene.Content.LoadTexture($"Sprites/Tilesets/{Tileset}.png");

            Tiles = new OgmoTile[TileMap.MapData.Width / TileWidth, TileMap.MapData.Height / TileHeight];

            if (DataCoords2D != null)
            {
                int[][][] data = DataCoords2D.ToObject <int[][][]>();

                if (data != null)
                {
                    for (int i = 0; i < data.Length; i++)
                    {
                        for (int j = 0; j < data[i].GetLength(0); j++)
                        {
                            if (data[i][j].Length > 1)
                            {
                                Vector2 type = new Vector2(data[i][j][0], data[i][j][1]);

                                bool isCollidableInDictionary =
                                    TileMap.NonCollidableTiles.TryGetValue(type, out var nonCollidable);
                                if (!isCollidableInDictionary)
                                {
                                    nonCollidable = false;
                                }

                                bool isSlopedInDictionary =
                                    TileMap.SlopedTiles.TryGetValue(type, out short slopeDirection);
                                if (!isSlopedInDictionary)
                                {
                                    slopeDirection = 0;
                                }

                                bool isOneWayInDictionary =
                                    TileMap.OneWayTiles.TryGetValue(type, out bool oneWay);
                                if (!isOneWayInDictionary)
                                {
                                    oneWay = false;
                                }

                                if (slopeDirection == 0)
                                {
                                    Tiles[j, i] = new OgmoTile(type, Color.White,
                                                               new Vector2(j * TileWidth, i * TileHeight), TileMap.Transform, TileWidth,
                                                               TileHeight, !nonCollidable, oneWay);
                                }
                                else
                                {
                                    Tiles[j, i] = new OgmoSlopedTile(type, Color.White,
                                                                     new Vector2(j * TileWidth, i * TileHeight), TileMap.Transform, TileWidth,
                                                                     TileHeight, !nonCollidable, slopeDirection, oneWay);
                                }
                            }
                            else
                            {
                                Tiles[j, i] = new OgmoTile(new Vector2(-1, -1), Color.White,
                                                           new Vector2(j * TileWidth, i * TileHeight), TileMap.Transform, TileWidth,
                                                           TileHeight, false, false);
                            }
                        }
                    }
                }
            }
        }