Iv basically changed the whole system around. iv managed to draw the map to a windows form.
Here is how your Map class should look:
[XmlTypeAttribute(AnonymousType = true)]
[XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class Map
{
private string[] tilesetField;
private byte widthField;
private byte heightField;
private string[] dataField;
[XmlArrayItemAttribute("tile", IsNullable = false)]
public string[] tileset
{
get
{
return tilesetField;
}
set
{
tilesetField = value;
}
}
public byte width
{
get
{
return widthField;
}
set
{
widthField = value;
}
}
public byte height
{
get
{
return heightField;
}
set
{
heightField = value;
}
}
[XmlArrayItemAttribute("row", IsNullable = false)]
public string[] data
{
get
{
return dataField;
}
set
{
dataField = value;
}
}
}
This is how your XML should look:
<?xml version="1.0" encoding="UTF-8"?>
<Map>
<tileset>
<tile>grass.png</tile>
<tile>grass1.png</tile>
</tileset>
<width>16</width>
<height>16</height>
<data>
<row>0000000000000000</row>
<row>0001000000001000</row>
<row>0000000110000000</row>
<row>0000000000000000</row>
<row>0001000000001000</row>
<row>0000000110000000</row>
<row>0000000000000000</row>
<row>0001000000001000</row>
<row>0000000110000000</row>
<row>0000000000000000</row>
<row>0001000000001000</row>
<row>0000000110000000</row>
<row>0000000000000000</row>
<row>0001000000001000</row>
<row>0000000110000000</row>
<row>0000000000000000</row>
</data>
</Map>
Now you can simply draw the map like this:
private void panel1_Paint(object sender, PaintEventArgs e)
{
XmlSerializer ser = new XmlSerializer(typeof(Map));
Map testmap;
using (XmlReader reader = XmlReader.Create("test.xml"))
{
testmap = (Map)ser.Deserialize(reader);
}
for (int y = 0; y < testmap.height; y += 1)
{
for (int x = 0; x < testmap.width; x += 1)
{
int t = int.Parse(testmap.data[y].Substring(x, 1));
e.Graphics.DrawImage(Image.FromFile(testmap.tileset[t]), new Rectangle(x * 32, y * 32, 32, 32));
}
}
}
So basically the XML can explain exactly how it works,
Firstly, like your first design the map had a width and height. The map also has tiles, these tiles are listed in the tileset. The order they are in is the index of the tile.
Then the data of the map is rows and columns of tile indexes.