Exemple #1
0
std::vector<std::vector<bool>> Graph<Room>::generateCorridors(Floor &floor) const
{
	auto arr = floor.toArray();

	int minX = floor.MinX(),
		maxX = floor.MaxX(),
		minY = floor.MinY(),
		maxY = floor.MaxY();

	for (const auto & node : nodes)
	{
		const Room & room = *node.content,
				   & next = *node.neighbors[0]->content;

		const int room_x = room.middle().x,
				  room_y = room.middle().y,

				  next_x = next.middle().x,
				  next_y = next.middle().y,

				  dx = next_x - minX,
				  dy = maxY - next_y;


		int x = room_x - minX,
		    y = maxY - room_y;

		//Horizontal part of corridor
		if (room_x < next_x)
			for (; x < dx; ++x)
				arr[y][x] = true;
		else
			for (; x > dx; --x)
				arr[y][x] = true;

		//Vertical part of corridor
		if (room_y < next_y)
			for (; y > dy; --y)
				arr[y][x] = true;
		else
			for (; y < dy; ++y)
				arr[y][x] = true;
	}

	return arr;
}