I finally found a tutorial on tile maps and loading them in from a file that I understand (http://circlessuck.blogspot.co.uk/2012/09/xna-tutorial-basic-tile-engine-part-2.html), however the tutorial doesn't show teach you how to do collision. I have vague idea in mind of what I might have to do from other tile map collisions I've seen, but I can't get it into code that will fit this style of loading tile maps. My tile map loadin:
private List<Texture2D> tiles;
private int[,] tileMap;
private const int tileWidth = 32;
private const int tileHeight = 32;
public TileMap(string name, ContentManager Content)
{
LoadTiles(Content);
LoadMapData(name);
}
public void Draw(SpriteBatch spriteBatch)
{
for (int y = 0; y < tileMap.GetLength(0); y++)
{
for (int x = 0; x < tileMap.GetLength(1); x++)
{
spriteBatch.Draw(
tiles[tileMap[y, x]], new Vector2(x * tileWidth, y * tileHeight),
Color.White);
}
}
}
private void LoadTiles(ContentManager Content)
{
tiles = new List<Texture2D>();
tiles.Add(Content.Load<Texture2D>("sky"));
tiles.Add(Content.Load<Texture2D>("grass"));
tiles.Add(Content.Load<Texture2D>("dirt"));
}
private void LoadMapData(string name)
{
string path = "Maps/" + name + ".txt";
int width = 0;
int height = File.ReadLines(path).Count();
StreamReader sReader = new StreamReader(path);
string line = sReader.ReadLine();
string[] tileNo = line.Split(',');
width = tileNo.Count();
tileMap = new int[height, width];
sReader.Close();
sReader = new StreamReader(path);
for (int y = 0; y < height; y++)
{
line = sReader.ReadLine();
tileNo = line.Split(',');
for (int x = 0; x < width; x++)
{
tileMap[y, x] = Convert.ToInt32(tileNo[x]);
}
}
sReader.Close();
}
(I have a player class with basic physics that all work fine)