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


C++ PhysicsBody::getCollisionBitmask方法代码示例

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


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

示例1: 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

示例2: onContactBegin

bool GameScene::onContactBegin(cocos2d::PhysicsContact &contact) {
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
	if ( (SNAKE_COLLISION_BITMASK == a->getCollisionBitmask() && FOOD_COLLISION_BITMASK == b->getCollisionBitmask()) ||
		(SNAKE_COLLISION_BITMASK == b->getCollisionBitmask() && FOOD_COLLISION_BITMASK == a->getCollisionBitmask()) ) {
		srand(time(NULL));
		auto random = rand() % 370 + 30;
		auto random2 = rand() % 270 + 30;
		auto moveTo = MoveTo::create(0, Vec2(random, random2));
		food->runAction(moveTo);

		int tempX = snakeParts.back()->getPositionX();
		int tempY = snakeParts.back()->getPositionY();
		Sprite* tempSprite = Sprite::create("snake.png");
		switch (direction) {
		case LEFT:
			tempSprite->setPosition(tempX + 10, tempY);
			break;
		case RIGHT:
			tempSprite->setPosition(tempX - 10, tempY);
			break;
		case UP:
			tempSprite->setPosition(tempX, tempY + 10);
			break;
		case DOWN:
			tempSprite->setPosition(tempX, tempY - 10);
			break;
		}

		this->addChild(tempSprite);
		snakeParts.push_back(tempSprite);
	}
	return true;
}
开发者ID:bulletmonks,项目名称:GAMEDEV-SNAKE,代码行数:34,代码来源:GameScene.cpp

示例3: onContactSeperate

void LevelThree::onContactSeperate(cocos2d::PhysicsContact &contact)
{
	PhysicsBody* a = contact.getShapeA()->getBody();
	PhysicsBody* b = contact.getShapeB()->getBody();

	if (1 == a->getCollisionBitmask() || 1 == b->getCollisionBitmask())
	{

	}
}
开发者ID:LpxHiggsy,项目名称:BigLittleWorld,代码行数:10,代码来源:LevelThree.cpp

示例4: onContactPreSolve

bool LevelThree::onContactPreSolve(cocos2d::PhysicsContact &contact, cocos2d::PhysicsContactPreSolve& solve)
{
	PhysicsBody* a = contact.getShapeA()->getBody();
	PhysicsBody* b = contact.getShapeB()->getBody();

	if (1 == a->getCollisionBitmask() || 1 == b->getCollisionBitmask())
	{
		solve.setRestitution(0);
	}

	return true;
}
开发者ID:LpxHiggsy,项目名称:BigLittleWorld,代码行数:12,代码来源:LevelThree.cpp

示例5: onContactBegin

bool HelloWorld::onContactBegin(cocos2d::PhysicsContact &contact) {
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
	if ((1 == a->getCollisionBitmask() && 2 == b->getCollisionBitmask()) || (2 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())) {
		auto spriteA = (Sprite*)a->getNode();
		auto spriteB = (Sprite*)b->getNode();
		if (2 == b->getCollisionBitmask()) {
			this->removeChild(spriteB, true);
			score++;
		} else if (2 == a->getCollisionBitmask()) {
			this->removeChild(spriteA, true);
			score++;
		}
	}
	return true;
}
开发者ID:renzdimayuga,项目名称:GAMEDEV2,代码行数:16,代码来源:HelloWorldScene.cpp

示例6: onContactBegin

bool GameScene::onContactBegin( cocos2d::PhysicsContact &contact )
{
    PhysicsBody *a = contact.getShapeA()->getBody();
    PhysicsBody *b = contact.getShapeB()->getBody();
    
    if ( ( BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask() ) ||
        ( BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask() ) )
    {
        CCLOG("a :%i", a->getCollisionBitmask());
        CCLOG("b: %i", b->getCollisionBitmask() );
        CCLOG("Score: %i", score );
        CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Hit.mp3");
        auto scene = GameOverScene::createScene( score );
        
        Director::getInstance()->replaceScene(TransitionFade::create( TRANSITION_TIME, scene ) );

    }
    else if ( ( BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && POINT_COLLISION_BITMASK == b->getCollisionBitmask() ) ||
             ( BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && POINT_COLLISION_BITMASK == a->getCollisionBitmask() ) )
    {
        CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Point.mp3");
        
        score++;
        __String *tempScore = __String::createWithFormat( "%i", score );
        scoreLabel->setString( tempScore->getCString() );

    }
    
    return true;
}
开发者ID:aperezg,项目名称:flappycocos,代码行数:30,代码来源:GameScene.cpp

