Exemple #1
0
//这个函数会在初始化调用
void FCScene::doEnable(void)
{
	
	_map->active();
	using namespace Ogre;
	//从系统中得到Ogre的场景管理器
	SceneManager * sm = OgreGraphicsManager::getSingleton().getSceneManager();

	//把其场景清空
	sm->clearScene();
	
	
	Plane plane;
	plane.normal = Vector3::UNIT_Y;
	plane.d = 100;
	FCKnowledge::getSingleton().mapInfo().setGround(-plane.d);
	FCKnowledge::getSingleton().mapInfo().enable();
	MeshManager::getSingleton().createPlane("Myplane",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
		512, 512,20,20,true,1,60,60,Vector3::UNIT_Z);
	Ogre::Entity* pPlaneEnt = sm->createEntity( "plane", "Myplane" );
	pPlaneEnt->setMaterialName("Examples/Rockwall");
	pPlaneEnt->setQueryFlags(0);
	sm->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

	//设置环境光
	sm->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

	//创建天空盒
	//sm->setSkyBox(true, "Examples/SpaceSkyBox", 50 );

	// 创建一个光源
	Light* l = sm->createLight("MainLight");

	//设置光源位置
	l->setPosition(20,80,50);


	//下面代码随机 放置砖块
	NameValueList par;
	for(int i = 1; i< 16 *16; ++i)
	{
		if(rand()%2 == 0)
		{
			par["pos"] = i;
			ActorPtr wall = Orz::GameFactories::getInstance().createActor("FCWall",IDManager::BLANK, &par );
			getWorld()->comeIn(wall);
			_walls.push_back(wall);
		}
	}

	//在这里我们通过XML文件FighteingClub.xml 得到两个格斗者的名字,然后创建他们 并给他们位置和ID
	XMLFighterLoader loader;
	if(loader.load("FighteingClub.xml"))
	{
		{
			par["pos"] = 10;
			par["id"] = 0;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor(loader.getFighter1(),IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
			_enemies.push_back(fighter);
			
		}
		{
			par["pos"] = 20;
			
			par["id"] = 1;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor(loader.getFighter2(),IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
		_enemies.push_back(fighter);
		}
	}
	else//如果XML读取失败 那么就采用默认的 "FCFighter"
	{
		for(int i =0; i<2; ++i)
		{
			
			par["id"] = i;
			par["pos"] = i*10;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor("FCFighter",IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
			_enemies.push_back(fighter);
		}
	}
}
Exemple #2
0
//这个函数会在初始化调用
void FCScene::doEnable(void)
{
	
	using namespace Ogre;
//	using namespace OgreNewt;
	//从系统中得到Ogre的场景管理器
	SceneManager * sm = OgreGraphicsManager::getSingleton().getSceneManager();
	
	
	//把其场景清空
	sm->clearScene();

	//sm->setWorldGeometry("terrain.cfg");
	

	Plane plane;
	plane.normal = Vector3::UNIT_Y;
	plane.d = 100;
	
	FCKnowledge::getSingleton().mapInfo().setGround(-plane.d);
	FCKnowledge::getSingleton().mapInfo().enable();

	FCKnowledge::getSingleton().setSceneName(this->getName());
	//MeshManager::getSingleton().createPlane("Myplane",
	//	ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
	//	1500,1500,20,20,true,1,60,60,Vector3::UNIT_Z);
	//Ogre::Entity* pPlaneEnt = sm->createEntity( "plane", "Myplane" );
	//pPlaneEnt->setMaterialName("Examples/Rockwall");
	//sm->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

	//set ambient light
	sm->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
	
	//create sky box
	sm->setSkyBox(true, "Examples/SpaceSkyBox2");

	// create a light source
	Light* l = sm->createLight("MainLight");


	//set light position
	l->setPosition(20,80,50);

	//create player
	NameValueList par;
	par["initPos"] = Ogre::Vector3(200, 50, 270);
	par["queryFlag"] = 0x2;
	par["speedLimit"] = 50.0;
	_player = Orz::GameFactories::getInstance().createActor("PlayerPlane", "player", &par);
	getWorld()->comeIn(_player);
	
	//create player controller
	NameValueList playerCtrlPar;
	playerCtrlPar["playerName"] = std::string("player");
	_playerCtrl = GameFactories::getInstance().createActor("PlayerController", "playerCtrl", &playerCtrlPar);
	getWorld()->comeIn(_playerCtrl);

	//create enemies
	for(int i = 0; i < _numEnemies; i++)
	{

		par["initPos"] = Ogre::Vector3(Ogre::Math::RangeRandom(0, 1000), Ogre::Math::RangeRandom(0, 200), Ogre::Math::RangeRandom(0, 1000));
		par["queryFlag"] = 0x8;
		par["speedLimit"] = 10.0;
		ActorPtr enemy = GameFactories::getInstance().createActor("EnemyPlane", "enemy"+boost::lexical_cast<std::string>(i), &par);
		getWorld()->comeIn(enemy);
		_enemies.push_back(enemy);

		NameValueList ctrlPar;
		ctrlPar["fighterName"] = "enemy"+boost::lexical_cast<std::string>(i);
		ActorPtr enemyCtrl = GameFactories::getInstance().createActor("EnemyController", "enemyCtrl"+boost::lexical_cast<std::string>(i), &ctrlPar);
		getWorld()->comeIn(enemyCtrl);
		_enemiesCtrl.push_back(enemyCtrl);
	}

	NameValueList obstaclePar;
	obstaclePar["pos"] = Ogre::Vector3(1000, 400, 800);
	obstaclePar["scale"] = 1.7;
	obstaclePar["materialName"] = std::string("Planets/Down");
	_obstacle1 = GameFactories::getInstance().createActor("Obstacle", "obstacle1", &obstaclePar);
	getWorld()->comeIn(_obstacle1);

	obstaclePar["pos"] = Ogre::Vector3(-1000, -100, 400);
	obstaclePar["scale"] = 1.2;
	obstaclePar["materialName"] = std::string("Planets/Dust");
	_obstacle2 = GameFactories::getInstance().createActor("Obstacle", "obstacle2", &obstaclePar);
	getWorld()->comeIn(_obstacle2);

	obstaclePar["pos"] = Ogre::Vector3(500, -400, -1000);
	obstaclePar["scale"] = 0.8;
	obstaclePar["materialName"] = std::string("Planets/Reststop");
	_obstacle3 = GameFactories::getInstance().createActor("Obstacle", "obstacle3", &obstaclePar);
	getWorld()->comeIn(_obstacle3);

	Ogre::OverlayManager::getSingleton().getByName("Target")->show();
	
	enableUpdate();
}