Exemplo n.º 1
0
        public Map(TileSet tileSet, int width, int height)
        {
            this.tileSet = tileSet;
            this.width   = width;
            this.height  = height;
            state        = new MapState(this.width, this.height);
            stateHover   = new MapState(this.width, this.height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < height; x++)
                {
                    state.SetSquareKind(x, y, TerrainKind.Floor);
                }
            }

            this.tileSet.SelectTiles(state, Rng, 0, 0, this.width + 1, this.height + 1);
            ClearHoverTerrain();
        }
Exemplo n.º 2
0
        public static Map DeserializeFrom(StreamReader stream)
        {
            XmlReader xml = XmlReader.Create(stream);

            xml.ReadStartElement("Map");

            String tilesetName = xml.ReadElementString("Tileset");

            if (tilesetName != "Linedraw")
            {
                throw new NotImplementedException();
            }

            TileSet tileSet = TileSet.Load(@"Data\Simple.mdts");

            int width  = int.Parse(xml.ReadElementString("Width"));
            int height = int.Parse(xml.ReadElementString("Height"));

            Map      map   = new Map(tileSet, width, height);
            MapState state = map.state;

            xml.ReadStartElement("Terrain");
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int tileId = int.Parse(xml.ReadElementString("Square"));
                    state.SetSquareKind(x, y, tileSet.TerrainByIndex[tileId]);
                }
            }
            xml.ReadEndElement(); /* Terrain */

            xml.ReadStartElement("Tiles");
            while (xml.IsStartElement("Tile"))
            {
                xml.ReadStartElement("Tile");

                int layer = int.Parse(xml.ReadElementString("Layer"));
                int x     = int.Parse(xml.ReadElementString("X"));
                int y     = int.Parse(xml.ReadElementString("Y"));
                int value = int.Parse(xml.ReadElementString("Value"));

                Tile tile = tileSet.TileList[value];
                if (tile.IsLarge)
                {
                    for (int subX = 0; subX < tile.Width; subX++)
                    {
                        for (int subY = 0; subY < tile.Height; subY++)
                        {
                            state.SetTile(layer, x + subX, y + subY, tile.GetSubtile(subX, subY));
                        }
                    }
                }
                else
                {
                    state.SetTile(layer, x, y, tile);
                }

                xml.ReadEndElement(); /* Tile */
            }

            xml.ReadEndElement(); /* Tiles */

            xml.ReadEndElement(); /* Map */

            // TODO: Verify that map is correct
            map.ClearHoverTerrain();
            return(map);
        }
Exemplo n.º 3
0
 private static void SetTerrainBase(MapState mapState, int squareX, int squareY, TerrainKind terrain)
 {
     mapState.SetSquareKind(squareX, squareY, terrain);
 }