Exemplo n.º 1
0
        private bool PlaceOutputNumber(int[,] matrix, uint sizeX, uint sizeY, RogueLikeOutputNumber rect, int tile)
        {
            if (rect.x < 1 || rect.y < 1 || rect.x + rect.w > sizeX - 1 || rect.y + rect.h > sizeY - 1)
            {
                return(false);
            }

            for (int y = rect.y; y < rect.y + rect.h; ++y)
            {
                for (int x = rect.x; x < rect.x + rect.w; ++x)
                {
                    if (matrix[startY + y, startX + x] != rogueLikeList.outsideWallId)
                    {
                        return(false);
                    }
                }
            }

            for (int y = rect.y - 1; y < rect.y + rect.h + 1; ++y)
            {
                for (int x = rect.x - 1; x < rect.x + rect.w + 1; ++x)
                {
                    if (y == rect.y - 1 || x == rect.x - 1 || y == rect.y + rect.h || x == rect.x + rect.w)
                    {
                        matrix[y, x] = rogueLikeList.insideWallId;
                    }
                    else
                    {
                        matrix[y, x] = tile;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool MakeRoom(int[,] matrix, uint sizeX, uint sizeY, List <RogueLikeOutputNumber> roomRect,
                              List <RogueLikeOutputNumber> branchPoint, List <bool> isWay, int x_, int y_, Direction dir_,
                              bool firstRoom = false)
        {
            var room = new RogueLikeOutputNumber();

            room.w = rand.Next(roomRange.x, roomRange.x + roomRange.w);
            room.h = rand.Next(roomRange.y, roomRange.y + roomRange.h);

            switch (dir_)
            {
            case Direction.North:
                room.x = x_ - room.w / 2;
                room.y = y_ - room.h;
                break;

            case Direction.South:
                room.x = x_ - room.w / 2;
                room.y = y_ + 1;
                break;

            case Direction.West:
                room.x = x_ - room.w;
                room.y = y_;    // - room.h / 2; Bug? 道の端から部屋を生成するときに、DirectionがWest or Eastだと基点のY軸が上にずれて部屋の生成と道がつながらなくなってしまう。
                break;

            case Direction.East:
                room.x = x_ + 1;
                room.y = y_;    // + room.h / 2; Bug? Direction.Westと同様。
                break;
            }

            if (PlaceOutputNumber(matrix, sizeX, sizeY, room, rogueLikeList.roomId))
            {
                roomRect.Add(room);
                if (dir_ != Direction.South || firstRoom)
                {
                    branchPoint.Add(new RogueLikeOutputNumber(room.x, room.y - 1, room.w, 1));
                    isWay.Add(false);
                }

                if (dir_ != Direction.North || firstRoom)
                {
                    branchPoint.Add(new RogueLikeOutputNumber(room.x, room.y + room.h, room.w, 1));
                    isWay.Add(false);
                }

                if (dir_ != Direction.East || firstRoom)
                {
                    branchPoint.Add(new RogueLikeOutputNumber(room.x - 1, room.y, 1, room.h));
                    isWay.Add(false);
                }

                if (dir_ != Direction.West || firstRoom)
                {
                    branchPoint.Add(new RogueLikeOutputNumber(room.x + room.w, room.y, 1, room.h));
                    isWay.Add(false);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        private bool MakeWay(int[,] matrix, uint sizeX, uint sizeY, List <RogueLikeOutputNumber> branchPoint,
                             List <bool> isWay,
                             int x_, int y_, Direction dir_)
        {
            var way_ = new RogueLikeOutputNumber();

            way_.x = x_;
            way_.y = y_;

            // 左右
            if (rand.Probability(0.5))
            {
                way_.w = rand.Next(wayRange.x, wayRange.x + wayRange.w);
                way_.h = 1;
                switch (dir_)
                {
                case Direction.North:
                    way_.y = y_ - 1;
                    if (rand.Probability(0.5))
                    {
                        way_.x = x_ - way_.w + 1;
                    }
                    break;

                case Direction.South:
                    way_.y = y_ + 1;
                    if (rand.Probability(0.5))
                    {
                        way_.x = x_ - way_.w + 1;
                    }
                    break;

                case Direction.West:
                    way_.x = x_ - way_.w;
                    break;

                case Direction.East:
                    way_.x = x_ + 1;
                    break;
                }
            }
            // 上下
            else
            {
                way_.w = 1;
                way_.h = rand.Next(wayRange.y, wayRange.y + wayRange.h);

                switch (dir_)
                {
                case Direction.North:
                    way_.y = y_ - way_.h;
                    break;

                case Direction.South:
                    way_.y = y_ + 1;
                    break;

                case Direction.West:
                    way_.x = x_ - 1;
                    if (rand.Probability(0.5))
                    {
                        way_.y = y_ - way_.h + 1;
                    }
                    break;

                case Direction.East:
                    way_.x = x_ + 1;
                    if (rand.Probability(0.5))
                    {
                        way_.y = y_ - way_.h + 1;
                    }
                    break;
                }
            }

            if (!PlaceOutputNumber(matrix, sizeX, sizeY, way_, rogueLikeList.wayId))
            {
                return(false);
            }
            if (dir_ != Direction.South && way_.w != 1)
            {
                branchPoint.Add(new RogueLikeOutputNumber(way_.x, way_.y - 1, way_.w, 1));
                isWay.Add(true);
            }

            if (dir_ != Direction.North && way_.w != 1)
            {
                branchPoint.Add(new RogueLikeOutputNumber(way_.x, way_.y + way_.h, way_.w, 1));
                isWay.Add(true);
            }

            if (dir_ != Direction.East && way_.h != 1)
            {
                branchPoint.Add(new RogueLikeOutputNumber(way_.x - 1, way_.y, 1, way_.h));
                isWay.Add(true);
            }

            if (dir_ != Direction.West && way_.h != 1)
            {
                branchPoint.Add(new RogueLikeOutputNumber(way_.x + way_.w, way_.y, 1, way_.h));
                isWay.Add(true);
            }

            return(true);
        }