Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Load Map
- public void LoadMap(string path)
- {
- string fileContents = string.Empty;
- try
- {
- using (StreamReader sr = new StreamReader(File.OpenRead(path)))
- {
- fileContents = sr.ReadToEnd().ToString();
- Console.WriteLine(fileContents); //file loaded correctly as the console output was correct
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("There was a problem loading the map");
- Console.WriteLine(e.Message);
- }
- //Splitting the file contents into parts to add to the array
- string[] parts = fileContents.Split(new string[] { "\r\n" }, StringSplitOptions.None);
- for (int i = 0; i < parts.Length; i++)
- {
- if (i == 0)
- {
- //Set Width
- tilesWide = Int16.Parse(parts[i]);
- }
- else if (i == 1)
- {
- //Set Height
- tilesHigh = Int16.Parse(parts[i]);
- //Declaring the identifier array using width and height
- TileMapIdentifiers = new int[tilesWide, tilesHigh];
- }
- if (i > 1)
- {
- //Loop through values and assign as needed
- string[] tiles = parts[i].Split(new string[] { "," }, StringSplitOptions.None);
- for (int j = 0; j < tiles.Length; j++)
- {
- TileMapIdentifiers[i - 2, j] = Int16.Parse(tiles[j]);
- }
- }
- }
- //Declaring the tile array using the width and height
- TileMapArray = new Tile[tilesWide, tilesHigh];
- //Using the identifiers to declare new tiles
- for(int i = 0; i < tilesWide; i++)
- {
- for (int j = 0; j < tilesHigh; j++)
- {
- TileMapArray[i,j] = new Tile(new Vector2(i*64, j*64), tileTexture, TileMapIdentifiers[i,j]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment