public DefaultWeightInfo RandCross(bool up, bool down, bool left, bool right)
        {
            var crossType = new Tuple <bool, bool, bool, bool>(up, down, left, right);


            return(WeightListUtils.HitWeightListByBinary(CrossWeightLists[crossType]));
        }
Esempio n. 2
0
        public static void Import()
        {
            TileChooser.Reset();

            WeightListUtils.Add("Black", 10, TileChooser.ObstacleTileWeightList);
            WeightListUtils.Add("Black", 10, TileChooser.WallTileWeightList);

            WeightListUtils.Add("White", 10, TileChooser.RoadTileWeightList);
            WeightListUtils.Add("White", 10, TileChooser.CrossTileWeightList);
            WeightListUtils.Add("White", 10, TileChooser.RoomTileWeightList);
        }
Esempio n. 3
0
        public static Tile RandTile(string type)
        {
            DefaultWeightInfo weightInfo;

            if (type == "Cross")
            {
                weightInfo = WeightListUtils.HitWeightListByBinary(CrossTileWeightList);
            }
            else if (type == "Obstacle")
            {
                weightInfo = WeightListUtils.HitWeightListByBinary(ObstacleTileWeightList);
            }
            else if (type == "Road")
            {
                weightInfo = WeightListUtils.HitWeightListByBinary(RoadTileWeightList);
            }
            else if (type == "Room")
            {
                weightInfo = WeightListUtils.HitWeightListByBinary(RoomTileWeightList);
            }
            else if (type == "Wall")
            {
                weightInfo = WeightListUtils.HitWeightListByBinary(WallTileWeightList);
            }
            else
            {
                weightInfo = WeightListUtils.HitWeightListByBinary(ObstacleTileWeightList);
            }

            if (TileBuffer.ContainsKey(weightInfo.Type))
            {
                return(TileBuffer[weightInfo.Type]);
            }
            else
            {
                var tileSprite = Resources.Load <Sprite>($"Sprites/{weightInfo.Type}");
                var tile       = ScriptableObject.CreateInstance("Tile") as Tile;

                tile.sprite = tileSprite;
                TileBuffer.Add(weightInfo.Type, tile);

                return(tile);
            }
        }
