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


C++ PhysicsContact类代码示例

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


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

示例1: collisionBeginCallback

int PhysicsWorld::collisionBeginCallback(PhysicsContact& contact)
{
    bool ret = true;

    PhysicsShape* shapeA = contact.getShapeA();
    PhysicsShape* shapeB = contact.getShapeB();
    PhysicsBody* bodyA = shapeA->getBody();
    PhysicsBody* bodyB = shapeB->getBody();
    std::vector<PhysicsJoint*> jointsA = bodyA->getJoints();

    // check the joint is collision enable or not
    for (PhysicsJoint* joint : jointsA)
    {
        if (std::find(_joints.begin(), _joints.end(), joint) == _joints.end())
        {
            continue;
        }

        if (!joint->isCollisionEnabled())
        {
            PhysicsBody* body = joint->getBodyA() == bodyA ? joint->getBodyB() : joint->getBodyA();

            if (body == bodyB)
            {
                contact.setNotificationEnable(false);
                return false;
            }
        }
    }

    // bitmask check
    if ((shapeA->getCategoryBitmask() & shapeB->getContactTestBitmask()) == 0
            || (shapeA->getContactTestBitmask() & shapeB->getCategoryBitmask()) == 0)
    {
        contact.setNotificationEnable(false);
    }

    if (shapeA->getGroup() != 0 && shapeA->getGroup() == shapeB->getGroup())
    {
        ret = shapeA->getGroup() > 0;
    }
    else
    {
        if ((shapeA->getCategoryBitmask() & shapeB->getCollisionBitmask()) == 0
                || (shapeB->getCategoryBitmask() & shapeA->getCollisionBitmask()) == 0)
        {
            ret = false;
        }
    }

    if (contact.isNotificationEnabled())
    {
        contact.setEventCode(PhysicsContact::EventCode::BEGIN);
        contact.setWorld(this);
        _scene->getEventDispatcher()->dispatchEvent(&contact);
    }

    return ret ? contact.resetResult() : false;
}
开发者ID:highjin,项目名称:ProjectArthas,代码行数:59,代码来源:CCPhysicsWorld.cpp

示例2: onContactBegan

bool Demo::onContactBegan(PhysicsContact& contact)
{
	auto m_action = FadeOut::create(0.3f);
	auto sp1 = (Sprite*)contact.getShapeA()->getBody()->getNode();
	auto sp2 = (Sprite*)contact.getShapeB()->getBody()->getNode();
	if (sp1->getTag() == 1 && sp2->getTag() == 2) {
		sp1->runAction(m_action);
		testParticleFireworks();
	}
	else if (sp1->getTag() == 2 && sp2->getTag() == 1) {
		sp2->runAction(m_action);
		testParticleFireworks();
	}
	return true;
}
开发者ID:1900zyh,项目名称:SYSU_Win8App,代码行数:15,代码来源:Demo.cpp

示例3: onContactPostSolve

void GameScene::onContactPostSolve(PhysicsContact &contact, const PhysicsContactPostSolve &solve)
{
	auto bodyA = contact.getShapeA()->getBody();
	auto bodyB = contact.getShapeB()->getBody();


	if (bodyA->getTag() == PLAYER && bodyB->getTag() == TILE)
	{
		bodyA->setVelocity(Vec2(bodyA->getVelocity().x * RESTITUTION, bodyA->getVelocity().y * RESTITUTION));
	}
	if (bodyB->getTag() == PLAYER && bodyA->getTag() == TILE)
	{
		bodyB->setVelocity(Vec2(bodyB->getVelocity().x * RESTITUTION, bodyB->getVelocity().y * RESTITUTION));
	}
}
开发者ID:kajaani,项目名称:Konks,代码行数:15,代码来源:GameScene.cpp

示例4: onContactSeparate

bool PassGateComponent::onContactSeparate(PhysicsContact& contact)
{
	if ((contact.getShapeA()->getCollisionBitmask() == PLAYER_ID) && (contact.getShapeB()->getCollisionBitmask() == PASSGATE_AREA_ID))
	{
		if ((_collisionPointX != 0) && (abs(_collisionPointX - contact.getShapeA()->getBody()->getPosition().x) > GATE_WIDTH-5))
		{
			// change 'Y' coordinate of the 'gate' main point
			auto action = MoveTo::create(GATE_ACTION_SPEED, Point(_visibleSize.width / 2, nextPosY()));
			_mainNode->runAction(action);
		}

		_collisionPointX = contact.getShapeA()->getBody()->getPosition().x;
	}

	return false;
}
开发者ID:kira333,项目名称:MyProjects,代码行数:16,代码来源:PassGateComponent.cpp

示例5: cpArbiterIgnore

