示例#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
		}
示例#2
0
		bool CRoomManager::init()
		{
			// register to console: TODO register some usefull stuff
			CV_GAME_MANAGER->getConsole()->registerClass(this,"ROOM MANAGER");
			CV_GAME_MANAGER->getConsole()->addParam(RLROOM,"() Reloads the rooms.");
			CV_GAME_MANAGER->getConsole()->addParam(RC,"() Prints room count.");
			CV_GAME_MANAGER->getConsole()->addParam(RC,"() Prints room count.");
			CV_GAME_MANAGER->getConsole()->addParam(SRA,"() Shows room area.");

			// construct new rooms
			CLevelManager *lManager = CV_GAME_MANAGER->getLevelManager();
			for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
			{
				for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
				{
					CBlock *block = lManager->getBlock(x,y);
					if (block->isRoom() && !block->isInRoom())
					{
						if(block->getType() == CV_BLOCK_TYPE_HEART_ID && block->getOwner() == CV_PLAYER_0)
						{
							cml::vector3f position = block->getRealPosition();
							CV_GAME_MANAGER->getControlManager()->getCamera()->setPosition(cml::vector3f(position[0]+0.3, CV_CAMERA_INITIAL_HEIGHT, position[2]+1));
						}
						// we found a room tile that isn't in a room yet. we create a new room.
						CRoom *newRoom = new CRoom();
						newRoom->init(block);
						allRooms[newRoom->getIndex()] = newRoom;
						roomColors[newRoom->getIndex()] = vector3f((GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f);
					}
				}
			}

			return true;
		}