public BLevel(int width, int height) { grid = new BBlock[width, height]; entities = new List <BEntity>(); mapname = "none"; playerStartPos = new Point((int)(width / AppInfo.TILESIZE), (int)(height / AppInfo.TILESIZE)); 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) { BBlockTemplate block = BBlocks.GetBlock(1); grid[x, y] = new BBlock(block.Name, block.Type, block.TexturePosition, x, y); } else { BBlockTemplate block = BBlocks.GetBlock(2); grid[x, y] = new BBlock(block.Name, block.Type, block.TexturePosition, x, y); } } } }
public BLevel(string mapname) { try { if (!Directory.Exists("Content/Maps")) { Directory.CreateDirectory("Content/Maps"); } if (!File.Exists($"Content/Maps/{mapname}.ls")) { throw new FileNotFoundException($"No map found with name '{mapname}'."); } var Map = BLevelFile.FromJson(File.ReadAllText($"Content/Maps/{mapname}.ls")); int width = Map.Width; int height = Map.Height; grid = new BBlock[width, height]; entities = new List <BEntity>(); this.mapname = mapname; playerStartPos = new Point(1, 1); int[] Tiles = Map.Layers[0].Data; int x = 0; int y = 0; for (int i = 0; i < Tiles.Length; i++) { BBlockTemplate block = BBlocks.GetBlock(Tiles[i]); grid[x, y] = new BBlock(block.Name, block.Type, block.TexturePosition, x, y); x++; if (x >= width) { x = 0; y++; } } playerStartPos = new Point(width / 2, height / 2); } catch (Exception e) { Console.WriteLine(e.Message); int width = 20; int height = 20; grid = new BBlock[width, height]; entities = new List <BEntity>(); this.mapname = "none"; playerStartPos = new Point(1, 1); 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) { BBlockTemplate block = BBlocks.GetBlock(1); grid[x, y] = new BBlock(block.Name, block.Type, block.TexturePosition, x, y); } else { BBlockTemplate block = BBlocks.GetBlock(2); grid[x, y] = new BBlock(block.Name, block.Type, block.TexturePosition, x, y); } } } } }