Ejemplo n.º 1
0
 public SpreadVault(GeneratorCell origin, int distance, GeneratorTile floor, GeneratorTile wall, bool isRoom = true) : base(origin)
 {
     Distance = distance;
     IsRoom   = isRoom;
     Floor    = floor;
     Wall     = wall;
 }
Ejemplo n.º 2
0
 public SpreadStatues(GeneratorCell origin, int distance, int gridHorizontal, int gridVertical, GeneratorTile tile) : base(origin)
 {
     Distance       = distance;
     GridHorizontal = gridHorizontal;
     GridVertical   = gridVertical;
     Tile           = tile;
 }
Ejemplo n.º 3
0
    /// <summary>
    /// 调整地图的整体位置
    /// </summary>
    void FindPathRoomsBtwMainRooms()
    {
        //// 寻找主房间路径之间穿过的房间
        //foreach (Path p in paths)
        //{
        //    foreach (GeneratorCell c in cells)
        //    {
        //        if (!c.isMainRoom && !c.isPathRoom)
        //        {
        //            foreach (BlockPath b in p.path)
        //            {
        //                if (LineRectangleIntersection(b, c))
        //                {
        //                    c.isPathRoom = true;
        //                    break;
        //                }
        //            }
        //        }
        //    }
        //}

        int index = 0;

        while (index < cells.Count)
        {
            GeneratorCell c = cells[index];
            if (c.isMainRoom)
            {
                maxX = Mathf.Max(c.x + c.width, maxX);
                maxY = Mathf.Max(c.y + c.height, maxY);
                minX = Mathf.Min(c.x, minX);
                minY = Mathf.Min(c.y, minY);

                index++;
            }
            else
            {
                cells.Remove(c);
            }
        }

        foreach (GeneratorCell c in cells)
        {
            c.x += Mathf.CeilToInt(Mathf.Abs(minX));
            c.y += Mathf.CeilToInt(Mathf.Abs(minY));
            maxX = Mathf.Max(c.x, c.width, maxX);
            maxY = Mathf.Max(c.y + c.height, maxX);
        }

        foreach (Path p in paths)
        {
            foreach (BlockPath b in p.path)
            {
                b.start.x += Mathf.Abs(minX);
                b.start.y += Mathf.Abs(minY);
                b.end.x   += Mathf.Abs(minX);
                b.end.y   += Mathf.Abs(minY);
            }
        }
    }
Ejemplo n.º 4
0
    void AddBossRoom()
    {
        int index = cells.Count;

        GeneratorCell cell = new GeneratorCell();

        cell.width  = Mathf.RoundToInt(levelStats.cellMaxWidth);
        cell.height = Mathf.RoundToInt(levelStats.cellMaxWidth);

        int roomMaxX = 0;
        int roomMaxY = 0;

        foreach (GeneratorCell c in cells)
        {
            if (c.isMainRoom)
            {
                roomMaxX = Mathf.Max(c.x + c.width, roomMaxX);
                roomMaxY = Mathf.Max(c.y + c.height, roomMaxY);
            }
        }

        float maxRadius = Mathf.Max(roomMaxX, roomMaxY);

        Vector2 pos = GetRandomPointInRing(maxRadius + cell.width);

        cell.x = Mathf.RoundToInt(pos.x);
        cell.y = Mathf.RoundToInt(pos.y);

        AddBossRoomPath(cell);

        cell.index      = index;
        cell.isMainRoom = true;
        cell.isBossRoom = true;
        cells.Add(cell);
    }
Ejemplo n.º 5
0
 public SpreadCave(GeneratorCell origin, int distance, GeneratorTile floor, GeneratorTile wall, bool wallOutside = true, float chance = 0.6f) : base(origin)
 {
     Distance    = distance;
     WallOutside = wallOutside;
     Chance      = chance;
     Floor       = floor;
     Wall        = wall;
 }
Ejemplo n.º 6
0
 public SpreadTower(GeneratorCell origin, int distance, float radius, GeneratorTile floor, GeneratorTile wall, bool wallOutside = true, bool isRoom = true) : base(origin)
 {
     Distance    = distance;
     Radius      = radius;
     WallOutside = wallOutside;
     IsRoom      = isRoom;
     Floor       = floor;
     Wall        = wall;
 }
