Example #1
0
        public Corridor Create(Room room, RangeInt length, RangeInt roomWidth, RangeInt roomHeight, int mapWidth, int mapHeight, bool firstCorridor)
        {
            while (true)
            {
                RandomDirection(room, length, firstCorridor);
                int maxLength = 0;

                switch (Direction)
                {
                case Direction.North:
                    Position  = new Point(Game1.Random.Next(room.Position.X + 1, room.Position.X + room.Width - 2), room.Position.Y);
                    maxLength = Position.Y - roomHeight.Min;
                    break;

                case Direction.East:
                    Position  = new Point(room.Position.X + room.Width - 1, Game1.Random.Next(room.Position.Y + 1, room.Position.Y + room.Height - 2));
                    maxLength = mapWidth - Position.X - roomWidth.Min;
                    break;

                case Direction.South:
                    Position  = new Point(Game1.Random.Next(room.Position.X + 1, room.Position.X + room.Width - 2), room.Position.Y + room.Height - 1);
                    maxLength = mapHeight - Position.Y - roomHeight.Min;
                    break;

                case Direction.West:
                    Position  = new Point(room.Position.X, Game1.Random.Next(room.Position.Y + 1, room.Position.Y + room.Height - 2));
                    maxLength = Position.X - roomWidth.Min;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Length = MathHelper.Clamp(Length, 0, maxLength);

                if (maxLength > 10)
                {
                    break;
                }
            }

            return(this);
        }
Example #2
0
        public Room Create(RangeInt widthRange, RangeInt heightRange, int mapWidth, int mapHeight, Corridor corridor)
        {
            EnteringCorridor = corridor.Direction;
            Width            = widthRange.Random;
            Height           = heightRange.Random;

            switch (corridor.Direction) // 0 bör vara 1 för vi lägger väggar och minus 1 på max.
            {
            case Direction.North:
                Height   = MathHelper.Clamp(Height, 3, corridor.EndPosition.Y);
                Position = new Point(MathHelper.Clamp(Game1.Random.Next(corridor.EndPosition.X - Width + 2, corridor.EndPosition.X - 1), 3, mapWidth - Width - 3), corridor.EndPosition.Y - Height + 1);
                break;

            case Direction.East:
                Width    = MathHelper.Clamp(Width, 3, mapWidth - corridor.EndPosition.X);
                Position = new Point(corridor.EndPosition.X, MathHelper.Clamp(Game1.Random.Next(corridor.EndPosition.Y - Height + 2, corridor.EndPosition.Y - 1), 3, mapHeight - Height - 3));
                break;

            case Direction.South:

                Height   = MathHelper.Clamp(Height, 3, mapHeight - corridor.EndPosition.Y);
                Position = new Point(MathHelper.Clamp(Game1.Random.Next(corridor.EndPosition.X - Width + 2, corridor.EndPosition.X - 1), 3, mapWidth - Width - 3), corridor.EndPosition.Y);
                break;

            case Direction.West:

                Width    = MathHelper.Clamp(Width, 3, corridor.EndPosition.X);
                Position = new Point(corridor.EndPosition.X - Width + 1, MathHelper.Clamp(Game1.Random.Next(corridor.EndPosition.Y - Height + 2, corridor.EndPosition.Y - 1), 3, mapHeight - Height - 3));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(this);
        }