Ejemplo n.º 1
0
		protected Map(int rows, int columns)
		{
			_cells = new Cell[rows, columns];
			Bounds = new RectI(0, 0, columns, rows);
			Rows = rows;
			Columns = columns;
		}
Ejemplo n.º 2
0
		public Room Generate(Random random, Area area)
		{
			if (_roomCount >= MaxRooms)
			{
				return null;
			}

			// Don't place the room on the area's edge.
			// This will keep rooms from being adjacent to each other.
			var placeableBounds = area.Bounds.Inflate(-1);

			var width = random.Next(MinWidth, placeableBounds.Width + 1);
			var height = random.Next(MinHeight, placeableBounds.Height + 1);

			// Find a place in the area to put the room.
			while (true)
			{
				var x = random.Next(placeableBounds.Left, placeableBounds.Right - width + 1 + 1);
				var y = random.Next(placeableBounds.Top, placeableBounds.Bottom - height + 1 + 1);
				var roomBounds = new RectI(x, y, width, height);
				if (placeableBounds.Contains(roomBounds))
				{
					_roomCount++;
					return new Room(random, roomBounds);
				}
			}
		}
Ejemplo n.º 3
0
		public Room(Random random, RectI bounds)
		{
			_random = random;

			HasNorthDoor = false;
			HasSouthDoor = false;
			HasEastDoor = false;
			HasWestDoor = false;
			Bounds = bounds;
		}
Ejemplo n.º 4
0
		public void Fill(Chunk chunk, ChunkLayer layer, RectI bounds, int blockId)
		{
			for (var row = bounds.Top; row <= bounds.Bottom; row++)
			{
				for (var column = bounds.Left; column <= bounds.Right; column++)
				{
					chunk[layer, column, row] = blockId;
				}
			}
		}
Ejemplo n.º 5
0
		public Area(RoomGenerator roomGenerator, Random random, int x, int y, int width, int height)
		{
			Random = random;

			Bounds = new RectI(x, y, width, height);
			SubArea1 = null;
			SubArea2 = null;

			Split(roomGenerator);

			if (!HasChildren)
			{
				Room = roomGenerator.Generate(random, this);
			}
		}
Ejemplo n.º 6
0
		private bool Contains(RectI bounds, Vector2I roomLocation, Room room)
		{
			return
				bounds.Contains(roomLocation.X, roomLocation.Y) &&
				bounds.Contains(roomLocation.X + room.Columns - 1, roomLocation.Y) &&
				bounds.Contains(roomLocation.X + room.Columns - 1, roomLocation.Y + room.Rows - 1) &&
				bounds.Contains(roomLocation.X, roomLocation.Y + room.Rows - 1);
		}