Example #1
0
		GLvoid CRoom::rec(vector2i pos)
		{
			// check pos validity
			if (pos[0]<0 || pos[1]<0 || pos[0]>=CV_LEVEL_MAP_SIZE || pos[1]>=CV_LEVEL_MAP_SIZE)
			{
				return;
			}

			CLevelManager *lManager = CV_GAME_MANAGER->getLevelManager();
			CBlock *baseBlock = roomTiles.size()>0?*roomTiles.begin():NULL;
			CBlock *targetBlock = lManager->getBlock(pos);

			// check if we are of same type and owner as last block			
			if (baseBlock && !lManager->isSameTypeAndOwner(pos[0],pos[1],baseBlock))
			{
				return;
			}

			// check if we have already been here
			if (targetBlock->isInRoom())
			{
				return;
			}

			// we have a valid block to add to out room
			targetBlock->setRoomIndex(roomIndex);
			roomTiles.push_back(targetBlock);

			// search in all directions
			rec(pos+vector2i(-1,0));	// L
			rec(pos+vector2i(+1,0));	// R
			rec(pos+vector2i(0,-1));	// U
			rec(pos+vector2i(0,+1));	// D
		}