public void LoadMap(string filename) { using (BinaryReader reader = new BinaryReader(new FileStream("Maps/" + filename, FileMode.Open))) { reader.ReadString(); reader.ReadInt32(); if (reader.ReadBoolean()) { using (FileStream str = new FileStream("temp", FileMode.Create)) { byte[] buffer = new byte[reader.ReadInt32()]; reader.Read(buffer, 0, buffer.Length); str.Write(buffer, 0, buffer.Length); } backgroundTexture = new Texture("temp"); backgroundMesh.Texture = backgroundTexture; File.Delete("temp"); } int nmbrOfTilesets = reader.ReadInt32(); for (int i = 0; i < nmbrOfTilesets; i++) { tilesetList.Add(new EnvTileset(reader)); } int nmbrOfTemplates = reader.ReadInt32(); for (int i = 0; i < nmbrOfTemplates; i++) { templateList.Add(new EnvTemplate(reader, this)); } int nmbrOfEvents = reader.ReadInt32(); for (int i = 0; i < nmbrOfEvents; i++) { eventList.Add(new EnvEvent( reader.ReadInt32(), reader.ReadString(), new TKTools.Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()) )); } int nmbrOfLayers = reader.ReadInt32(); for (int i = 0; i < nmbrOfLayers; i++) { float depth = 0; if (i == 0) //SOLIDS LAYER { int nmbrOfObjects = reader.ReadInt32(); for (int j = 0; j < nmbrOfObjects; j++) { bool isEvent = reader.ReadBoolean(); if (!isEvent) { solidList.Add(new EnvSolid(reader, this)); } else { int id = reader.ReadInt32(); int argNmbr = reader.ReadInt32(); int[] argList = new int[argNmbr]; for (int a = 0; a < argList.Length; a++) { argList[a] = reader.ReadInt32(); } Polygon p = new Polygon(new Vector2[] { new Vector2(reader.ReadSingle(), reader.ReadSingle()), new Vector2(reader.ReadSingle(), reader.ReadSingle()), new Vector2(reader.ReadSingle(), reader.ReadSingle()), new Vector2(reader.ReadSingle(), reader.ReadSingle()) }); if (id != -1) { map.SceneEvent(eventList.Find((x) => x.ID == id), argList, p); } } } } else { depth = reader.ReadSingle(); EnvLayer layer = new EnvLayer(depth); int nmbrOfObjects = reader.ReadInt32(); for (int j = 0; j < nmbrOfObjects; j++) { EnvObject obj = new EnvObject(reader, depth, this); objectList.Add(obj); layer.AddObject(obj); } layer.CreateCombinedMesh(); layerList.Add(layer); } } Polygon combinedPoly = new Polygon(); List <Polygon> solids = new List <Polygon>(); foreach (EnvSolid solid in solidList) { combinedPoly.AddPoint(solid.polygon); solids.Add(solid.polygon); } RectangleF rect = combinedPoly.Bounds; originOffset = new Vector2(rect.X, rect.Y) + new Vector2(rect.Width / 2, rect.Height / 2); width = rect.Width; height = rect.Height; layerList.Sort(delegate(EnvLayer x, EnvLayer y) { if (x.depth == y.depth) { return(0); } else if (x.depth < y.depth) { return(1); } else { return(-1); } }); AStar.CreateBuffer(solids, 0.5f); } }
public void AddObject(EnvObject obj) { objects.Add(obj); }