Ejemplo n.º 7
0
    /// <summary>
    /// 将重叠部分的房间分散
    /// </summary>
    void SeparateCells()
    {
        bool cellCollision = true;

        while (cellCollision)
        {
            cellCollision = false;

            //利用选择排序进行判断房间是否重叠
            for (int i = 0; i < cells.Count; i++)
            {
                GeneratorCell c = cells[i];
                for (int j = i + 1; j < cells.Count; j++)
                {
                    GeneratorCell cb = cells[j];
                    if (c.CollidesWith(cb))
                    {
                        cellCollision = true;

                        int cbX = Mathf.RoundToInt((c.x + c.width) - cb.x);
                        int cbY = Mathf.RoundToInt((c.y + c.height) - cb.y);

                        int cX = Mathf.RoundToInt((cb.x + cb.width) - c.x);
                        int cY = Mathf.RoundToInt((cb.y + cb.height) - c.y);

                        if (cX < cbX)
                        {
                            if (cX < cY)
                            {
                                c.Shift(cX, 0);
                            }
                            else
                            {
                                c.Shift(0, cY);
                            }
                        }
                        else
                        {
                            if (cbX < cbY)
                            {
                                cb.Shift(cbX, 0);
                            }
                            else
                            {
                                cb.Shift(0, cbY);
                            }
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// AABB类结构,用于检测碰撞
    /// </summary>
    /// <param name="cell"></param>
    /// <returns></returns>
    public bool CollidesWith(GeneratorCell cell)
    {
        bool value = true;

        if (cell.x >= this.x + this.width ||
            cell.y >= this.y + this.height ||
            cell.x + cell.width <= this.x ||
            cell.y + cell.height <= this.y)
        {
            value = false;
        }

        return(value);
    }
Ejemplo n.º 9
0
    /// <summary>
    /// 通过坐标判断获取目标房间
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    GeneratorCell GetCellByPoint(float x, float y)
    {
        GeneratorCell cell = null;

        foreach (GeneratorCell c in cells)
        {
            if (c.x < x && c.y < y && c.x + c.width > x && c.y + c.height > y)
            {
                cell = c;
                break;
            }
        }

        return(cell);
    }
Ejemplo n.º 10
0
    /// <summary>
    /// 找到两个房间之间路径的起点和终点,暂时不需要
    /// </summary>
    void FindCellLines()
    {
        foreach (LineSegment l in spanningTree)
        {
            GeneratorCell cellStart = GetCellByPoint(l.p0.Value.x, l.p0.Value.y);
            //if (cellStart != null)
            //{

            //}
            //else
            //    Debug.LogError("Could not find cell start for " + l.p0.Value);

            GeneratorCell cellEnd = GetCellByPoint(l.p1.Value.x, l.p1.Value.y);
            //if (cellEnd != null)
            //{

            //}
            //else
            //    Debug.LogError("Could not find cell end for " + l.p1.Value);
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 给Boss房间添加单向的通路
    /// </summary>
    /// <param name="bossCell"></param>
    void AddBossRoomPath(GeneratorCell bossCell)
    {
        int     index  = 0;
        float   dis    = 0f;
        float   minDis = float.PositiveInfinity;
        Vector2 bPos   = new Vector2(bossCell.x, bossCell.y);

        foreach (GeneratorCell c in cells)
        {
            Vector2 cPos = new Vector2(c.x, c.y);
            dis = (cPos - bPos).magnitude;
            if (dis < minDis)
            {
                minDis = dis;
                index  = c.index;
            }
        }

        Path path = new Path();

        Vector2 startPoint = new Vector2(cells[index].x + cells[index].width / 2,
                                         cells[index].y + cells[index].height / 2);
        Vector2 endPoint = new Vector2(bossCell.x + bossCell.width / 2,
                                       bossCell.y + bossCell.height / 2);

        BlockPath b1 = new BlockPath();

        b1.start = startPoint;
        b1.end   = new Vector2(endPoint.x, startPoint.y);

        BlockPath b2 = new BlockPath();

        b2.start = b1.end;
        b2.end   = endPoint;

        path.path.Add(b1);
        path.path.Add(b2);
        paths.Add(path);
    }
Ejemplo n.º 12
0
    /// <summary>
    /// 创建房间
    /// </summary>
    void CreatCells()
    {
        RandomFromDistribution.ConfidenceLevel_e confLevel = RandomFromDistribution.ConfidenceLevel_e._80;

        percFromGraphToPaths = levelStats.perFromGraphToPaths;
        mainRoomMeanCutoff   = levelStats.mainRoomCutOff;
        int   numberOfCells    = levelStats.numberOfCells;
        float roomCircleRadius = levelStats.roomCircleRadius;

        float cellMinWidth  = levelStats.cellMinWidth;
        float cellMaxWidth  = levelStats.cellMaxWidth;
        float cellMinHeight = levelStats.cellMinHeight;
        float cellMaxHeight = levelStats.cellMaxHeight;

        for (int i = 0; i < numberOfCells; i++)
        {
            float minWidthScalar  = cellMinWidth;
            float maxWidthScalar  = cellMaxWidth;
            float minHeightScalar = cellMinHeight;
            float maxHeightScalar = cellMaxHeight;

            GeneratorCell cell = new GeneratorCell();
            //使房间大小符合随机范围内的正态分布
            cell.width  = Mathf.RoundToInt(RandomFromDistribution.RandomRangeNormalDistribution(minWidthScalar, maxWidthScalar, confLevel));
            cell.height = Mathf.RoundToInt(RandomFromDistribution.RandomRangeNormalDistribution(minHeightScalar, maxHeightScalar, confLevel));

            Vector2 pos = GetRandomPointInCircle(roomCircleRadius);
            cell.x     = Mathf.RoundToInt(pos.x);
            cell.y     = Mathf.RoundToInt(pos.y);
            cell.index = i;
            cells.Add(cell);
            widthAvg  += cell.width;
            heightAvg += cell.height;
        }

        widthAvg  /= cells.Count;
        heightAvg /= cells.Count;
    }
Ejemplo n.º 13
0
 protected SpreadTile(GeneratorCell origin)
 {
     Origin = origin;
 }
Ejemplo n.º 14
0
 private bool IsNaturalWall(GeneratorCell cell)
 {
     return(cell.Tile.HasTag(TileTag.Wall) && !cell.Tile.HasTag(TileTag.Artificial));
 }
Ejemplo n.º 15
0
 public SpreadPlatform(GeneratorCell origin, int distance, GeneratorTile tile) : base(origin)
 {
     Distance = distance;
     Tile     = tile;
 }
Ejemplo n.º 16
0
 public SpreadOre(GeneratorCell origin, int distance, float chance, GeneratorTile tile) : base(origin)
 {
     Distance = distance;
     Chance   = chance;
     Tile     = tile;
 }
Ejemplo n.º 17
0
 public SpreadGlow(GeneratorCell origin, int distance, float chance, bool glowing) : base(origin)
 {
     Distance = distance;
     Chance   = chance;
     Glowing  = glowing;
 }