示例7: onContactBegin

bool GameScene::onContactBegin(cocos2d::PhysicsContact & contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
	if ((BALL_COLLISION_BITMASK == a->getCollisionBitmask() && (BRICK_COLLISION_BITMASK) == b->getCollisionBitmask()) ||
		(BALL_COLLISION_BITMASK == b->getCollisionBitmask() && (BRICK_COLLISION_BITMASK) == a->getCollisionBitmask()))
	{
		
		auto bricky = b->getNode();
		this->removeChild(bricky);

		score++;
		__String *tempScore = __String::createWithFormat( "%i", score );
        scoreLabel->setString( tempScore->getCString( ) );
		if (score == 50)
		{
			auto scene = GameOverScene::createScene(score);

			Director::getInstance()->replaceScene(TransitionFade::create(TRANSITION_TIME, scene));
		}
	}
	return true;
}
开发者ID:net4nt,项目名称:Breakout,代码行数:23,代码来源:GameScene.cpp

示例8: onContactBegin

bool GameScene::onContactBegin( cocos2d::PhysicsContact &contact )
{
	if(gameState == 1)
	{
		PhysicsBody *a = contact.getShapeA()->getBody();
		PhysicsBody *b = contact.getShapeB()->getBody();

		if ((BIRD_COLLISION_BITMASK == a->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == b->getCollisionBitmask()) || (BIRD_COLLISION_BITMASK == b->getCollisionBitmask() && OBSTACLE_COLLISION_BITMASK == a->getCollisionBitmask()))
		{
			hit();
		}
	}

	return true;
}
开发者ID:lovchinsky,项目名称:Top-Heights,代码行数:15,代码来源:GameScene.cpp

示例9: onContactBegin

bool CGameLayer::onContactBegin(cocos2d::PhysicsContact &contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
	contact.getShapeA()->getTag();
	if (((MASK_BALL == a->getCollisionBitmask()) &&
		(BORDER_CONTACT_BITMASK == b->getCollisionBitmask())) ||
		((MASK_BALL == b->getCollisionBitmask()) &&
			(BORDER_CONTACT_BITMASK == a->getCollisionBitmask())))
	{
		if (m_startBallMovement)
		{
			--g_gameState->m_life;
			this->removeChildByTag(TAG_BALL, true);
			m_ball.erase(m_ball.begin());
			CBall *_ball = new (std::nothrow) CBall();
			_ball->init(this, g_gameState->m_acc * g_gameState->m_level, m_player->GetPosition());
			//this->addChild(_ball);
			m_ball.push_back(_ball);
			m_startBallMovement = false;
		}
		return true;
	}

	if (((MASK_BALL == a->getCollisionBitmask()) &&
		(MASK_BLOCK == b->getCollisionBitmask())) ||
		((MASK_BALL == b->getCollisionBitmask()) &&
			(MASK_BLOCK == a->getCollisionBitmask())))
	{
		int pTag;
		if ((MASK_BALL == a->getCollisionBitmask()) && (MASK_BLOCK == b->getCollisionBitmask()))
		{
			pTag = b->getNode()->getTag();
		}
		else
		{
			pTag = a->getNode()->getTag();
		}

		int i = 0;
		for (auto it = m_blocks.begin(); it != m_blocks.end(); ++it)
		{
			if (pTag == m_blocks[i]->getTag())
			{
				playerScore();
				m_blocks[i]->del(this);
				it = m_blocks.erase(it);
				--it;
			}
			++i;
		}
		return true;
	}
	else if ((a->getCollisionBitmask() == MASK_BALL && MASK_RACKET == b->getCollisionBitmask()) || 
		(b->getCollisionBitmask() == MASK_BALL && MASK_RACKET == a->getCollisionBitmask()))
	{
		return true;
	}
	return false;
}
开发者ID:Smi1le,项目名称:PPO,代码行数:60,代码来源:GameLayer.cpp

示例10: setHit

