public void ConnectEdgeWalls(GeneratingTileInfo other, Direction directionToOther) { var edges = this.edgeWalls[directionToOther]; var otherEdges = other.edgeWalls[directionToOther.Opposite()]; edges.ConnectWalls(otherEdges); }
public void GenerateWalls() { this.Walls = new List <Wall>(); this.edgeWalls = new Dictionary <Direction, EdgeWallPair>(); var wallsIn = new Dictionary <Direction, Wall>(); var wallsOut = new Dictionary <Direction, Wall>(); if (this.OpenSides.Any()) { var edges = this.OpenSides.Enumerate() .Select(d => new { Direction = d, Points = GeneratingTileInfo.makeWallPoints(d, this.CorridorWidths[(int)d]) }).ToList(); for (int i = 0; i < edges.Count; i++) { var from = edges[i]; var to = edges[(i + 1) % edges.Count]; var walls = GeneratingTileInfo.makeWallSections(from.Points.Item2, to.Points.Item1).ToList(); wallsIn[from.Direction] = walls.First(); wallsOut[to.Direction] = walls.Last(); this.Walls.AddRange(walls); } foreach (var direction in this.OpenSides.Enumerate()) { this.edgeWalls[direction] = new EdgeWallPair(wallsIn[direction], wallsOut[direction]); } } }
public Tilemap <TileInfo> Generate() { if (!this.MuteAllOutput) { Console.WriteLine("------------------------------"); Console.WriteLine("Generating level with radius {0} ({1} tiles)...", this.Radius, Extensions.TileCountForRadius(this.Radius)); } var timer = SteppedStopwatch.StartNew(); timer.Mute = this.MuteAllOutput || !this.LogGenerationDetails; #region initialise var tempMap = new Tilemap <GeneratingTileInfo>(this.Radius); timer.WriteStepToConsole("Made mutable tilemap ......... {0}"); var tiles = tempMap.ToList(); timer.WriteStepToConsole("Enumerated tiles ............. {0}"); //var tilesSpiral = tempMap.TilesSpiralOutward.ToList(); //var tilesDistance = tiles.OrderBy( // t => (Settings.Game.Level.TileToPosition * t.Xy).LengthSquared // ).ToList(); //var infos = new List<GeneratingTileInfo>(tiles.Count); foreach (var tile in tiles) { var info = new GeneratingTileInfo(); //infos.Add(info); tempMap[tile] = info; } timer.WriteStepToConsole("Filled mutable tiles ......... {0}"); #endregion var centerTile = new GeneratingTile(tempMap, 0, 0); #region open walls centerTile.OpenRandomSpanningTree(this.MinCorridorWidth, this.MaxCorridorWidth); timer.WriteStepToConsole("Opened random spanning tree .. {0}"); if (this.OpennessCore > 0 || this.OpennessRim > 0) { tiles.OpenRandomWalls(t => GameMath.Lerp( this.OpennessCore, this.OpennessRim, (float)t.Radius / this.Radius), this.MinCorridorWidth, this.MaxCorridorWidth); timer.WriteStepToConsole( string.Format("Opened {0:0}%-{1:0}% random walls ", this.OpennessCore * 100, this.OpennessRim * 100) .PadRight(30, '.') + " {0}"); } #endregion #region make level geometry tiles.MakeWalls(); timer.WriteStepToConsole("Generated level walls ........ {0}"); tiles.MakeFloors(); timer.WriteStepToConsole("Generated level floors ....... {0}"); #endregion #region light level var lightBuffer1 = new Tilemap <float>(this.Radius); var lightBuffer2 = new Tilemap <float>(this.Radius); lightBuffer1.SetRandom(); lightBuffer1[0, 0] = 0.5f; lightBuffer1.DilateTo(tempMap, lightBuffer2); foreach (var tile in lightBuffer2.Where(t => t.Radius == this.Radius)) { lightBuffer2[tile] = 1f; } lightBuffer2.SmoothTo(tempMap, lightBuffer1); //lightBuffer1.SmoothTo(tempMap, lightBuffer2); lightBuffer1.SetBrightness(tempMap); timer.WriteStepToConsole("Generated level lightness .... {0}"); #endregion #region build var result = tempMap.Build(); timer.WriteStepToConsole("Build immutable tilemap ...... {0}"); #endregion if (!this.MuteAllOutput) { timer.Mute = false; timer.WriteTotalToConsole("Generated level in {0}"); Console.WriteLine("------------------------------"); } return(result); }