Example #1
0
String Map::GetMapDataAsText() {

	String mapDataAsText = "";
	mapDataAsText.push_back('\n');

	for (int y = m_size.y - 1; y >= 0; y--) {
		for (int x = 0; x < m_size.x; x++) {
			Tile* tile = GetTileAtLocation(IntVector2(x, y));

			switch (tile->GetCurrentTileType()) {
			case TILE_AIR:
				mapDataAsText.push_back('0');
				break;
			case TILE_STONE:
				mapDataAsText.push_back('#');
				break;
			case TILE_GRASS:
				mapDataAsText.push_back('.');
				break;
			case TILE_WATER:
				mapDataAsText.push_back('$');
				break;
			case TILE_LAVA:
				mapDataAsText.push_back('x');
				break;
			}
		}

		mapDataAsText.push_back('\n');
	}

	//String mapData = StringUtils::ReverseString(mapDataAsText);

	return mapDataAsText;
}
Example #2
0
IntVector2 Map::FindRandomValidLocationToSpawn() {
	IntVector2 position;
	bool foundALocation = false;
	int indicesToConsider = m_tiles.size();

	int numTimesRan = 0;

	while (!foundALocation) {
		int ind = RandInt(0, indicesToConsider - 1);

		Tile* currTile = GetTileAtIndex(ind);

		if (nullptr != currTile && currTile->IsValid() && currTile->GetCurrentTileType() != TILE_WATER && currTile->GetCurrentTileType() != TILE_LAVA) {
			position = currTile->GetLocation();
			foundALocation = true;
		}


		if (numTimesRan > 10000) {
			DebuggerPrintf("ERROR: Find Random Valid Location running too long.");
			return IntVector2(0, 0);
		}
		numTimesRan++;
	}

	return position;
}
Example #3
0
IntVector2 Map::GetLocationWithOpeningOnEitherSide() {

	std::vector<Tile*> allStoneTilesOnMap;

	for (int x = 0; x < m_size.x; x++) {
		for (int y = 0; y < m_size.y; y++) {
			IntVector2 loc = IntVector2(x, y);
			Tile* currTile = GetTileAtLocation(loc);

			if (currTile->GetCurrentTileType() == TILE_STONE) {
				allStoneTilesOnMap.push_back(currTile);
			}
		}
	}

	int numTimesRan = 0;
	bool b = true;
	while (b) {
		int which = RandIntZeroToSize(allStoneTilesOnMap.size());

		Tile*& currTile = allStoneTilesOnMap[which];
		IntVector2 loc = currTile->GetLocation();

		Tile* tileToLeft = GetTileAtLocation(loc + WEST);
		Tile* tileToRight = GetTileAtLocation(loc + EAST);
		Tile* tileToUp = GetTileAtLocation(loc + NORTH);
		Tile* tileToDown = GetTileAtLocation(loc + SOUTH);

		if (tileToLeft && tileToRight && tileToLeft->IsValid() && tileToRight->IsValid()) {
			return loc;
		}
		else if (tileToUp && tileToDown && tileToUp->IsValid() && tileToDown->IsValid()) {
			return loc;
		}


		if (numTimesRan > 10000) {
			DebuggerPrintf("ERROR: Find Random Valid Location running too long.");
			return IntVector2(0, 0);
		}
		numTimesRan++;
	}

	return IntVector2(0, 0);
}