示例#1
0
void World::LoadRoomsFromFile(string p_fileName)
{
	int counter = -1;
	string line;
	ifstream myfile (p_fileName);

	if (myfile.is_open())
	{
		getline (myfile,line);
		m_roomCount = atoi(line.c_str());
		m_world = new Room*[m_roomCount];

		for (int i = 0; i < m_roomCount; i++)
			m_world[i] = new Room();

		while ( getline (myfile,line) )
		{
			if(line == "")
			{
				counter++;
			}
			else
			{
				m_world[counter]->SetName(line);
				getline (myfile, line);
				m_world[counter]->SetDesc(line);
			}
		}
		myfile.close();
	}
	else
		cout << "Unable to open file" << '\n';
	//Load rooms into the world
	ConnectRooms();
}
示例#2
0
void MapGenerator::ConnectRooms(Map* map, BSPNode* parent) {
	// Start at the top node and connect each leaf to its sibling, and then recurse on each leaf.
	BSPNode* A = parent->A;
	BSPNode* B = parent->B;

	// Get the center points for both rooms.
	int aCX = (A->column + A->width) - (A->width / 2);
	int aCY = (A->row + A->height) - (A->height / 2);

	int bCX = (B->column + B->width) - (B->width / 2);
	int bCY = (B->row + B->height) - (B->height / 2);

	// Connect the two points on the X-axis.
	for(int startX = aCX; startX != bCX; startX += ((aCX < bCX)?1:-1)) {
		map->GetTile(aCY, startX)->SetType(Tile::REGULAR_TYPE);
	}
	// Connect the two points on the Y-axis.
	for(int startY = aCY; startY != bCY; startY += ((aCY < bCY)?1:-1)) {
		map->GetTile(startY, bCX)->SetType(Tile::REGULAR_TYPE);
	}

	if(A->A != NULL && A->B != NULL) ConnectRooms(map, A);
	if(B->A != NULL && B->B != NULL) ConnectRooms(map, B);
}
示例#3
0
void TileGrid::Init() {
	std::vector<std::vector<TileStatus>> tiles;
	SpawnRooms(tiles);
	ConnectRooms(tiles);

	m_tiles.resize(WORLDSIZE);
	for (unsigned int y = 0; y < m_tiles.size(); y++) {
		m_tiles.at(y).resize(WORLDSIZE);
		for (unsigned int x = 0; x < m_tiles.at(y).size(); x++) {
			switch (tiles.at(y).at(x)) {
			case UNBUILDABLE:
				m_tiles.at(y).at(x) = new TileWall(Position(x * TILESIZE, y * TILESIZE));
				break;

			case WALL:
				m_tiles.at(y).at(x) = new TileEmpty(Position(x * TILESIZE, y * TILESIZE));
				break;

			case CORRIDOR:
				m_tiles.at(y).at(x) = new TileFloor(Position(x * TILESIZE, y * TILESIZE));
				break;

			case ROOM:
				m_tiles.at(y).at(x) = new TileFloor(Position(x * TILESIZE, y * TILESIZE));
				break;

			case ROOMWALL:
				m_tiles.at(y).at(x) = new TileWall(Position(x * TILESIZE, y * TILESIZE));
				break;

			default:
				std::cout << "creation of tilegrid failed\n";
				break;
			}
		}
	}
}