Drought.World.HeightMap.initalise C# (CSharp) Method

initalise() public method

public initalise ( ) : void
return void
        public void initalise()
        {
            string fileName = LevelInfo.getFileName(level);

            FileStream fs = new FileStream("Content/HeightMaps/" + fileName + ".bmp", FileMode.Open, FileAccess.Read);
            BinaryReader r = new BinaryReader(fs);

            r.BaseStream.Seek(10, SeekOrigin.Current);
            int bitmapOffset = (int)r.ReadUInt32();

            r.BaseStream.Seek(4, SeekOrigin.Current);
            width = (int)r.ReadUInt32();
            height = (int)r.ReadUInt32();

            map = new float[width, height];

            r.BaseStream.Seek(bitmapOffset - 26, SeekOrigin.Current);
            for (int x = 0; x < height; x++)
            {
                for (int y = 0; y < width; y++)
                {
                    int currHeight = (int)r.ReadByte();
                    currHeight += r.ReadByte();
                    currHeight += r.ReadByte();
                    currHeight /= 8;

                    map[width - y - 1, height - x - 1] = currHeight;
                }
            }
            r.Close();

            for (int x = 1; x < width - 2; x++)
            {
                for (int y = 1; y < height - 2; y++)
                {
                    map[x, y] = (map[x - 1, y - 1] + map[x - 1, y] + map[x - 1, y + 1] +
                                map[x, y - 1] + map[x, y] + map[x, y + 1] +
                                map[x + 1, y - 1] + map[x + 1, y] + map[x + 1, y + 1]) / 9;
                }
            }
        }