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


C# Dungeon.IsWithinDungeon方法代码示例

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


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

示例1: CarveCorridor

        /// <summary>
        /// Creates a corridor.
        /// </summary>
        /// <param name="roomBounds">Position and dimension of the room where the corridor shall start.</param>
        /// <param name="direction">The direction (right or bottom) of the corridor.</param>
        /// <param name="corridor">Bounds of the corridor created.</param>
        /// <returns>True if a corridor was created without any intersections.</returns>
        public static bool CarveCorridor(Dungeon dungeon, Room room, Vector2 direction, Vector2 minMaxCorridorLength, Vector2 minRoomDimensions, out Corridor corridor)
        {
            corridor = Corridor.CreateInstance(new Rect(), direction);

            if (!CanFitCorridor(dungeon, direction, room.Bounds, minMaxCorridorLength))
            {
                return false;
            }

            Vector2 corridorStart = Vector2.zero;
            int tries = 10;
            bool maySpawnCorridor = false;
            Vector2 sideOffset = direction.YX();
            for (int count = 0; !maySpawnCorridor && count < tries; count++)
            {
                corridorStart = room.GetRandomCell();

                //move the corridor starting point outside the room
                while (corridorStart.x < dungeon.Width && corridorStart.y < dungeon.Height && room.ContainsCell(corridorStart))
                    corridorStart += direction;

                Vector2 offsetA = corridorStart + sideOffset;
                Vector2 offsetB = corridorStart - sideOffset;

                if (dungeon.IsWithinDungeon(offsetA))
                {
                    if (dungeon[offsetA] != null)
                    {
                        maySpawnCorridor = false;
                        continue;
                    }
                    else
                    {
                        maySpawnCorridor = true;
                    }
                }
                if (dungeon.IsWithinDungeon(offsetB))
                {
                    if (dungeon[offsetB] != null)
                    {
                        maySpawnCorridor = false;
                        continue;
                    }
                    else
                    {
                        maySpawnCorridor = true;
                    }
                }
            }

            corridor.Position = corridorStart;

            //if there would be no space for the smallest room after making a corridor with the minimum length, no use creating one
            if ((direction.x != 0 && corridor.X + minRoomDimensions.x >= dungeon.Width)
                || (direction.y != 0 && corridor.Y + minRoomDimensions.y >= dungeon.Height))
                return false;

            //move the end of the corridor to the very edge of the room bounds (on the direction the corridor should go)
            while ((direction.x != 0 && corridor.LastCell.x < room.Bounds.xMax) || (direction.y != 0 && corridor.LastCell.y < room.Bounds.yMax))
                corridor.Length++;

            corridor.Length += Mathf.CeilToInt(Dungeon.Random.Range(minMaxCorridorLength.x, minMaxCorridorLength.y));

            if (corridor.Length == 0)
            {
                Debug.LogWarning("No use creating a corridor with 0 length (" + room.Bounds + ")");
                return false;
            }

            int predefinedSize = corridor.Length;
            int actualSize = 0;
            for (int size = 0; size < predefinedSize; size++)
            {
                Vector2 cell = corridor[size];
                if (!dungeon.IsWithinDungeon(cell) || dungeon[cell] != null)
                {
                    break;
                }
                actualSize = size + 1;
            }
            corridor.Length = actualSize;

            bool success = corridor.Length > 0 && corridor.Length == predefinedSize;

            return success;
        }
开发者ID:LuciusSixPercent,项目名称:Finsternis,代码行数:93,代码来源:CorridorFactory.cs


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