Example #1
0
        public TileMap(TileSet tileset, MapLayer layer)
        {
            mapWidth = layer.Width;
            mapHeight = layer.Height;

            tileSets = new List<TileSet>();
            tileSets.Add(tileset);

            mapLayers = new List<MapLayer>();
            mapLayers.Add(layer);
        }
Example #2
0
        public LayerLoader(string filename, TileList tileList)
        {
            XmlDocument xmlDoc = new XmlDocument();
             xmlDoc.Load(filename);

             foreach (XmlNode tileMapNode in xmlDoc.DocumentElement.ChildNodes) // tilesetFile nodes
             {
                 //TODO Get tileWidth and tileHeight also
                 mapWidth = int.Parse(tileMapNode.Attributes["rows"].Value);
                 mapHeight = int.Parse(tileMapNode.Attributes["columns"].Value);

                 foreach (XmlNode layerNode in tileMapNode.ChildNodes)
                 {
                     MapLayer layer = new MapLayer(mapWidth, mapHeight);

                     //Get data node inside layernode
                     XmlNode dataNode = layerNode.FirstChild;
                     string data = dataNode.InnerXml;

                     //Parse all extra marks from data
                     data = data.Replace("\r\n\t\t\t\t", "");
                     data = data.Replace("\n\t\t\t", "");

                     //Parse all , makrs also

                     int counter = 0; // counter for data

                     for (int y = 0; y < mapWidth; y++)
                     {
                         for (int x = 0; x < mapHeight; x++)
                         {
                             // Get data id
                           // int id = int.Parse(data[counter].ToString());
                             int id = RemoveInt(ref data);
                             if (id != 0)
                             {
                                 layer.SetTile(x, y, tileList.GetTile(id));
                             }
                             counter++;
                         }
                     }
                      layers.Add(layer);
                 }
             }
        }
Example #3
0
 private void ProcessCollisionLayer(MapLayer layer)
 {
     for (int y = 0; y < mapHeight; y++)
         for (int x = 0; x < mapWidth; x++)
         {
             Tile tile = layer.GetTile(x, y);
             if (tile.IsNullTile)
             {
                 if (tile.CollisionType == CollisionType.Unpassable)
                 collisionLayer.SetTile(x, y, CollisionType.Unpassable);
             }
         }
 }
Example #4
0
 // Add new layer, make sure it's the same size as
 // the map
 internal void AddLayer(MapLayer layer)
 {
     if (layer.Width != mapWidth || layer.Height != mapHeight)
         throw new Exception("Error in layer size.");
     mapLayers.Add(layer);
 }