Need help saving map
I need help with my map editor, I'm stuck on saving it. When I save, after I put some grass on map, it gets grass everywhere in map file. Here's variables:
mapMaximumX: maximum of the map in X (it is set as 500)
mapMaximumY: maximum of the map in Y (it is also set as 500)
mapTiles[index]: this is a list with class, each class has ID (0 = empty, 1 = grass, 2 = water), X and Y
if (Keyboard.GetState().IsKeyDown(Keys.F1))
{
for(int y = 0; y < mapMaximumY; y++)
{
for (int x = 0; x < mapMaximumX; x++)
{
if (MapTiles[i3].X == x && MapTiles[i3].Y == y)
{
}
else
开发者_C百科 {
MapTiles.Add(new Class1(0, x * 32, y * 32));
}
if (i3 < MapTiles.Count)
{
i3++;
}
}
}
TextWriter file = new StreamWriter("map1.MAP");
for (int y = 0; y < mapMaximumY; y++)
{
for (int x = 0; x < mapMaximumX; x++)
{
file.Write(MapTiles[i2].ID + ", ");
}
file.Write(file.NewLine);
}
i2 = 0;
System.Windows.Forms.MessageBox.Show("Saved!");
file.Close();
}
Full code is here, if u need it:
http://pastebin.com/qrWbuPtb
Thanx.
file.Write(MapTiles[i2].ID + ", ");
i2 never changes within your loop, so whatever i2 is will always be what's used to write your output.
You need to be using X and Y from your loops in determining which cell to write out.
精彩评论