/// <summary> /// Creates a server-side version of the map /// </summary> public Map(string name, string description, int width, int height, int id) { ID = id; Name = name; Description = description; Width = width; Height = height; IsServer = true; //Running a server Tiles = new Tile[Width, Height, 2]; Players = new List<Bricklayer.Common.Entities.Player>(); Generate(); }
/// <summary> /// Generates a simple world with borders /// </summary> public void Generate() { //Temporary Generation int[] heightMap = new int[Width]; //Config int offset = Height - 17; float peakheight = 5; float flatness = 40; int iterations = 8; double[] rands = new double[iterations]; for (int i = 0; i < iterations; i++) { rands[i] = random.NextDouble() + i; } for (int x = 0; x < Width; x++) { double height = 0; for (int i = 0; i < iterations; i++) { height += peakheight / rands[i] * Math.Sin((float)x / flatness * rands[i] + rands[i]); } heightMap[x] = (int)height + offset; } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (x == 0 || y == 0 || x == Width - 1 || y == Height - 1) Tiles[x, y, 1] = new Tile(BlockType.Default); else { if (y > heightMap[x] + 8) Tiles[x, y, 1] = new Tile(BlockType.Stone); else if (y > heightMap[x]) Tiles[x, y, 1] = new Tile(BlockType.Dirt); else if (y == heightMap[x]) Tiles[x, y, 1] = new Tile(BlockType.Grass); else Tiles[x, y, 1] = new Tile(BlockType.Empty); } Tiles[x, y, 0] = new Tile(BlockType.Empty); } } }
public static Bricklayer.Server.World.Map LoadMap(string name) { Bricklayer.Server.World.Map map; using (BinaryReader binaryReader = new BinaryReader( //Create a new binary writer to write to the file new BufferedStream( File.Open(Path.Combine(mapFolder, name + mapSuffix), FileMode.Open)))) { //Read general data map = new Bricklayer.Server.World.Map(binaryReader.ReadString(), binaryReader.ReadString(), binaryReader.ReadInt16(), binaryReader.ReadInt16(), Server.Maps.Count) { Rating = binaryReader.ReadDouble() }; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { Tile fg; Tile bg; SaveFlags sf = (SaveFlags)binaryReader.ReadByte(); int RLE = 0; if (sf.HasFlag(SaveFlags.RLE)) RLE = binaryReader.ReadInt16(); if (sf.HasFlag(SaveFlags.Foreground)) fg = new Tile(BlockType.FromID(binaryReader.ReadByte())); else fg = new Tile(BlockType.Empty); if (sf.HasFlag(SaveFlags.Background)) bg = new Tile(BlockType.FromID(binaryReader.ReadByte())); else bg = new Tile(BlockType.Empty); map.Tiles[x, y, 1] = fg; map.Tiles[x, y, 0] = bg; if (RLE > 0) //RLE enabled { for (int i = 1; i <= RLE; i++) { map.Tiles[x + i, y, 1] = fg; map.Tiles[x + i, y, 0] = bg; } x += RLE; } } } } return map; }
public bool Equals(Tile compareTo) { return Block.ID == compareTo.Block.ID; }