public override void GenerateLevel() { DungeonRectangle rect = new DungeonRectangle(new Vector2(0, 0), new Vector2(width, height)); rect.StartSplitting(Rooms); Tile[,] map = new Tile[(int)rect.Size.x, (int)rect.Size.y]; for (int x = 0; x < map.GetLength(0); x++) { for (int y = 0; y < map.GetLength(1); y++) { map[x, y] = new Tile() { TileNumber = 1 }; } } foreach (Vector2 vect in rect.Visualize()) { map[(int)Mathf.Abs(vect.x), (int)Mathf.Abs(vect.y)].TileNumber = 0; } this.map = map; this.Obstacles.Add(1); }
public bool Split() { if (ChildOne != null) { return false; } bool dir = (Random.value > 0.5 ? false : true); float max = (dir ? Size.y : Size.x) - MIN_SIZE; if (max <= MIN_SIZE) { return false; } float split = Random.Range(0, max); if (split < MIN_SIZE) { split = MIN_SIZE; } if (dir) { ChildOne = new DungeonRectangle(Position, new Vector2(Size.x, split)); ChildTwo = new DungeonRectangle(new Vector2(Position.x, Position.y - split), new Vector2(Size.x, Size.y - split)); } else { ChildOne = new DungeonRectangle(Position, new Vector2(split, Size.y)); ChildTwo = new DungeonRectangle(new Vector2(Position.x + split, Position.y), new Vector2(Size.x - split, Size.y)); } return true; }
public Vector2[] ConnectTo(DungeonRectangle connector) { return GenHelpers.PlotLine(Position.x + Size.x / 2, Position.y - Size.y / 2, connector.Position.x + connector.Size.x / 2, connector.Position.y - connector.Size.y / 2, true); }