public Level(Tileset t, int w, int h) { tileset = t; Width = w; Height = h; data = new Byte[Width, Height]; }
public static Level LoadLevel(String filename, Tileset tiles) { System.IO.StreamReader stream = new System.IO.StreamReader(filename); int Wi = int.Parse(stream.ReadLine()); int He = int.Parse(stream.ReadLine()); Level l = new Level(tiles, Wi, He); l.file = filename; for (int y = 0; y < He; y++) { String[] arr = stream.ReadLine().Split(','); for (int x = 0; x < Wi; x++) l.data[x, y] = byte.Parse(arr[x]); } stream.Close(); return l; }
public static Tileset LoadTileset(String filename) { Tileset ts = new Tileset(); LinkedList<Actor> act = new LinkedList<Actor>(); System.IO.StreamReader stream = new System.IO.StreamReader(filename); String dir = stream.ReadLine(); String test = stream.ReadLine(); Model m = global.content.Load<Model>("Wall"); Texture2D tex = global.content.Load<Texture2D>("Blank"); foreach (ModelMesh mesh in m.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = global.e; } } act.AddLast(new Actor(m, tex, Matrix.CreateTranslation(-1.5f * Vector3.UnitZ))); act.AddLast(new Actor(m, tex, Matrix.CreateTranslation(1.5f * Vector3.UnitZ))); while (!stream.EndOfStream) { String[] arr = stream.ReadLine().Split(','); int variations = int.Parse(arr[1]); for (int i = 0; i < variations; i++) { m = global.content.Load<Model>(dir + "\\" + arr[0] + i); tex = global.content.Load<Texture2D>(dir + "\\" + arr[0] + i + "tex"); foreach (ModelMesh mesh in m.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = global.e; } } act.AddLast(new Actor(m, tex, Matrix.Identity)); act.AddLast(new Actor(m, tex, Matrix.CreateRotationZ(MathHelper.PiOver2))); act.AddLast(new Actor(m, tex, Matrix.CreateRotationZ(MathHelper.Pi))); act.AddLast(new Actor(m, tex, Matrix.CreateRotationZ(3 * MathHelper.PiOver2))); } } stream.Close(); ts.actors = act.ToArray(); return ts; }