building levels from an external file. C#
I have built a few games in the past but I have always had to read levels off of hard coded arrays. I'd like to be able to build my levels from an external file but I don't know how. Any recommendations on what I should learn to accomplish this is greatly appreciated.
I like to use blender, because it's free and also pretty damn good. However first you might want to check that it creates models that are compatible with whatever graphics API you are using.
Alternatively if you want to spend some money there are loads of terrain generating software packages out there.
Alternatively if you want to spend some money there are loads of terrain generating software packages out there.
I don't think I was clear. I'm talking about using an array like structure in an external file that I can load then use to parse a 2D tile level. Think about building a 2D zelda style screen from an external file.
Quote:Original post by steveworks
I have built a few games in the past but I have always had to read levels off of hard coded arrays. I'd like to be able to build my levels from an external file but I don't know how. Any recommendations on what I should learn to accomplish this is greatly appreciated.
Well, the first thing to do would be to build your external files. You should use a format you know and understand. That could be as simple as a text file full of numbers, or more complex such as a binary format that's then compressed using zlib. There are many standard file formats you can use, such as png, jpg, dxtf (such as dxt1 - dxt5), and then there are other formats for your models, terrain, etc. Google around to find ones appropriate for your usage.
Once you know the format of your file you can then load it up using standard file IO routines, parse out the data you need, and then do with it as you will.
Quote:As a side note, C# has built-in Xml handling.
I found that out recently and after looking at a few tutorials I believe I can throw something together.
I don't know any tutorials, but maybe this will get you started. System.Runtime.Serialization.DataContractJsonSerializer is much just like XmlSerializer, but for JSON. I just happened to have it in front of me.
[Flags]enum TileFlags{ None, CanWalkOn = 1, CanBuildOn = 2, HasOre = 4, IsRoad = 8 | CanWalkOn,}[Serializable]struct Tile{ public TileFlags Flags; public int SpriteIndex;}[Serializable]sealed class Map[ public Tile[][] Tiles { get; set; } public static Map LoadMap(Stream s) { return Serializer.ReadObject(s) as Map; } static readonly DataContractJsonSerializer Serializer = new DataContractJsonSerializer(typeof(Map));}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement