Hi,
I really urge you to learn how to read from an xml file (same as tmx really, you can just rename the map to “yourMap.xml” and it will function as an xml file), it’s going to make a lot of things easier for you in the long run.
Perhaps I can help you getting started. Keep in mind though that the examples I will give you is based on a normal XNA project (I can’t stand MonoGame until they have implemented a proper content pipeline, it’s simply horrible as it is now, unfortunately), but if you can get your MonoGame project to properly load xml files for you (I couldn’t, haha), then the code below should work the same regardless.
Let’s say we have a .tmx/.xml map looking like this:
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="left-down" width="2" height="2" tilewidth="32" tileheight="32" nextobjectid="1">
<tileset firstgid="1" name="sea_000" tilewidth="32" tileheight="32">
<image source="Tilesets/sea_000.png" width="256" height="192"/>
</tileset>
<layer name="Ground" width="2" height="2">
<data>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
<tile gid="1"/>
</data>
</layer>
</map>
We can then read from this file by using the following C# code:
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
using (XmlReader reader = XmlReader.Create("yourMap.xml", settings))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.Name)
{
case "map":
// Do something based on the information given
// inside the <map> starting tag, such as reading
// width and height (in tiles) of the map
width = int.Parse(reader.GetAttribute("width"));
height = int.Parse(reader.GetAttribute("height"));
break;
case "layer":
// This is where you would want to do something
// based on which layer we're currently reading.
// You could for example read the name of the
// layer and do something based on that name.
layerName = reader.GetAttribute("name");
break;
case "tile":
// Notice that I skipped a case for the "data" tag,
// this will make the reader just skip to the next row.
// This is where you would want to get the gid of the
// tile currently being read.
gid = int.Parse(reader.GetAttribute("gid"));
break;
}
break;
}
}
}
Of course, it would probably be a good idea if you try and learn the basics of xml before you try and implement something based on my example, but it should serve as a good base, I think.
Regarding collisions, this can be done in a lot of different ways. I’m not going to get into depth on this right now, but feel free to ask and I will try and help you further.
Oh, and I’m sorry for not giving you any advice on using .csv! I simply don’t know how I would approach using a .csv or .txt file since I wouldn’t personally ever use anything but .xml for my maps.