当前位置: 首页>>代码示例>>C++>>正文


C++ CGameObject::addController方法代码示例

本文整理汇总了C++中CGameObject::addController方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameObject::addController方法的具体用法?C++ CGameObject::addController怎么用?C++ CGameObject::addController使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGameObject的用法示例。


在下文中一共展示了CGameObject::addController方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

bool CGamePlayState::update(float dtime)
{
	
	m_enemyTime -= dtime;
	if (m_enemyCount > 0.f && m_enemyTime <= 0.f)
	{
		m_enemyTime = 2.f;
		m_enemyId++;
		// Create new enemy
		CGameObject* enemy = new CGameObject();
		if (m_enemyId == 1) {
			enemy->setPosition(glm::vec3(-50.f, 30.f, 50.f));
			enemy->setRotation(glm::vec3(0.f));
			enemy->setScale(glm::vec3(0.5f));
			enemy->addController(std::make_shared<CRestrictPositionController>(glm::vec2(-100.f, -100.f), glm::vec2(100.f, 100.f)));
			enemy->addController(std::make_shared<CLinearMovementController>(enemy->getForward(), 15.f));
			enemy->addController(std::make_shared<CHealthController>(100.f));
			enemy->addController(std::make_shared<CRemoveOnDeathController>(this));
		}

		if (m_enemyId == 2) {
			enemy->setPosition(glm::vec3(0.f, 45.f, -50.f));
			enemy->setRotation(glm::vec3(0.f));
			enemy->setScale(glm::vec3(0.5f));
			enemy->addController(std::make_shared<CRestrictPositionController>(glm::vec2(-100.f, -100.f), glm::vec2(100.f, 100.f)));
			enemy->addController(std::make_shared<CLinearMovementController>(enemy->getForward(), 15.f));
			enemy->addController(std::make_shared<CHealthController>(100.f));
			enemy->addController(std::make_shared<CRemoveOnDeathController>(this));
		}

		if (m_enemyId == 3) {
			enemy->setPosition(glm::vec3(50.f, 20.f, 0.f));
			enemy->setRotation(glm::vec3(0.f));
			enemy->setScale(glm::vec3(0.5f));
			enemy->addController(std::make_shared<CRestrictPositionController>(glm::vec2(-100.f, -100.f), glm::vec2(100.f, 100.f)));
			enemy->addController(std::make_shared<CLinearMovementController>(enemy->getForward(), 15.f));
			enemy->addController(std::make_shared<CHealthController>(100.f));
			enemy->addController(std::make_shared<CRemoveOnDeathController>(this));
		}

		if (m_enemyId == 4) {
			enemy->setPosition(glm::vec3(50.f, 25.f, 0.f));
			enemy->setRotation(glm::vec3(0.f, 92.6,0.f));
			enemy->setScale(glm::vec3(0.5f));
			enemy->addController(std::make_shared<CRestrictPositionController>(glm::vec2(-100.f, -100.f), glm::vec2(100.f, 100.f)));
			enemy->addController(std::make_shared<CSimpleWaypointController>(glm::vec3(-101.f, 25.f, 0.f), 15.f, this));
			enemy->addController(std::make_shared<CHealthController>(100.f));
			enemy->addController(std::make_shared<CRemoveOnDeathController>(this));
		}
		
		if (m_enemyId == 5) {
			enemy->setPosition(glm::vec3(0.f, 40.f, -50.f));
			enemy->setRotation(glm::vec3(0.f, 92.6, 0.f));
			enemy->setScale(glm::vec3(0.5f));
			enemy->addController(std::make_shared<CRestrictPositionController>(glm::vec2(-100.f, -100.f), glm::vec2(100.f, 100.f)));
			enemy->addController(std::make_shared<CSimpleWaypointController>(glm::vec3(-101.f, 40.f, -50.f), 15.f, this));
			enemy->addController(std::make_shared<CHealthController>(100.f));
			enemy->addController(std::make_shared<CRemoveOnDeathController>(this));
		}
		
		if (m_enemyId == 6) {
			enemy->setPosition(glm::vec3(-50.f, 50.f, 50.f));
			enemy->setRotation(glm::vec3(0.f, 92.6, 0.f));
			enemy->setScale(glm::vec3(0.5f));
			enemy->addController(std::make_shared<CRestrictPositionController>(glm::vec2(-100.f, -100.f), glm::vec2(100.f, 100.f)));
			enemy->addController(std::make_shared<CSimpleWaypointController>(glm::vec3(-101.f, 50.f, 50.f), 15.f, this));
			enemy->addController(std::make_shared<CHealthController>(100.f));
			enemy->addController(std::make_shared<CRemoveOnDeathController>(this));
		}
		
		// Player collidable added to player collision group
		std::vector<float> enemyVertices;
		std::vector<unsigned int> enemyIndices;
		std::vector<float> enemyNormals;
		std::vector<float> enemyUvs;
		EPrimitiveType enemyType;
		m_resourceManager->getMesh(enemyShip, enemyVertices, enemyIndices, enemyNormals, enemyUvs, enemyType);
		enemy->setCollidable(m_collisionSystem->add(CAABBox::create(enemyVertices), m_enemyGroup));

		// Create scene object
		CSceneObjectProxy* enemySceneObject = new CSceneObjectProxy(m_scene, m_scene->createObject(enemyShip, enemyShipMaterial, glm::vec3(m_enemyXPosition, 25.f, 0.f), glm::quat(0.f, 0.f, 0.f, 0.f), glm::vec3(0.5f)));
		enemy->setSceneObject(enemySceneObject);

        // Add enemy
		getGameWorld().addObject(enemy);

		m_enemyCount -= 1;
		m_enemyXPosition += 25.f;
	}

	
	m_ring->setRotation(glm::vec3(m_ring->getRotation().x, m_ring->getRotation().y, m_ring->getRotation().z + dtime));
	

	if (m_inputProvider->isKeyPressed(GLFW_KEY_P))
	{
		return false;
	}
	if (m_inputProvider->isKeyPressed(GLFW_KEY_O))
	{
//.........这里部分代码省略.........
开发者ID:whztt07,项目名称:CG2015,代码行数:101,代码来源:CGamePlayState.cpp


注:本文中的CGameObject::addController方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。