当前位置: 首页>>代码示例>>C#>>正文


C# Dungeon.OverlapsCorridor方法代码示例

本文整理汇总了C#中Dungeon.OverlapsCorridor方法的典型用法代码示例。如果您正苦于以下问题:C# Dungeon.OverlapsCorridor方法的具体用法?C# Dungeon.OverlapsCorridor怎么用?C# Dungeon.OverlapsCorridor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dungeon的用法示例。


在下文中一共展示了Dungeon.OverlapsCorridor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBrush

        private static bool CreateBrush(
            Vector2 minBrushSize,
            Vector2 maxBrushSize,
            Vector2 startingPosition,
            Vector2 corridorDirection,
            Dungeon dungeon,
            Room room,
            ref Rect brush)
        {
            //make sure a segment with the given dimensions won't go over the room bounds
            brush.width = Mathf.RoundToInt(Dungeon.Random.Range(minBrushSize.x, maxBrushSize.x - Mathf.Min(0, brush.x - startingPosition.x)));
            brush.height = Mathf.RoundToInt(Dungeon.Random.Range(minBrushSize.y, maxBrushSize.y - Mathf.Min(0, brush.y - startingPosition.y)));

            Rect brushPerimeter = new Rect(brush);
            Vector2 offset = corridorDirection.YX();
            brushPerimeter.min -= offset;
            brushPerimeter.max += offset;

            bool hadToExpandBrush = !room.Size.IsZero() && !room.Bounds.Overlaps(brushPerimeter);
            //make sure this new part will be connected to the room!
            while (!corridorDirection.IsZero() && hadToExpandBrush && !dungeon.OverlapsCorridor(brush.position, brush.size))
            {
                brush.width += corridorDirection.y;
                brush.height += corridorDirection.x;
                hadToExpandBrush = !room.Bounds.Overlaps(brush);
            }

            //make sure this new part won't go over a corridor!
            while (!corridorDirection.IsZero()
                    && brush.width > minBrushSize.x
                    && brush.height > minBrushSize.y
                    && dungeon.OverlapsCorridor(brush.position, brush.size))
            {
                if (hadToExpandBrush) //there's no point in reducing the brush if it had to be expanded to begin with!
                    return false;
                brush.width -= corridorDirection.y;
                brush.height -= corridorDirection.x;
            }

            brush.width = Mathf.Min(brush.width, maxBrushSize.x);
            brush.height = Mathf.Min(brush.height, maxBrushSize.y);

            return true;
        }
开发者ID:LuciusSixPercent,项目名称:Finsternis,代码行数:44,代码来源:RoomFactory.cs

示例2: CarveRoom

        public static bool CarveRoom(Dungeon dungeon, Corridor corridor, Vector4 brushSizeVariation, Vector2 maxRoomSize, int maxBrushStrokes, out Room room)
        {
            Vector2 startingPosition = corridor ? corridor.Bounds.max : Vector2.zero;
            Vector2 corridorDirection = corridor ? corridor.Direction : Vector2.zero;
            Vector2 minBrushSize = brushSizeVariation.XY();
            Vector2 maxBrushSize = brushSizeVariation.ZW();

            Rect brush = new Rect(startingPosition, Vector2.zero);

            //move the room one up or to the left so it aligns properly to the corridor
            brush.x -= corridorDirection.y;
            brush.y -= corridorDirection.x;

            room = Room.CreateInstance(brush.position, Dungeon.Random);

            if (brush.x < 0 || brush.y < 0
                || !AdjustCoordinate(corridorDirection, minBrushSize, dungeon.Size, ref brush))
            {
                return false;
            }

            bool enoughSpaceForRoom = !dungeon.OverlapsCorridor(brush.position, minBrushSize);

            while (!corridorDirection.IsZero()
                    && !enoughSpaceForRoom //if the room is currently intersecting a corridor
                    && ((corridorDirection.y != 0 && brush.x >= 0 && brush.x + minBrushSize.x - 1 > room.Bounds.x)  //and it can be moved to the left (orUp)
                    || (corridorDirection.x != 0 && brush.y >= 0 && brush.y + minBrushSize.y - 1 > room.Bounds.y))) //while still being attached to the corridor
            {
                //move the room and check again
                brush.x -= corridorDirection.y;
                brush.y -= corridorDirection.x;
                enoughSpaceForRoom = !dungeon.OverlapsCorridor(brush.position, minBrushSize);//!dungeon.SearchInArea(pos, minSize, CellType.corridor);
            }

            if (!enoughSpaceForRoom) //if a room with the minimum size possible would still intersect a corridor, stop trying to make it
                return false;

            brush.x = Mathf.Clamp(brush.x, 0, dungeon.Width);
            brush.y = Mathf.Clamp(brush.y, 0, dungeon.Height);

            bool roomCarved = false;
            //mark cells at random locations within the room, until the maximum tries is reached
            for (int tries = 0; tries < maxBrushStrokes; tries++)
            {

                if (CreateBrush(
                    minBrushSize,
                    maxBrushSize,
                    startingPosition,
                    corridorDirection,
                    dungeon,
                    room,
                    ref brush))
                {
                    if (!brush.size.IsZero())
                    {
                        if (!dungeon.OverlapsCorridor(brush.position, brush.size))
                        {
                            if (AddCells(brush, dungeon, room) > 0)
                                roomCarved = true;
                        }
                    }
                }
                MoveBrush(dungeon, startingPosition, corridorDirection, room, minBrushSize, maxBrushSize, ref brush);
            }

            if (room.Position.x < 0 || room.Position.y < 0)
                throw new ArgumentOutOfRangeException("Room was carved outside of dungeon!\n" + room);

            return roomCarved;
        }
开发者ID:LuciusSixPercent,项目名称:Finsternis,代码行数:71,代码来源:RoomFactory.cs


注:本文中的Dungeon.OverlapsCorridor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。