예제 #1
0
bool Brave::onContactBegin(const PhysicsContact& contact)
{
// 	auto playerA = (Player*)contact.getShapeA()->getBody()->getNode();
// 	auto playerB = (Player*)contact.getShapeB()->getBody()->getNode();

	auto playerA = dynamic_cast<Player*>(contact.getShapeA()->getBody()->getNode());
	auto playerB = dynamic_cast<Player*>(contact.getShapeB()->getBody()->getNode());

	auto typeA = playerA->getPlayerType();
	auto typeB = playerB->getPlayerType();

	if (typeA == Player::PlayerType::PLAYER)
	{
		log("contact enmy!");
		playerB->setCanAttack(true);
		playerA->addAttacker(playerB);
	}

	if ( typeB==Player::PlayerType::PLAYER)
	{
		log("contact enemy!");
		playerB->setCanAttack(true);
		playerA->addAttacker(playerB);
	}
	
	return true;
}
예제 #2
0
void MainScene::onContactSeperate(const PhysicsContact& contact)
{
	auto playerA = (Player*)contact.getShapeA()->getBody()->getNode();
	auto playerB = (Player*)contact.getShapeB()->getBody()->getNode();
	auto typeA = playerA->getPlayerType();
	auto typeB = playerB->getPlayerType(); 
	if(typeA == Player::PlayerType::PLAYER)
	{
		// only one player so ShapeB must belong to an enemy		
		log("leave enemy!");
		playerB->setCanAttack(false);
	}

	if(typeB == Player::PlayerType::PLAYER)
	{
		// only one player so ShapeA must belong to an enemy		
		log("leave enemy!");
		playerA->setCanAttack(false);
	}
}
예제 #3
0
bool MainScene::onContactBegin(const PhysicsContact& contact)
{
	auto playerA = (Player*)contact.getShapeA()->getBody()->getNode();
	auto playerB = (Player*)contact.getShapeB()->getBody()->getNode();
	auto typeA = playerA->getPlayerType();
	auto typeB = playerB->getPlayerType(); 
	if(typeA == Player::PlayerType::PLAYER)
	{
		// only one player so ShapeB must belong to an enemy		
		log("contact enemy!");
		playerB->setCanAttack(true);
	}
	if(typeB == Player::PlayerType::PLAYER)
	{
		// only one player so ShapeA must belong to an enemy		
		log("contact enemy!");
		playerA->setCanAttack(true);
	}
	return true;
}
예제 #4
0
void Brave::onContactSeperate(const PhysicsContact& contact)
{
	auto playerA = (Player*)contact.getShapeA()->getBody()->getNode();
	auto playerB = (Player*)contact.getShapeA()->getBody()->getNode();

	auto typeA = playerA->getPlayerType();
	auto typeB = playerB->getPlayerType();

	if (typeA==Player::PlayerType::PLAYER)
	{
		log("lave enemy!");
		playerB->setCanAttack(false);
		playerA->removeAttacker(playerB);
	}

	if (typeB == Player::PlayerType::PLAYER)
	{
		log("leave enemy!");
		playerA->setCanAttack(false);
		playerB->removeAttacker(playerA);
	}
}