bool GameScene::setHit(cocos2d::PhysicsContact &contact)
{

	if (GameManager::sharedGameManager()->isGameLive == true)
	{

		PhysicsBody *a = contact.getShapeA()->getBody();
		PhysicsBody *b = contact.getShapeB()->getBody();

		float* v = new float[2];
		v[0] = a->getVelocity().length(); // Created By An Unknown Source, Via Stack OverFlow
		v[1] = b->getVelocity().length(); // Created By An Unknown Source, Via Stack OverFlow

		contact.setData(v);


		if ((1 == a->getCollisionBitmask() && 2 == b->getCollisionBitmask()) || (2 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask()))// BACK TO FRONT FOR NOW
		{
			bool hit = true;
		}

		else
		{
			bool hit = false;
		}

		if (hit = true)
		{

			if ((a->getCollisionBitmask() == Paddle_Bitmask && b->getCollisionBitmask() == Ball_Bitmask) || (a->getCollisionBitmask() == Ball_Bitmask && b->getCollisionBitmask() == Paddle_Bitmask))
			{
				Ball::sharedBall()->AddToDampening(5000.0f);
				SoundManager::sharedSoundManager()->PlaySoundEffect("ballRebound.mp3", false, 1.0f, 1.0f, 1.0f);
			}

			if ((a->getCollisionBitmask() == Brick_Bitmask && b->getCollisionBitmask() == Ball_Bitmask) || (a->getCollisionBitmask() == Ball_Bitmask && b->getCollisionBitmask() == Brick_Bitmask))
			{
				Ball::sharedBall()->AddToDampening(5000.0f);
				GameManager::sharedGameManager()->AddToScore(1);
				this->removeChild(contact.getShapeB()->getBody()->getNode());

				Ball::sharedBall()->AddToAcceleration(5000);
				//ScoreLabel->setString(StringUtils::format("%d", GameManager::sharedGameManager()->GetScore()));

				Vec2 first = contact.getShapeA()->getBody()->getNode()->convertToWorldSpace(Vec2(50, 50));

				x = first.x;
				y = first.y;

				this->schedule(schedule_selector(GameScene::SetPowerUp));

				//level = 50;
				if (level == 1)
				{
					number = number + 1;
					CCLOG("number = %i", number);

					brick.SetLevel(level);
					//if (number == 5)
					//{
					// CCLOG("level 2");
					// //level = 2;
					// this->removeChild(contact.getShapeA()->getBody()->getNode());
					//this->schedule(schedule_selector(GameScene::SetBrick));
					//this->schedule(schedule_selector(GameScene::SetBall));
					//}
				}

				else if (level == 2)
				{
					number = number + 1;
					brick.SetLevel(level);
					/*if (number == 5)
					{
					level = 3;
					this->removeChild(contact.getShapeA()->getBody()->getNode());
					this->schedule(schedule_selector(GameScene::SetBrick));
					this->schedule(schedule_selector(GameScene::SetBall));
					}*/

				}

				else if (level == 3)
				{
					number = number + 1;
					brick.SetLevel(level);
					/*if (number == 5)
					{
					level = 4;
					this->removeChild(contact.getShapeA()->getBody()->getNode());
					this->schedule(schedule_selector(GameScene::SetBrick));
					this->schedule(schedule_selector(GameScene::SetBall));
					}*/
				}

				else if (level == 4)
				{
					number = number + 1;
					brick.SetLevel(level);
					/*if (number == 5)
//.........这里部分代码省略.........
开发者ID:JamesEdgerton1995,项目名称:BaseLandscapeProject,代码行数:101,代码来源:GameMainScene.cpp

示例11: onContactPostSolve

void LevelThree::onContactPostSolve(cocos2d::PhysicsContact &contact, const cocos2d::PhysicsContactPostSolve& solve)
{
	PhysicsBody* a = contact.getShapeA()->getBody();
	PhysicsBody* b = contact.getShapeB()->getBody();

	if (1 == a->getCollisionBitmask() && 21 == b->getCollisionBitmask())
	{
		this->removeAllChildren();
		LevelThree::GoToLevel4();
		slingshot = true;
	}
	else if (21 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
	{
		this->removeAllChildren();
		LevelThree::GoToLevel4();
		slingshot = true;
	}
	else
	{
		if (1 == a->getCollisionBitmask() && 9 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (9 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 10 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (10 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 11 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (11 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 12 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (12 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 13 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (13 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 14 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (14 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 15 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (15 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 16 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		else if (16 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())
		{
			LevelThree::GoToGameOverScene();
			slingshot = false;
		}
		if (1 == a->getCollisionBitmask() && 17 == b->getCollisionBitmask())
//.........这里部分代码省略.........
开发者ID:LpxHiggsy,项目名称:BigLittleWorld,代码行数:101,代码来源:LevelThree.cpp

示例12: onContactBegin

bool GameSceneQuattro::onContactBegin(cocos2d::PhysicsContact &contact)
{
	cocos2d::log("GameSceneQuattro::onContactBegin   ....... inizio   ");
    PhysicsBody *a = contact.getShapeA()->getBody();
    PhysicsBody *b = contact.getShapeB()->getBody();


    PhysicsBody *pallinaBody = nullptr ;
    if ( ! (3 == a->getCollisionBitmask() && 3 == b->getCollisionBitmask())){
			if (  3 == a->getCollisionBitmask() )
			   {
				  // CCLOG( "GameSceneQuattro::onContactBegin COLLISION HAS OCCURED" );
				   pallinaBody = contact.getShapeA()->getBody();
			   }

			if (   3 == b->getCollisionBitmask() )
			   {
					pallinaBody = contact.getShapeB()->getBody();
			   }

         if(pallinaBody){


        	 _emitter->setPosition(pallinaBody->getNode()->getPosition());
        	 _emitter->resetSystem();
        	 _emitter->setDuration(0.5);

			//prendo tag
			  if (12 == pallinaBody->getTag()){
			        	  cocos2d::log("GameSceneQuattro::onContactBegin   colpita pallina 2  ");
                    //deve variare la y
			        	 // pallinaBody->applyForce( Vect(-50, -220) );
                         pallinaBody->setVelocity(Vec2(randomValueTra(900,900),
                        		 randomValueTra(0,500)));
			    }
			  if (13 == pallinaBody->getTag()){
						        	  cocos2d::log("GameSceneQuattro::onContactBegin  colpita pallina 3   ");

                  pallinaBody->setVelocity(Vec2(randomValueTra(900,1900),
                		  randomValueTra(0,800)));
				}
			  if (14 == pallinaBody->getTag()){
			 						        	  cocos2d::log("GameSceneQuattro::onContactBegin  colpita pallina 4   ");

                  pallinaBody->setVelocity(Vec2(randomValueTra(900,1900),
                		  randomValueTra(0,800)));

			 				}
			  if (15 == pallinaBody->getTag()){
			 						        	  cocos2d::log("GameSceneQuattro::onContactBegin   colpita pallina 5  ");

                  pallinaBody->setVelocity(Vec2(randomValueTra(900,1900),
                		  randomValueTra(-400,800)));
			 				}
           }
        }


          if (PIETRA_TAG == a->getTag()){
        	//  cocos2d::log("GameSceneQuattro::onContactBegin   ....... 1  ");
              a-> getNode()->stopAllActions();
        	  a-> getNode()->setVisible(false);
              a->removeFromWorld();
              //a->setEnable(false);         	 // a->applyForce( Vect(100, 78) );
          }
          if (PIETRA_TAG == b->getTag()   ){
        	 // cocos2d::log("GameSceneQuattro::onContactBegin   ....... 2  ");
               b-> getNode()->stopAllActions();
        	  b-> getNode()->setVisible(false);
              b->removeFromWorld();

             // b->setEnable(false);
        	 // b->applyForce( Vect(100, 78) );
         }

               CCLOG("Forse megio cosi recupero i tag e poi faccio tutto" );
              auto sp = (Sprite*)contact.getShapeA()->getBody()->getNode();
              int tag = sp->getTag();
              CCLOG("onContactBegin tag di A : %d", tag);
              auto spb = (Sprite*)contact.getShapeA()->getBody()->getNode();
				int tagb = spb->getTag();
				CCLOG("onContactBegin tag di B : %d", tagb);


    return true;
}
开发者ID:silviomazzotta,项目名称:Pippo,代码行数:86,代码来源:GameSceneQuattro.cpp

示例13: onContactBegin

bool Tutorial::onContactBegin(cocos2d::PhysicsContact &contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
	auto nodeA = contact.getShapeA()->getBody()->getNode();
	auto nodeB = contact.getShapeB()->getBody()->getNode();
	if (nodeA && nodeB)
	{
		if (nodeA->getTag() == 10)
		{
			if (nodeB->getTag() == 30)
			{
				CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/scoreSound.mp3");
				nodeB->removeFromParentAndCleanup(true);
			}

			else if (nodeB->getTag() == 40)
			{
				CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/invisCollected.mp3");
				nodeB->removeFromParentAndCleanup(true);
				powerUpBool = true;
				this->scheduleOnce(schedule_selector(Tutorial::DeactivatePowerUp), 4.0f);
			}
			else if (nodeB->getTag() == 50)
			{
				CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/speedboost.mp3");
				nodeB->removeFromParentAndCleanup(true);
				speed -= true;
				this->scheduleOnce(schedule_selector(Tutorial::StopSpeed), 3.0f);
			}
			else if (nodeB->getTag() == 60)
			{
				CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/ScoreBoost.mp3");
				nodeB->removeFromParentAndCleanup(true);
			}
		}
		else if (nodeA->getTag() == 30)
		{
			CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/scoreSound.mp3");
			nodeA->removeFromParentAndCleanup(true);
		}
		else if (nodeA->getTag() == 40)
		{
			CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/invisCollected.mp3");
			nodeA->removeFromParentAndCleanup(true);
			powerUpBool = true;
			this->scheduleOnce(schedule_selector(Tutorial::DeactivatePowerUp), 4.0f);
		}
		else if (nodeA->getTag() == 50)
		{
			CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/speedboost.mp3");
			nodeA->removeFromParentAndCleanup(true);
			speed -= true;
			this->scheduleOnce(schedule_selector(Tutorial::StopSpeed), 3.0f);
		}
		else if (nodeA->getTag() == 60)
		{
			CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/ScoreBoost.mp3");
			nodeA->removeFromParentAndCleanup(true);
		}
	}

	if ((0x000001 == a->getCollisionBitmask() && 0x000002 == b->getCollisionBitmask() || 0x000001 == b->getCollisionBitmask() && 0x000002 == a->getCollisionBitmask()))
	{
		if (powerUpBool == false)
		{
			this->scheduleOnce(schedule_selector(Tutorial::activateGameOverScene), 1.491f);
			CocosDenshion::SimpleAudioEngine::getInstance()->setEffectsVolume(0.85f);
			CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/crashSound.mp3");
			move = false;
			Crash();
			CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("audio/GameOver.mp3");	
		}
	}
	return true;
}
开发者ID:shanedooley,项目名称:FinalYearProject,代码行数:76,代码来源:Tutorial.cpp

示例14: onContactBegin

bool LevelTwo::onContactBegin(cocos2d::PhysicsContact &contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();

	auto nodeA = contact.getShapeA()->getBody()->getNode();
	auto nodeB = contact.getShapeB()->getBody()->getNode();

	if ((nodeA&&nodeB))
	{
		if ((nodeA->getTag() == 21))
		{
			if (nodeB->getTag() == 10)
			{
				playerOneDead = true;
			}
		}

		if ((nodeA->getTag() == 10))
		{
			if (nodeB->getTag() == 21)
			{
				playerOneDead = true;
			}
		}
		//You'll have to check for collision between Jill and the platform and the platform and Jill
		//Collision between Jill and her endgame platform
		if ((nodeA->getTag() == 11))
		{
			if (nodeB->getTag() == 8)
			{
				playerTwoEndGame = true;
			}
		}

		//Collision between the platform and Jill.
		if ((nodeA->getTag() == 8))
		{
			if (nodeB->getTag() == 11)
			{
				playerTwoEndGame = true;
			}
		}

		if ((nodeA->getTag() == 7))
		{
			//Collision between jack and his endGame platform
			if (nodeB->getTag() == 10)
			{
				playerOneEndGame = true;
			}
		}

		if ((nodeA->getTag() == 10))
		{
			//Collision between jack and his endGame platform
			if (nodeB->getTag() == 7)
			{
				playerOneEndGame = true;
			}

			if (nodeB->getTag() == 20)
			{
				//trap->removeTrap(trap);
				//removeTraps = true;
				//m_traps->
				//nodeB->removeFromParentAndCleanup(true);
				for (int i = 0; i < m_traps.size(); i++)
				{
					auto trap = m_traps.at(i);
					Director::getInstance()->getRunningScene()->removeChild(trap);
					//iter = m_projectiles.erase(iter);
					delete m_traps.at(i);
					//m_traps[i]->removeFromParentAndCleanup(true);
					addPlatfroms = true;
				}
				m_traps.clear();
				//GameScreen::addPlatfroms = true;
			}
		}

		if ((nodeA->getTag() == 20))
		{
			if (nodeB->getTag() == 10)
			{
				//nodeA->removeFromParentAndCleanup(true);
			}
		}
		//return addPlatfroms;
	}



	//check if the bodies have collided.
	if ((0x000001 == a->getCollisionBitmask() && 0x000016 == b->getCollisionBitmask()) || (0x000016 == a->getCollisionBitmask() && 0x000001 == b->getCollisionBitmask()))
	{
		CCLOG("Collision has occured between Jack and the door!");
		//pButton->setSpriteFrame(ptr->m_buttonPressed);
		//this->scheduleOnce(schedule_selector(GameScreen::activateGameOverScene), 1.0f);
		playerOneEndGame = true;
//.........这里部分代码省略.........
开发者ID:ChristopherBuggy,项目名称:FYP,代码行数:101,代码来源:levelTwo.cpp

示例15: setHit

bool GameScene::setHit(cocos2d::PhysicsContact &contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
	
	if ((1 == a->getCollisionBitmask() && 2 == b->getCollisionBitmask()) || (2 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask()))// BACK TO FRONT FOR NOW
	{
		bool hit = true;
		CCLOG(" A Collision has occured");
	}
	
	else
	{
		bool hit = false;
	}
	
	if (hit = true)
	{

		if ((a->getCollisionBitmask() == Paddle_Bitmask && b->getCollisionBitmask() == Ball_Bitmask) || (a->getCollisionBitmask() == Ball_Bitmask && b->getCollisionBitmask() == Paddle_Bitmask))
		{
			Ball::sharedBall()->AddToDampening(5000.0f);
		}

		if ((a->getCollisionBitmask() == Brick_Bitmask && b->getCollisionBitmask() == Ball_Bitmask) || (a->getCollisionBitmask() == Ball_Bitmask && b->getCollisionBitmask() == Brick_Bitmask))
		{
			Ball::sharedBall()->AddToDampening(5000.0f);
			GameManager::sharedGameManager()->AddToScore(1);
			this->removeChild(contact.getShapeB()->getBody()->getNode());
			
			Ball::sharedBall()->AddToAcceleration(5000);
			//ScoreLabel->setString(StringUtils::format("%d", GameManager::sharedGameManager()->GetScore()));

				Vec2 first = contact.getShapeA()->getBody()->getNode()->convertToWorldSpace(Vec2(50, 50));
				Vec2 Second = contact.getShapeA()->getBody()->getNode()->convertToWorldSpace(Vec2(50, 50));
				//CCLOG("X: %f",x);
				//CCLOG("Y: %f", y);
				//CCLOG("position = (%f,%f)", x, y);
				x = first.x;
				y = first.y;

				xb = Second.x;
				yb = Second.y;
				CCLOG("position = (%f,%f)", first.x, first.y);
				this->schedule(schedule_selector(GameScene::SetPowerUp));

			 if (level == 1)
			{
				 number = number + 1;
				 CCLOG("number = %i", number);
				 if (number == 5)
				 {
					 CCLOG("level 2");
					 level = 2;
					 this->removeChild(contact.getShapeA()->getBody()->getNode());
					this->schedule(schedule_selector(GameScene::SetBrick));
					this->schedule(schedule_selector(GameScene::SetBall));
				 }
			}

			else if (level == 2)
			{
				number = number + 1;

				if (number == 5)
				{
					level = 3;
					this->removeChild(contact.getShapeA()->getBody()->getNode());
					this->schedule(schedule_selector(GameScene::SetBrick));
					this->schedule(schedule_selector(GameScene::SetBall));
				}

			}

			else if (level == 3)
			{
				number = number + 1;

				if (number == 5)
				{
					level = 4;
					this->removeChild(contact.getShapeA()->getBody()->getNode());
					this->schedule(schedule_selector(GameScene::SetBrick));
					this->schedule(schedule_selector(GameScene::SetBall));
				}
			}

			else if (level == 4)
			{
				number = number + 1;

				if (number == 5)
				{
					level = 5;
					this->removeChild(contact.getShapeA()->getBody()->getNode());
					this->schedule(schedule_selector(GameScene::SetBrick));
					this->schedule(schedule_selector(GameScene::SetBall));
				}
			}
		}
//.........这里部分代码省略.........
开发者ID:JamesEdgerton1995,项目名称:BaseLandscapeProject,代码行数:101,代码来源:GameMainScene.cpp


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