Esempio n. 4
0
        private static void BuildInitRoom()
        {
            // 初始化房间记录
            RoomGenerator.Reset();

            // 根据关卡描述的生成欲望尝试生成次数,公式如下
            var tryBuildRoomTime = (int)(LevelDescription.MaxChunkX * LevelDescription.MaxChunkY / 5.0 * LevelDescription.RoomRate);
            var tryBuildDoorTime = (int)(RNG.RandInt(2, 4) * LevelDescription.DoorRate);

            // 尝试生成房间
            for (int i = 0; i < tryBuildRoomTime; i++)
            {
                // 禁止在边界一圈区块生成房间,因此排除边界点。房间向右上生长,因此右上保留空间
                var centerX  = RNG.RandInt(1 + Constant.OverBorderChunkSize, LevelDescription.MaxChunkX - 2 - LevelDescription.MaxRoomSize);
                var centerY  = RNG.RandInt(1 + Constant.OverBorderChunkSize, LevelDescription.MaxChunkY - 2 - LevelDescription.MaxRoomSize);
                var roomInfo = WeightListUtils.HitWeightListByBinary(LevelDescription.RoomWeightList) as RoomChunkWeightInfo;

                // 保证目标区域为空
                var flag = true;
                for (int x = centerX; x < centerX + roomInfo.X; x++)
                {
                    for (int y = centerY; y < centerY + roomInfo.Y; y++)
                    {
                        if (ChunkMap[x, y].ChunkType != "None")
                        {
                            flag = false;
                        }
                    }
                }

                if (flag)
                {
                    // 记录房间信息供后续生成
                    RoomGenerator.Add(centerX * Constant.ChunkSize, centerY * Constant.ChunkSize, (centerX + roomInfo.X) * Constant.ChunkSize, (centerY + roomInfo.Y) * Constant.ChunkSize);
                    // 填充目标区域为房间区块
                    for (int x = centerX; x < centerX + roomInfo.X; x++)
                    {
                        for (int y = centerY; y < centerY + roomInfo.Y; y++)
                        {
                            ChunkMap[x, y] = new ChunkInfoRoom();
                        }
                    }

                    for (int j = 0; j < tryBuildDoorTime; j++)
                    {
                        var randDir = RNG.RandInt(1, 4);
                        var randPos = 0;
                        switch (randDir)
                        {
                        case 1:
                            randPos = RNG.RandInt(0, roomInfo.X - 1);
                            if ((ChunkMap[centerX + randPos, centerY + roomInfo.Y - 1] as ChunkInfoRoom).Dir != 0)
                            {
                                break;
                            }
                            (ChunkMap[centerX + randPos, centerY + roomInfo.Y - 1] as ChunkInfoRoom).Dir = 1;
                            // 保证邻接房间下也会生成对应的门
                            if (ChunkMap[centerX + randPos, centerY + roomInfo.Y - 1 + 1] is ChunkInfoRoom)
                            {
                                (ChunkMap[centerX + randPos, centerY + roomInfo.Y - 1 + 1] as ChunkInfoRoom).Dir = 2;
                            }
                            // 否则在门口生成路口点
                            else
                            {
                                ChunkMap[centerX + randPos, centerY + roomInfo.Y - 1 + 1] = new ChunkInfoCross(centerX + randPos, centerY + roomInfo.Y - 1 + 1);
                            }
                            break;

                        case 2:
                            randPos = RNG.RandInt(0, roomInfo.X - 1);
                            if ((ChunkMap[centerX + randPos, centerY] as ChunkInfoRoom).Dir != 0)
                            {
                                break;
                            }
                            (ChunkMap[centerX + randPos, centerY] as ChunkInfoRoom).Dir = 2;
                            // 保证邻接房间下也会生成对应的门
                            if (ChunkMap[centerX + randPos, centerY - 1] is ChunkInfoRoom)
                            {
                                (ChunkMap[centerX + randPos, centerY - 1] as ChunkInfoRoom).Dir = 1;
                            }
                            // 否则在门口生成路口点
                            else
                            {
                                ChunkMap[centerX + randPos, centerY - 1] = new ChunkInfoCross(centerX + randPos, centerY - 1);
                            }
                            break;

                        case 3:
                            randPos = RNG.RandInt(0, roomInfo.Y - 1);
                            if ((ChunkMap[centerX, centerY + randPos] as ChunkInfoRoom).Dir != 0)
                            {
                                break;
                            }
                            (ChunkMap[centerX, centerY + randPos] as ChunkInfoRoom).Dir = 3;
                            // 保证邻接房间下也会生成对应的门
                            if (ChunkMap[centerX - 1, centerY + randPos] is ChunkInfoRoom)
                            {
                                (ChunkMap[centerX - 1, centerY + randPos] as ChunkInfoRoom).Dir = 4;
                            }
                            // 否则在门口生成路口点
                            else
                            {
                                ChunkMap[centerX - 1, centerY + randPos] = new ChunkInfoCross(centerX - 1, centerY + randPos);
                            }
                            break;

                        case 4:
                            randPos = RNG.RandInt(0, roomInfo.Y - 1);
                            if ((ChunkMap[centerX + roomInfo.X - 1, centerY + randPos] as ChunkInfoRoom).Dir != 0)
                            {
                                break;
                            }
                            (ChunkMap[centerX + roomInfo.X - 1, centerY + randPos] as ChunkInfoRoom).Dir = 4;
                            // 保证邻接房间下也会生成对应的门
                            if (ChunkMap[centerX + roomInfo.X - 1 + 1, centerY + randPos] is ChunkInfoRoom)
                            {
                                (ChunkMap[centerX + roomInfo.X - 1 + 1, centerY + randPos] as ChunkInfoRoom).Dir = 3;
                            }
                            // 否则在门口生成路口点
                            else
                            {
                                ChunkMap[centerX + roomInfo.X - 1 + 1, centerY + randPos] = new ChunkInfoCross(centerX + roomInfo.X - 1 + 1, centerY + randPos);
                            }
                            break;
                        }
                    }
                }
            }
        }
        public void AddCross(bool up, bool down, bool left, bool right, string crossName, double weight)
        {
            var crossType = new Tuple <bool, bool, bool, bool>(up, down, left, right);

            WeightListUtils.Add(crossName, weight, CrossWeightLists[crossType]);
        }
 public DefaultWeightInfo RandRoom()
 {
     return(WeightListUtils.HitWeightListByBinary(RoomWeightList));
 }
 public DefaultWeightInfo RandObstacle()
 {
     return(WeightListUtils.HitWeightListByBinary(ObstacleWeightList));
 }
 public void AddObstacle(string obstacleName, double weight)
 {
     WeightListUtils.Add(obstacleName, weight, ObstacleWeightList);
 }