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 MovePlayerBy(Point amount) { // Get the position the player will be at Point newPosition = Player.Position + amount; // Check to see if the position is within the map if (new Rectangle(0, 0, Width, Height).Contains(newPosition) && rogueMap.IsWalkable(newPosition.X, newPosition.Y)) { // Move the player Player.Position += amount; // Scroll the view area to center the player on the screen TextSurface.RenderArea = new Rectangle(Player.Position.X - (TextSurface.RenderArea.Width / 2), Player.Position.Y - (TextSurface.RenderArea.Height / 2), TextSurface.RenderArea.Width, TextSurface.RenderArea.Height); // If he view area moved, we'll keep our entity in sync with it. Player.RenderOffset = this.Position - TextSurface.RenderArea.Location; // Erase the status on the old field-of-view. foreach (var cell in previousFOV) { mapData[cell.X, cell.Y].RemoveCellFromView(this[cell.X, cell.Y]); } // Calculate the new field-of-view. previousFOV = rogueFOV.ComputeFov(Player.Position.X, Player.Position.Y, 10, true); // Set status on new field-of-view. foreach (var cell in previousFOV) { rogueMap.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true); mapData[cell.X, cell.Y].RenderToCell(this[cell.X, cell.Y], true, rogueMap.GetCell(cell.X, cell.Y).IsExplored); } } }