Пример #1
0
 private void TestRandom()
 {
     Console.WriteLine(BRandom.RandomGauss(0f, 2f / Mathf.Sqrt(10)));
     Console.WriteLine(BRandom.RandomGauss(0f, 2f / Mathf.Sqrt(3)));
     Console.WriteLine(BRandom.RandomGauss(0f, 2f / Mathf.Sqrt(30)));
     Console.WriteLine(BRandom.RandomGauss(0f, 2f / Mathf.Sqrt(100)));
 }
Пример #2
0
        /// <summary>
        /// 生成房间
        /// </summary>
        /// <returns></returns>
        public Dungeon GenerateRooms()
        {
            generationSpace = generationSpace ?? GenerateSpace();
            List <Room> roomsList                = new List <Room>();
            VectorInt   generateStartPoint       = new VectorInt(1, 0, 1);
            VectorInt   dungeonSizeForGeneration = size - generateStartPoint;

            for (int i = maxTestTimes; i > 0; i--)
            {
                Room r = new Room(BRandom.GetVectorInt(generateStartPoint, dungeonSizeForGeneration),
                                  BRandom.GetVectorInt(minRoomSize, maxRoomSize));
                bool isIntersect = false;
                foreach (var room in roomsList)
                {
                    if (room.IsIntersectWith(r))
                    {
                        isIntersect = true;
                        break;
                    }
                }
                if (isIntersect)
                {
                    continue;
                }
                roomsList
                .Add(r.Init(generationSpace, solid, colloid, minDistanceToEdge));
            }
            rooms = roomsList.ToArray();
            return(this);
        }
Пример #3
0
 private void DefaultOffsetInit(int seed)
 {
     BRandom.Init(seed);
     Offsets    = new Vector[3];
     Offsets[0] = new Vector(BRandom.Value * 1000, BRandom.Value * 1000, BRandom.Value * 1000);
     Offsets[1] = new Vector(BRandom.Value * 1000, BRandom.Value * 1000, BRandom.Value * 1000);
     Offsets[2] = new Vector(BRandom.Value * 1000, BRandom.Value * 1000, BRandom.Value * 1000);
 }
Пример #4
0
        /// <summary>
        /// 生成迷宫
        /// </summary>
        /// <returns></returns>
        public Dungeon GenerateMaze()
        {
            string emptytype = Default.Properties.Empty.NodeType;
            Path   path;
            Node   start, end;
            bool   upToDown    = BRandom.GetBoolean();
            bool   rightToLeft = BRandom.GetBoolean();

            List <Node> boundries = new List <Node>();

            foreach (var r in rooms)
            {
                foreach (var b in r.boundryNodes)
                {
                    boundries.Add(b);
                }
            }

            for (int i = 0, length = maxTestTimes; i < length; i++)
            {
                start = BRandom.GetElement(boundries);
                end   = BRandom.GetElement(boundries);
                path  = new Path(start, end, mazeGenerationAgent, false);
                path.Find();
                for (int j = 0, lengthJ = maxTestTimes; j < lengthJ && path.State != Path.STATE.SUCCESS; j++)
                {
                    path.Reset();
                    path.Start = BRandom.GetElement(boundries);
                    path.End   = BRandom.GetElement(boundries);
                    path.Find();
                }
                foreach (var item in path.Result)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    //将节点设置为实心
                    item.SetProerties(solid);

                    if (boundries.Contains(item))
                    {
                        boundries.Remove(item);
                    }

                    foreach (var neighbor in item.Neighbors)
                    {
                        if (neighbor == null || neighbor.Type == solid.NodeType)
                        {
                            continue;
                        }

                        neighbor.SetProerties(solid);

                        if (boundries.Contains(neighbor))
                        {
                            boundries.Remove(neighbor);
                        }

                        foreach (var neighborSecondary in neighbor.Neighbors)
                        {
                            if (neighborSecondary == null || neighborSecondary.Type == solid.NodeType)
                            {
                                continue;
                            }

                            neighborSecondary.SetProerties(colloid);

                            if (!boundries.Contains(neighborSecondary))
                            {
                                boundries.Add(neighborSecondary);
                            }
                        }
                    }
                }
                path.Reset();
            }

            foreach (var node in generationSpace.Nodes)
            {
                if (string.Equals(node.Type, empty.NodeType, StringComparison.CurrentCultureIgnoreCase))
                {
                    node.SetProerties(dungeonNodePrefab);
                }
                if (string.Equals(node.Type, solid.NodeType, StringComparison.CurrentCultureIgnoreCase))
                {
                    node.SetProerties(roomFloorPrefab);
                }
                if (string.Equals(node.Type, colloid.NodeType, StringComparison.CurrentCultureIgnoreCase))
                {
                    node.SetProerties(boundryNodePrefab);
                }
            }
            return(this);
        }