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


C++ Entity::GetState方法代码示例

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


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

示例1: Update

void ProjectileSystem::Update(float _dt)
{
	MouseInputComponent* mouse;
	PositionComponent* position;

	EntityMap::iterator it;
	for (it = m_entityMap.begin(); it != m_entityMap.end(); ++it)
	{
		Entity* e = it->second;
		if (e->GetState() != Entity::ALIVE)
			continue;

		mouse = e->GetComponent<MouseInputComponent>();
		if (mouse->m_controls.LeftButton == InputState::Pressed)
		{
			position = it->second->GetComponent<PositionComponent>();

			Entity* e = m_world->CreateEntity();
			EntityFactory::GetInstance()->CreateEntity(e, EntityFactory::BALL);
			e->GetComponent<VelocityComponent>()->m_velocity = VECTOR3(0, 40, 0);
			e->GetComponent<PositionComponent>()->SetPosition(VECTOR3(position->GetPosition().x, position->GetPosition().y + 2.0f, 0));

			m_world->AddEntity(e);
		}
	}
}
开发者ID:kelkka,项目名称:Agile,代码行数:26,代码来源:ProjectileSystem.cpp

示例2: Update

void AudioSystem::Update(float _dt)
{
	for (auto entityPair : m_entityMap)
	{
		Entity* e = entityPair.second;

		if ((e->GetState() == Entity::DEAD))
			continue;

		auto collision = e->GetComponent<CollisionComponent>();
		std::vector<CollisionContact> collisions = collision->GetCollisions();
		for (unsigned int i = 0; i < collisions.size(); ++i)
		{
			const char* audioPath = e->GetComponent<AudioComponent>()->m_audioPath.c_str();
			m_audioManager->PlaySoundEffect(audioPath);
		}
	}

}
开发者ID:kelkka,项目名称:Agile,代码行数:19,代码来源:AudioSystem.cpp

示例3: Update

void PhysicsSystem::Update(float _dt)
{
	for (auto it = m_entityMap.begin(); it != m_entityMap.end(); ++it)
	{
		Entity* e = it->second;
		if (e->GetState() != Entity::ALIVE)
			continue;

		auto collision = e->GetComponent<CollisionComponent>();
		auto stats = e->GetComponent<CollisionStatsComponent>();
		auto position = e->GetComponent<PositionComponent>();
		auto velocity = e->GetComponent<VelocityComponent>();
		auto rotation = e->GetComponent<RotationComponent>();
		b2Body* b2Body = collision->GetBody();
		
		// Update position, velocity and rotation after the components
		if (position && rotation)
		{
			const b2Vec2 b2Pos = b2Vec2(position->GetPosition().x, position->GetPosition().y);
			if (collision->GetBody()->GetPosition().x != b2Pos.x || collision->GetBody()->GetPosition().y != b2Pos.y || collision->GetBody()->GetAngle() != rotation->GetRotation().z)
				collision->GetBody()->SetTransform(b2Pos, rotation->GetRotation().z);
		}
		else if (position)
		{
			const b2Vec2 b2Pos = b2Vec2(position->GetPosition().x, position->GetPosition().y);
			if (collision->GetBody()->GetPosition().x != b2Pos.x || collision->GetBody()->GetPosition().y != b2Pos.y)
				collision->GetBody()->SetTransform(b2Pos, collision->GetBody()->GetAngle());
		}
		else if (rotation)
		{
			if (collision->GetBody()->GetAngle() != rotation->GetRotation().z)
				collision->GetBody()->SetTransform(collision->GetBody()->GetPosition(), rotation->GetRotation().z);
		}
		if (velocity)
		{
			const b2Vec2 b2Velocity = b2Vec2(velocity->m_velocity.x, velocity->m_velocity.y);
			if (collision->GetBody()->GetLinearVelocity().x != b2Velocity.x || collision->GetBody()->GetLinearVelocity().y != b2Velocity.y)
				collision->GetBody()->SetLinearVelocity(b2Velocity);
		}
		
		// Update velocity min/max and deacceleration
		if (velocity && stats)
		{
			if (b2Body->GetLinearVelocity().y <= 0.5f && b2Body->GetLinearVelocity().y >= -0.5f)
				b2Body->SetLinearVelocity(b2Vec2(b2Body->GetLinearVelocity().x, -3.0f));

			float speed = b2Body->GetLinearVelocity().Length();
			// Speed cant be 0
			if (speed == 0)
				continue;
			// Set speed between min/max
			if (speed < stats->GetMinSpeed())
			{
				b2Body->SetLinearVelocity(b2Vec2((b2Body->GetLinearVelocity().x / speed) * stats->GetMinSpeed(), (b2Body->GetLinearVelocity().y / speed) * stats->GetMinSpeed()));
			}
			if (speed > stats->GetMaxSpeed())
			{
				b2Body->SetLinearVelocity(b2Vec2((b2Body->GetLinearVelocity().x / speed) * stats->GetMaxSpeed(), (b2Body->GetLinearVelocity().y / speed) * stats->GetMaxSpeed()));
			}
			// Deaccelerate
			if (speed > stats->GetMaxDampingSpeed())
			{
				float newSpeed = speed - (stats->GetDampingAcceleration() * _dt);
				if (speed < stats->GetMaxDampingSpeed())
					newSpeed = stats->GetMaxDampingSpeed();
				b2Body->SetLinearVelocity(b2Vec2((b2Body->GetLinearVelocity().x / speed) * newSpeed, (b2Body->GetLinearVelocity().y / speed) * newSpeed));
			}
		}
	}

	// Simulate worlds physics
	m_b2World->Step(_dt, VELOCITYITERATIONS, POSITIONITERATIONS);

	// Update position, velocity and rotation components
	for (auto it = m_entityMap.begin(); it != m_entityMap.end(); ++it)
	{
		Entity* e = it->second;

		if (e->GetState() != Entity::ALIVE)
			continue;

		auto collision = e->GetComponent<CollisionComponent>();
		auto position = e->GetComponent<PositionComponent>();
		auto velocity = e->GetComponent<VelocityComponent>();
		auto rotation = e->GetComponent<RotationComponent>();
		b2Body* b2Body = collision->GetBody();

		collision->ResetCollisions();

		if (position)
		{
			b2Vec2 b2Pos = b2Body->GetPosition();
			position->SetPosition(VECTOR3(b2Pos.x, b2Pos.y, position->GetPosition().z));
		}
		if (velocity)
		{
			b2Vec2 b2Velocity = b2Body->GetLinearVelocity();
			velocity->m_velocity = VECTOR3(b2Velocity.x, b2Velocity.y, velocity->m_velocity.z);
		}
		if (rotation)
//.........这里部分代码省略.........
开发者ID:kelkka,项目名称:Agile,代码行数:101,代码来源:PhysicsSystem.cpp


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