int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact)
{
    if (!contact.isNotificationEnabled())
    {
        cpArbiterIgnore(static_cast<cpArbiter*>(contact._contactInfo));
        return true;
    }
    
    contact.setEventCode(PhysicsContact::EventCode::PRESOLVE);
    contact.setWorld(this);
    EventCustom event(PHYSICSCONTACT_EVENT_NAME);
    event.setUserData(&contact);
    _scene->getEventDispatcher()->dispatchEvent(&event);
    
    return contact.resetResult();
}
开发者ID:6520874,项目名称:pipiGame,代码行数:16,代码来源:CCPhysicsWorld.cpp

示例6: onContactBegin

bool PlayerComponent::onContactBegin(PhysicsContact& contact)
{
	if (!is_endGame)
	{
		PhysicsBody *a = contact.getShapeB()->getBody();

		if ((a->getCollisionBitmask() == OBSTACLE_ID) || (a->getCollisionBitmask() == SPIKESBORDER_ID))
		{
			is_onTouch = false;
			is_fall = false;
			is_endGame = true;

			// display 'dialog box'
			this->getOwner()->addChild(MyDialogBox::create(
				{
					Label::create("Your Score:", "Calibri", 30),
					Label::create(StringUtils::toString(((ScoreCounterComponent*)this->getOwner()->getComponent(SCORECOUNTER_NAME))->getScore()), "Calibri", 120)
				},
				{
					DialogBoxButton("TRY AGAIN", TextHAlignment::LEFT, CC_CALLBACK_1(GameScene::goToGameScene, ((GameScene*)this->getOwner()))),
					DialogBoxButton("BACK TO\n MAIN MENU", TextHAlignment::RIGHT, CC_CALLBACK_1(GameScene::goToMainMenuScene, ((GameScene*)this->getOwner())))
				}
			), 10);
		}
	}

	return false;
}
开发者ID:kira333,项目名称:MyProjects,代码行数:28,代码来源:PlayerComponent.cpp

示例7: onContactBegin

bool ObjectLayer::onContactBegin(PhysicsContact& contact)
{
    auto objectA = static_cast<custom::Object*>(contact.getShapeA()->getBody()->getNode());
    auto objectB = static_cast<custom::Object*>(contact.getShapeB()->getBody()->getNode());

    if (!objectA || !objectB || !objectA->GetOwner() || !objectB->GetOwner())
    {
        return false;
    }
    if (objectA->GetOwner()->GetType() != objectB->GetOwner()->GetType())
    {
        objectA->Damaged(objectB->GetDefInfo().m_Damage);
        objectB->Damaged(objectA->GetDefInfo().m_Damage);
    }
    return true;
}
开发者ID:dlakwwkd,项目名称:WeaponCook,代码行数:16,代码来源:ObjectLayer.cpp

示例8: onContactBegin

bool Balloon::onContactBegin(PhysicsContact& contact)
{
    auto balloon = static_cast<Balloon*>(contact.getCurrentTarget());

    //if (obj1->getTag() != obj2->getTag())
    //{
    //obj1->removeFromParent();
    /*
    		Event e = contact;

    		auto balloon = static_cast<Balloon*>(e.getCurrentTarget());

    		contact.

    		balloon->setVisible(false);*/
    //}

    //int tag = s->getTag();
    //CCLog("Contact tag: %d", obj1->getTag());
    //CCLog("Contact tag: %d", obj2->getTag());

    //this->removeFromParent();

    //this->setVisible(false);
    //HelloWorld::removeBalloon(this);
    return true;
}
开发者ID:ricky-flyguy,项目名称:RMZ_2014,代码行数:27,代码来源:Balloon.cpp

示例9: if

void GameScene_Box2D::onContactPostSolve(PhysicsContact& contact, const PhysicsContactPostSolve& solve)
{
    auto node1 = contact.getShapeA()->getBody()->getNode();
    auto node2 = contact.getShapeB()->getBody()->getNode();
    if (node1->getTag()== spriteType::kFloor && node2->getTag()== spriteType::kBall) {
        BallSprite *ball = (BallSprite *)node2;
        bool ball_state_none    = (ball->getBallContState() == BallSprite::ballContactState::kNone);
        if (ball_state_none) {
            ball->setBallContState(BallSprite::ballContactState::kFloorContact);
        }
        
    }
    else if (node2->getTag()== spriteType::kFloor && node1->getTag()== spriteType::kBall) {
        BallSprite *ball = (BallSprite *)node1;
        bool ball_state_none    = (ball->getBallContState() == BallSprite::ballContactState::kNone);
        ball->setBallContState(BallSprite::ballContactState::kFloorContact);
        if (ball_state_none) {
            ball->setBallContState(BallSprite::ballContactState::kFloorContact);
        }
    }
    else if (node2->getTag()== spriteType::kBall && node1->getTag()== spriteType::kBall) {
        BallSprite *ball1 = (BallSprite *)node1;
        BallSprite *ball2 = (BallSprite *)node2;
        bool ball1_state_floor   = (ball1->getBallContState() == BallSprite::ballContactState::kFloorContact);
        bool ball2_state_floor   = (ball2->getBallContState() == BallSprite::ballContactState::kFloorContact);
        bool ball1_state_none    = (ball1->getBallContState() == BallSprite::ballContactState::kNone);
        bool ball2_state_none    = (ball2->getBallContState() == BallSprite::ballContactState::kNone);
        bool ball1_state_second  = (ball1->getBallContState() == BallSprite::ballContactState::kSecondContact);
        bool ball2_state_second  = (ball2->getBallContState() == BallSprite::ballContactState::kSecondContact);
        
        if (ball1_state_none || ball2_state_floor) {
            ball1->setBallContState(BallSprite::ballContactState::kSecondContact);
        }
        else if (ball1_state_floor || ball2_state_none) {
            ball2->setBallContState(BallSprite::ballContactState::kSecondContact);
        }
        else if (ball1_state_none || ball2_state_second) {
            ball1->setBallContState(BallSprite::ballContactState::kSecondContact);
        }
        else if (ball2_state_none || ball1_state_second) {
            ball2->setBallContState(BallSprite::ballContactState::kSecondContact);
        }
        
    }
    
}
开发者ID:tigerwoods1206,项目名称:LiquidFunClassOnly,代码行数:46,代码来源:GameScene_Box2D.cpp

