protected override float RandomBranchAngle(RoomDef r) { Vector2 center; if (firstLoop.Contains(r)) { center = firstLoopCenter; } else { center = secondLoopCenter; } float toCenter = AngleBetweenPoints(new Vector2((r.Left + r.Right) / 2f, (r.Top + r.Bottom) / 2f), center); if (toCenter < 0) { toCenter += 360f; } float currAngle = Rnd.Float(360f); for (var i = 0; i < 4; i++) { float newAngle = Rnd.Float(360f); if (Math.Abs(toCenter - newAngle) < Math.Abs(toCenter - currAngle)) { currAngle = newAngle; } } return(currAngle); }
public static void Paint(Level level, RoomDef room, int i = -1, bool gold = false) { var painter = i == -1 ? Instance.Generate() : Instance.Get(i); painter.Paint(level, room, new Rect(room.Left + 1, room.Top + 1, room.Left + 1 + room.GetWidth() - 2, room.Top + 1 + room.GetHeight() - 2), gold); }
public void Build(FileInfo outFile, RoomDef room) { Room = room; Builder = new StringBuilder(); // build the floor Verts.Add(new Vector3(0, 0, room.Bounds.Height)); Verts.Add(new Vector3(room.Bounds.Width, 0, room.Bounds.Height)); Verts.Add(new Vector3(room.Bounds.Width, 0, 0)); Verts.Add(new Vector3(0, 0, 0)); Normals.Add(new Vector3(0, 1, 0)); UVs.Add(new Vector2(0, room.Bounds.Height)); UVs.Add(new Vector2(room.Bounds.Width, room.Bounds.Height)); UVs.Add(new Vector2(room.Bounds.Width, 0)); UVs.Add(new Vector2(0, 0)); Builder.AppendLine("g " + room.FloorObjectName); Builder.AppendLine("usemtl " + room.FloorMaterialName); Builder.AppendLine("usemap " + room.FloorMaterialName); Builder.AppendLine("f 0//0//0 1//1//0 2//2//0 3//3//0"); // build low walls // north }
protected static float AngleBetweenRooms(RoomDef From, RoomDef To) { var FromCenter = new Vector2((From.Left + From.Right) / 2f, (From.Top + From.Bottom) / 2f); var ToCenter = new Vector2((To.Left + To.Right) / 2f, (To.Top + To.Bottom) / 2f); return(AngleBetweenPoints(FromCenter, ToCenter)); }
public static bool[][] Generate(RoomDef R) { var Maze = new bool[R.GetWidth()][]; for (var X = 0; X < Maze.Length; X++) { Maze[X] = new bool[R.GetHeight()]; for (var Y = 0; Y < Maze[0].Length; Y++) { if (X == 0 || X == Maze.Length - 1 || Y == 0 || Y == Maze[0].Length - 1) { Maze[X][Y] = Filled; } } } foreach (var D in R.Connected.Values) { try { Maze[D.X - R.Left][D.Y - R.Top] = Empty; } catch (Exception e) { } } return(Generate(Maze)); }
public void Build(FileInfo outFile, RoomDef room) { Room = room; Builder = new StringBuilder(); // build the floor Verts.Add(new Vector3(0,0,room.Bounds.Height)); Verts.Add(new Vector3(room.Bounds.Width, 0, room.Bounds.Height)); Verts.Add(new Vector3(room.Bounds.Width, 0, 0)); Verts.Add(new Vector3(0, 0, 0)); Normals.Add(new Vector3(0, 1, 0)); UVs.Add(new Vector2(0,room.Bounds.Height)); UVs.Add(new Vector2(room.Bounds.Width, room.Bounds.Height)); UVs.Add(new Vector2(room.Bounds.Width, 0)); UVs.Add(new Vector2(0, 0)); Builder.AppendLine("g " + room.FloorObjectName); Builder.AppendLine("usemtl " + room.FloorMaterialName); Builder.AppendLine("usemap " + room.FloorMaterialName); Builder.AppendLine("f 0//0//0 1//1//0 2//2//0 3//3//0"); // build low walls // north }
public static void Paint(Level level, RoomDef room, WallRegistry registry = null, int i = -1) { var painter = i == -1 ? (registry ?? Instance).Generate() : (registry ?? Instance).Get(i); painter.Paint(level, room, new Rect(room.Left + 1, room.Top + 1, room.Left + 1 + room.GetWidth() - 2, room.Top + 1 + room.GetHeight() - 2)); }
protected void CleanDiagonalEdges(RoomDef room) { if (Patch == null) { return; } var w = room.GetWidth() - 2; for (var i = 0; i < Patch.Length - w - 1; i++) { if (!Patch[i]) { continue; } if (i % w != 0) { if (Patch[i - 1 + w] && !(Patch[i - 1] || Patch[i + w])) { Patch[i - 1 + w] = false; } } if ((i + 1) % w != 0) { if (Patch[i + 1 + w] && !(Patch[i + 1] || Patch[i + w])) { Patch[i + 1 + w] = false; } } } }
public override void Paint(Level level, RoomDef room, Rect inside) { var t = Tiles.RandomFillWall(); var hw = room.GetWidth() / 2; var hh = room.GetHeight() / 2; var before = Rnd.Chance(); var frame = Rnd.Chance(); if (before && frame) { Painter.Rect(level, room, 1, Tile.Chasm); } switch (Rnd.Int(4)) { case 0: { Painter.Fill(level, room.Left + 1, room.Top + 1, hw, hh, t); break; } case 1: { Painter.Fill(level, room.Right - hw, room.Top + 1, hw, hh, t); break; } case 2: { Painter.Fill(level, room.Left + 1, room.Bottom - hh, hw, hh, t); break; } default: { Painter.Fill(level, room.Right - hw, room.Bottom - hh, hw, hh, t); break; } } if (Rnd.Chance()) { var s = Math.Min(inside.GetWidth(), inside.GetHeight()); var c = room.GetTileCenter(); var sz = s / 3; inside = new Rect(c.X - sz / 2, c.Y - sz / 2).Resize(sz, sz); Painter.Fill(level, inside, Tiles.Pick(Tile.Chasm, Tiles.RandomFillWall())); if (Rnd.Chance()) { inside = inside.Shrink(Rnd.Int(1, 3)); Painter.Fill(level, inside, Tiles.Pick(Tile.Chasm, Tiles.RandomFillWall())); } } if (!before && frame) { Painter.Rect(level, room, 1, Tile.Chasm); } room.PaintTunnel(level, Tiles.RandomFloor(), room.GetCenterRect(), Rnd.Chance(30)); }
public override void Paint(Level level, RoomDef room, Rect inside) { var t = Tiles.RandomSolid(); fl = Rnd.Chance(10); CreateWalls(level, new Rect(room.Left + 1, room.Top + 1, room.Right - 1, room.Bottom - 1), t); }
private void SimplePaint(Level level, RoomDef room) { var fill = 0.25f + (room.GetWidth() * room.GetHeight()) / 1024f; Setup(level, room, fill, 4, true); CleanDiagonalEdges(room); PaintPatch(level, room, Tiles.RandomSolid()); }
public override bool CanConnect(RoomDef r) { if (Run.Type != RunType.BossRush && LevelSave.BiomeGenerated is JungleBiome && !(r is HiveRoom)) { return(false); } return(base.CanConnect(r)); }
public override bool CanConnect(RoomDef R, Dot P) { if (P.X == Left || P.X == Right || P.Y == Top) { return(false); } return(base.CanConnect(R, P)); }
public override bool CanConnect(RoomDef r, Dot p) { if (p.X == Left + 1 || p.X == Right - 1 || p.Y == Top + 1 || p.Y == Bottom - 1) { return(false); } return(base.CanConnect(r, p)); }
public override bool CanConnect(RoomDef R) { if (!(R is ShopRoom || R is SubShopRoom)) { return(false); } return(base.CanConnect(R)); }
public override bool CanConnect(RoomDef R) { if (R is GrannyRoom || R is OldManRoom || R is PrebossRoom || R is ShopRoom) { return(base.CanConnect(R)); } return(false); }
public override void Paint(Level level, RoomDef room, Rect inside) { Painter.Fill(level, room, 1, Tiles.Pick(Tile.Chasm, Tile.SensingSpikeTmp)); var f = Tiles.RandomFloor(); Painter.Fill(level, room, Rnd.Int(2, 4), f); room.PaintTunnel(level, Rnd.Chance(30) ? f : Tiles.RandomFloorOrSpike(), room.GetCenterRect()); }
private void printToMap(char[,] map, RoomDef room, char tile) { for (int j = room.getNW()[1]; j <= room.getSW()[1]; j++) { for (int i = room.getNW()[0]; i <= room.getNE()[0]; i++) { //Debug.Log("i = " + i + ", j = " + j); map[i, j] = tile; //TODO Array index out of bounds exception } } }
public override void Paint(Level level, RoomDef room, Rect inside, bool gold) { FloorRegistry.Paint(level, room, -1, gold); var m = Rnd.Int(2, 4); var a = gold && Rnd.Chance(); Painter.Fill(level, room, m, a ? Tile.FloorD : Tiles.RandomFloor()); Painter.Fill(level, room, m + 1, !a && gold && Rnd.Chance() ? Tile.FloorD : Tiles.RandomNewFloor()); Painter.Fill(level, room, m + 1, LevelSave.BiomeGenerated is DesertBiome ? Tiles.RandomNewFloor() : Tile.Water); }
//Function to make a room only take up a portion of its possible space, to space out the map private void depleteTheRoom(RoomDef room) { //Decide what percent to deplete the room horizontally and vertically by float horizontalPercent = randomHorDist.Next(30, 71); float verticalPercent = randomVerDist.Next(30, 71); //Distribute those percents to the four sides randomly float splitPercent = randomHorVerSplit.Next(10, 91); float westPercent = verticalPercent * (splitPercent / 100); float eastPercent = verticalPercent - westPercent; splitPercent = randomHorVerSplit.Next(10, 91); float northPercent = horizontalPercent * (splitPercent / 100); float southPercent = horizontalPercent - northPercent; //Calculate room width and height float roomWidth = room.getNE()[0] - room.getNW()[0]; float roomHeight = room.getSE()[1] - room.getNE()[1]; //Deplete each side by their percent of the width or height float northCalc = roomHeight * (northPercent / 100); int northDeplete = Mathf.RoundToInt(northCalc); room.setNE(room.getNE()[0], room.getNE()[1] + northDeplete); room.setNW(room.getNW()[0], room.getNW()[1] + northDeplete); float southCalc = roomHeight * (southPercent / 100); int southDeplete = Mathf.RoundToInt(southCalc); room.setSE(room.getSE()[0], room.getSE()[1] - southDeplete); room.setSW(room.getSW()[0], room.getSW()[1] - southDeplete); float westCalc = roomWidth * (westPercent / 100); int westDeplete = Mathf.RoundToInt(westCalc); room.setNW(room.getNW()[0] + westDeplete, room.getNW()[1]); room.setSW(room.getSW()[0] + westDeplete, room.getSW()[1]); float eastCalc = roomWidth * (eastPercent / 100); int eastDeplete = Mathf.RoundToInt(eastCalc); room.setNE(room.getNE()[0] - eastDeplete, room.getNE()[1]); room.setSE(room.getSE()[0] - eastDeplete, room.getSE()[1]); /* * Debug.Log("northPercent = " + northPercent + "%"); * Debug.Log("southPercent = " + southPercent + "%"); * Debug.Log("eastPercent = " + eastPercent + "%"); * Debug.Log("westPercent = " + westPercent + "%"); */ }
public override void Paint(Level level, RoomDef room, Rect inside, bool gold) { var tiles = new[] { Tile.FloorA, Tile.FloorB, Tile.FloorC }; if (gold) { tiles[Rnd.Int(3)] = Tile.FloorD; } tiles = tiles.OrderBy(x => Rnd.Generator.Next()).ToArray(); var a = tiles[0]; var b = tiles[1]; var c = Rnd.Chance() ? a : tiles[2]; var start = Rnd.Float(); var size = Rnd.Int(1, 4); var two = Rnd.Chance(); for (int y = inside.Top; y < inside.Bottom; y++) { for (int x = inside.Left; x < inside.Right; x++) { int val; if (two) { val = ((int)(x + start) % size == 0 ? 1 : ((int)(y + start)) % size == 0 ? 1 : 0) % 3; } else { val = (((int)(x + start) % size == 0 ? 1 : 0) + ((int)(y + start) % size == 0 ? 1 : 0)) % 3; } var tile = a; if (val == 1) { tile = b; } else if (val == 2) { tile = c; } Painter.Set(level, x, y, tile); } } }
protected void PaintPatch(Level level, RoomDef room, Tile tile) { var w = room.GetWidth() - 2; for (var y = 0; y < room.GetHeight() - 2; y++) { for (var x = 0; x < w; x++) { if (Patch[x + y * w]) { level.Set(room.Left + x + 1, room.Top + y + 1, Tile.FloorA); level.Set(room.Left + x + 1, room.Top + y + 1, tile); } } } }
public override bool CanConnect(RoomDef R, Dot P) { if (P.X == Left || P.X == Right) { if (P.Y == Top + 1 || P.Y == Bottom - 1) { return(false); } } else if (P.Y == Top || P.Y == Bottom) { return(false); } return(base.CanConnect(R, P)); }
public override void Paint(Level level, RoomDef room, Rect inside) { base.Paint(level, room, inside); var t = Tiles.Pick(Tile.WallA, Tile.Planks); if (Rnd.Chance()) { Painter.DrawLine(level, new Dot(room.Left + room.GetWidth() / 2, room.Top + 1), new Dot(room.Left + room.GetWidth() / 2, room.Bottom - 1), t); PlaceTeleporter(level, new Dot(room.Left + room.GetWidth() / 4, Rnd.Int(room.Top + 3, room.Bottom - 3)), new Dot(room.Left + room.GetWidth() / 4 * 3, Rnd.Int(room.Top + 3, room.Bottom - 3))); } else { Painter.DrawLine(level, new Dot(room.Left + 1, room.Top + room.GetHeight() / 2), new Dot(room.Right - 1, room.Top + room.GetHeight() / 2), t); PlaceTeleporter(level, new Dot(Rnd.Int(room.Left + 3, room.Right - 3), room.Top + room.GetHeight() / 4), new Dot(Rnd.Int(room.Left + 3, room.Right - 3), room.Top + room.GetHeight() / 4 * 3)); } }
protected override float PlaceRoom(List <RoomDef> Collision, RoomDef Prev, RoomDef Next, float Angle) { var v = base.PlaceRoom(Collision, Prev, Next, Angle); if (v > -1 && Next is ShopRoom) { Log.Info("Placing sub shop rooms"); foreach (var r in SubShop) { var a = Rnd.Angle(); var i = 0; while (true) { var an = PlaceRoom(Collision, Next, r, a % 360); if ((int)an != -1) { break; } i++; if (i > 36) { Log.Error("Failed."); return(-1); } a += 10; } } /*if (SubShop.Count > 0) { * for (var i = 0; i < SubShop.Count - 1; i++) { * for (var j = i + 1; j < SubShop.Count; j++) { * SubShop[i].ConnectTo(SubShop[j]); * } * } * }*/ Log.Info("Failed to fail."); } return(v); }
private bool InvestigateDoor(RoomDef room, DoorPlaceholder cameFrom) { if (room is LibraryConnectionRoom && room != this) { return(true); } foreach (var door in room.Connected) { if (door.Value != cameFrom) { return(InvestigateDoor(door.Key, door.Value)); } } return(false); }
public override void Paint(Level level, RoomDef room, Rect inside) { var fill = 0.25f + (room.GetWidth() * room.GetHeight()) / 2048f; var t = Rnd.Chance(20) ? Tile.Lava : Tiles.RandomFloorOrSpike(); Setup(level, room, fill, 0, true); CleanDiagonalEdges(room); for (var i = room.Top + 1; i < room.Bottom; i++) { for (var j = room.Left + 1; j < room.Right; j++) { if (Patch[ToIndex(room, j, i)]) { level.Set(j, i, t); } } } }
public override bool CanConnect(RoomDef R, Dot P) { if (P.X == Left || P.X == Right) { if (Math.Abs(P.Y - (Top + GetHeight() / 2)) > 0) { return(false); } } else { if (Math.Abs(P.X - (Left + GetWidth() / 2)) > 0) { return(false); } } return(base.CanConnect(R, P)); }
public override void Paint(Level level, RoomDef room, Rect inside) { Painter.Fill(level, room, Tiles.RandomWall()); var t = Tiles.RandomSolid(); if (t == Tile.Lava) { Painter.Fill(level, inside, Tiles.RandomFloor()); } Painter.Fill(level, inside, t); Painter.FillEllipse(level, inside, Tiles.RandomFloor()); // fixme: breaks custom floors var before = Rnd.Chance(); if (before) { if (Rnd.Chance()) { room.PaintTunnel(level, Tiles.RandomNewFloor(), new Rect(room.GetCenter()), true); } room.PaintTunnel(level, Tiles.RandomNewFloor(), new Rect(room.GetCenter())); } if (Rnd.Chance()) { Painter.Ellipse(level, inside, Tiles.RandomFloor()); } if (!before) { if (Rnd.Chance()) { room.PaintTunnel(level, Tiles.RandomNewFloor(), new Rect(room.GetCenter()), true); } room.PaintTunnel(level, Tiles.RandomNewFloor(), new Rect(room.GetCenter())); } }
public override bool CanConnect(RoomDef R, Dot P) { if (P.X == Left || P.X == Right) { if (P.Y - Top < 3 || Bottom - P.Y < 3) { return(false); } } else { if (P.X - Left < 3 || Right - P.X < 3) { return(false); } } return(base.CanConnect(R, P)); }
public override void Paint(Level level, RoomDef room, Rect inside, bool gold) { if (Rnd.Chance()) { Painter.Fill(level, inside, Tiles.RandomFloor()); inside = inside.Shrink(Rnd.Int(1, 3)); } var a = gold ? Tile.FloorD : Tiles.RandomFloor(); var b = Tiles.RandomNewFloor(); for (int y = inside.Top; y < inside.Bottom; y++) { for (int x = inside.Left; x < inside.Right; x++) { Painter.Set(level, x, y, (x + y * 2) % 4 == 0 ? a : b); } } }