/// <summary> /// Initializes a new instance of the <see cref="Map"/> class. /// Creates an empty array for segmentDefinition, 3 layers each with /// room for 64 segments, an array of 16 ledges and a collision grid which is 20x20 /// then it reads segment definitions - to load a map from a file the Read() method /// has to be invoked manually (we do this in the initialize method from the main class) /// </summary> public Map() { segDef = new SegmentDefinitions[512]; mapSegment = new MapSegment[3, 64]; colisionGrid = new int[20, 20]; ledges = new Ledge[16]; for (int i = 0; i < 16; i++) { ledges[i] = new Ledge(); } GlobalFlags = new MapFlags(64); ReadSegmentDefinitions(); }
/// <summary> /// Reads the map from file. /// </summary> public void Read() { BinaryReader file = new BinaryReader(File.Open(@"Content/data/maps/" + path + ".zmx", FileMode.Open)); // read ledge information first for (int i = 0; i < ledges.Length; i++) { ledges[i] = new Ledge(); ledges[i].TotalNodes = file.ReadInt32(); for (int n = 0; n < ledges[i].TotalNodes; n++) { ledges[i].Nodes[n] = new Vector2( file.ReadSingle() * 2f, file.ReadSingle() *2f); } ledges[i].isHardLedge = file.ReadInt32(); } // read layer / segment information for (int l = 0; l < 3; l++) { for (int i = 0; i < 64; i++) { int t = file.ReadInt32(); if (t == -1) mapSegment[l, i] = null; else { mapSegment[l, i] = new MapSegment(); mapSegment[l, i].Index = t; mapSegment[l, i].location = new Vector2( file.ReadSingle(), file.ReadSingle()); } } } // read collision grid information for (int x = 0; x < 20; x++) { for (int y = 0; y < 20; y++) { colisionGrid[x, y] = file.ReadInt32(); } } mapScript = new MapScript(this); for (int i = 0; i < mapScript.Lines.Length; i++) { String s = file.ReadString(); if (s.Length > 0) mapScript.Lines[i] = new MapScriptLine(s); else mapScript.Lines[i] = null; } file.Close(); // turn off fog by default and start reading MapScript // if we find the init tag in the first line we process // the rest of the script in the update method Bucket = null; Water = 0f; Fog = -1; if (mapScript.GotoTag("init")) mapScript.IsReading = true; }