I'm currently working on a 2D game project, as of now I can load a map from a textfile without a problem. Though the items read is listed line by line, and it is initialized by the map name so to say and how many tiles X and Y, like this:
Plain
8
8
S
1
G
0
G
0
G
0
And so on for 64 tiles, where G and S is for a grass and stone texture, and the 0 and 1 values below represents if it's not blocked or blocked.
Code that reads in tile informations (Not Plain, 8, 8):
public void Read(object o)
{
StreamReader reader = (StreamReader)o;
string tiles = reader.ReadLine();
string blocked = reader.ReadLine();
if (tiles.Equals("G"))
{
tileTexture = TextureManager.RequestTexture("G");
}
else if (tiles.Equals("S"))
{
tileTexture = TextureManager.RequestTexture("S");
}
if (blocked.Equals("1"))
{
Blocking = true;
}
else
Blocking = false;
}
The map txt file is loaded through Alt + L
if (state[DXInput.Key.LeftAlt] && state[DXInput.Key.L])
{
map.Read(@"Map/MapFile.txt");
}
With this layout of the text file and code I have absolutely no problem with loading the map into the game using ReadLine.
Now to the catch, I want the text file to look as following (alt. "," instead of spaces between each S0/1, G0/1):
Plain
8
8
S0 G0 G0 G0 G0 G0 G0 S0
G0 G0 G0 G0 G0 G0 G0 G0
G0 G0 G0 G0 G0 G0 G0 G0
G0 G0 S1 G0 G0 G0 G0 G0
G0 G0 G0 G0 G0 G0 S1 G0
G0 G0 G0 G0 G0 G0 G0 G0
G0 G0 G0 G0 G0 G0 G0 G0
S0 G0 G0 G0 G0 G0 G0 S0
I want to read it all separately like it does now, e.g. It should read one character at a time as it does now though with one line at a time.
This makes the text files easier to read and edit by hand.
Note: I don't want any code that control how many columns or lines should be in the text file or so, just how to load the map similar to how I currently am doing it but instead from a text file like that latest shown example.
Also if needed, how do I tell the streamreader to start from line 4 in the text file? As that is where the "tile" code starts.
Code snippets of how I should approach this is very much appreciated.
-Pierre

New Topic/Question
Reply




MultiQuote





|