示例10: onContactBegan

bool GamePlay::onContactBegan(PhysicsContact &contact) {
  auto nodeA = contact.getShapeA()->getBody()->getNode();
  auto nodeB = contact.getShapeB()->getBody()->getNode();
  auto bang = Sprite::create("HelloWorld.png");
  bang->setScale(0.03);
  bang->setPosition(nodeA->getPosition());
  this->addChild(bang);

  auto actionMove = MoveTo::create(1, nodeA->getPosition());
  auto actionRemove = RemoveSelf::create();
  bang->runAction(Sequence::create(actionMove,actionRemove, nullptr));


  nodeA->removeFromParent();
  nodeB->removeFromParent();
  return true;
}
开发者ID:kadir4172,项目名称:coco_workspace,代码行数:17,代码来源:GameScene.cpp

示例11: onContactBegin

bool HelloWorld::onContactBegin(PhysicsContact& contact){
	//接触开始
	auto a = contact.getShapeA()->getTag();
	auto b = contact.getShapeB()->getTag();
	if ((a*b) == PLAYER_TAG * EDGE_TAG) {
		isContact = true;
		isPressedW = false;
		jumped = false;
	}
	else if ((a*b) == PLAYER_TAG*ENEMY_TAG_ZERO){
		player1->contactNumber++;
	}
	auto temp = String::createWithFormat("%d", player1->contactNumber);
	log(temp->getCString());
	log("onContactBegin");
	return true;
}
开发者ID:JimmyCheung94,项目名称:1,代码行数:17,代码来源:HelloWorldScene.cpp

示例12: onContactBegin

bool WorldLayer::onContactBegin(PhysicsContact& contact) {
    PhysicsBody *aBody = contact.getShapeA()->getBody();
    PhysicsBody *bBody =contact.getShapeB()->getBody();
    Player *player = NULL;
    Entity *object = NULL;
    if(aBody->getNode()->getTag() == 1) {
        player = (Player *)aBody->getNode();
        object = (Entity *)bBody->getNode();
        player->setCollided(object);
        return true;
    } else if(bBody->getNode()->getTag() == 1) {
        player = (Player *)bBody->getNode();
        object = (Entity *)aBody->getNode();
        player->setCollided(object);
        return true;
    }

    return false;
}
开发者ID:DrivenBlue,项目名称:SquirrelReborn,代码行数:19,代码来源:WorldLayer.cpp

示例13: onContactSeperate

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)
	{
		log("leave enemy!");
		playerB->setCanAttack(false);
		playerA->removeAttacker(playerB);
	}
	if (typeB == Player::PlayerType::PLAYER)
	{
		log("leave enemy!");
		playerA->setCanAttack(false);
		playerB->removeAttacker(playerA);
	}
}
开发者ID:evamango,项目名称:democpp36,代码行数:19,代码来源:MainScene.cpp

示例14: onContactSeperate

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);
	}
}
开发者ID:anyexxx,项目名称:Brave_cpp,代码行数:20,代码来源:MainScene.cpp

示例15: onContactBegin

bool CBullet::onContactBegin(PhysicsContact &contact)
{
	auto nodeA = contact.getShapeA()->getBody()->getNode();
	auto nodeB = contact.getShapeB()->getBody()->getNode();

	if (nodeA && nodeB)
	{
		//bullet collision with enemy objects and wall objects
		if (nodeA->getTag() == BULLET_TAG && nodeB->getTag() == ENEMY_TAG)
		{
			nodeA->removeFromParentAndCleanup(true);
		}
		else if (nodeB->getTag() == BULLET_TAG && nodeA->getTag() == ENEMY_TAG)
		{
			nodeB->removeFromParentAndCleanup(true);
		}
	}

	return true;
}
开发者ID:yeojingkang,项目名称:GameEngAssignment,代码行数:20,代码来源:Bullet.cpp


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