private void GenerateMap() { // Create the map. RogueSharp.MapCreation.IMapCreationStrategy <RogueSharp.Map> mapCreationStrategy = new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy <RogueSharp.Map>(Width, Height, 100, 15, 4); rogueMap = RogueSharp.Map.Create(mapCreationStrategy); rogueFOV = new RogueSharp.FieldOfView(rogueMap); // Create the local cache of the map data. mapData = new MapObjects.MapObjectBase[Width, Height]; // Loop through the map information generated by RogueSharp and create out cached visuals of that data. foreach (var cell in rogueMap.GetAllCells()) { if (cell.IsWalkable) { // Our local information about each map square. mapData[cell.X, cell.Y] = new MapObjects.Floor(); // Copy the appearance we've defined for Floor or Wall or whatever to the actual console data that is being rendered. mapData[cell.X, cell.Y].RenderToCell(this[cell.X, cell.Y], false, false); } else { rogueMap.SetCellProperties(cell.X, cell.Y, false, false); mapData[cell.X, cell.Y] = new MapObjects.Wall(); mapData[cell.X, cell.Y].RenderToCell(this[cell.X, cell.Y], false, false); // A wall blocks LOS rogueMap.SetCellProperties(cell.X, cell.Y, false, cell.IsWalkable); } } RogueSharp.Random.IRandom random = new RogueSharp.Random.DotNetRandom(); // Position the player somewhere on a walkable square. while (true) { int x = random.Next(Width - 1); int y = random.Next(Height - 1); if (rogueMap.IsWalkable(x, y)) { Player.Position = new Point(x, y); // Center the view area. TextSurface.RenderArea = new Rectangle(Player.Position.X - (TextSurface.RenderArea.Width / 2), Player.Position.Y - (TextSurface.RenderArea.Height / 2), TextSurface.RenderArea.Width, TextSurface.RenderArea.Height); Player.RenderOffset = this.Position - TextSurface.RenderArea.Location; break; } } }
public void SaveGame(RogueSharp.Map dm, int mapLevel, int randomSeed) { // save map Systems.SaveSystem saveSystem = new Systems.SaveSystem(); saveSystem.SaveMap(dm); //save stats saveSystem.SaveStats(mapLevel, randomSeed); // save Entities saveSystem.SaveEntites(Entities); }
public Map(int width, int height) { Width = width; Height = height; tiles = new int[Width, Height]; walkable = new bool[Width, Height]; transparent = new bool[Width, Height]; explored = new bool[Width, Height]; fovMap = new RogueSharp.Map(Width, Height); }
public void SaveMap(RogueSharp.Map dungeonMap) { RogueSharp.MapState saveMap = dungeonMap.Save(); string mapJson = Newtonsoft.Json.JsonConvert.SerializeObject(saveMap, Newtonsoft.Json.Formatting.Indented); using (StreamWriter sw = new StreamWriter("map.json")) { sw.Write(mapJson); } }
public void UpdateFovMap() { if (fovMap == null) { fovMap = new RogueSharp.Map(Width, Height); } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { FovMap.SetCellProperties(x, y, IsTransparent(x, y), IsWalkable(x, y)); } } }