Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///This method would load in data from a text file for level
- protected void LoadLevel()
- {
- using (StreamReader sr = new StreamReader("Content\\Levels\\Level.txt"))
- {
- string line = sr.ReadLine();
- while (line != null)
- {
- tiles = line.Split(',');
- foreach (string tile in tiles)
- {
- //This would be a grass
- if (tile == "0")
- {
- //Create object here
- //ii and jj are the x,y position of our level in this case
- //Then add to list
- var obj = new object();
- obj.Position = new Vector2(ii, jj);
- obj.Texture = grassTexture;
- tileList.Add(obj);
- }
- if (tile == "1")
- {
- //Create object here
- //ii and jj are the x,y position of our level in this case
- //Then add to list
- var obj = new object();
- obj.Position = new Vector2(ii, jj);
- obj.Texture = dirtTexture;
- tileList.Add(obj);
- }
- ii += 50;
- }
- ii = 0;
- jj += 50;
- }
- }
- }
- ///You would draw the level like this
- foreach(obj o in tileList)
- {
- spriteBatch.Draw(o.Texture, o.Position, Color.White);
- }
- ///The text file would be in this format
- 0,0,1,0,0,0,0,0,0,0
- 0,0,1,0,0,0,0,0,0,0
- 0,0,1,0,0,0,0,0,0,0
- 0,0,1,0,0,0,0,0,0,0
- 0,0,1,1,1,1,1,1,1,1
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement