本文整理汇总了C++中cocos2d::PhysicsContact类的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsContact类的具体用法?C++ PhysicsContact怎么用?C++ PhysicsContact使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhysicsContact类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: onContactBegin
bool BombMissile::onContactBegin(cocos2d::PhysicsContact& contact)
{
//한 번만 데미지 입히게 하기 위한 용도. 뎀 드가고 나면 그림만 보임.
//실제 미사일 삭제 시점은 그래픽 사라지는 시점.
m_IsPhysics = false;
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = (BaseComponent*)bodyA->getNode();
auto componentB = (BaseComponent*)bodyB->getNode();
BaseComponent* enemyComponent;
bool isComponentA = true;
if (componentA->getType() == getType())
{
enemyComponent = componentB;
isComponentA = true;
}
else
{
enemyComponent = componentA;
isComponentA = false;
}
GET_SOUND_MANAGER()->createSound(SoundManager::MONSTERHIT, false, getPosition());
GET_EFFECT_MANAGER()->createEffect(ET_PUNCH_MISSILE, enemyComponent->getPosition())->enter();
return false;
}
开发者ID:highjin,项目名称:ProjectArthas,代码行数:29,代码来源:BombMissile.cpp
示例3: onContactBegin
bool GameLayer::onContactBegin(cocos2d::PhysicsContact &contact)
{
log("2222");
if ((contact.getShapeA()->getBody()->getCategoryBitmask() & kMaskBall) == kMaskBall)
{
//ball do something
}
if ((contact.getShapeB()->getBody()->getCategoryBitmask() & kMaskBall) == kMaskBall)
{
//ball do something
}
if ((contact.getShapeA()->getBody()->getCategoryBitmask() & kMaskPlayer) == kMaskPlayer)
{
//player do something
}
if ((contact.getShapeB()->getBody()->getCategoryBitmask() & kMaskPlayer) == kMaskPlayer)
{
//player do something
}
// auto nodeA = (Sprite*)contact.getShapeA()->getBody()->getNode();
// auto nodeB = (Sprite*)contact.getShapeB()->getBody()->getNode();
//
// if (nodeA == nullptr || nodeB == nullptr)
// {
//
// return false;
// }
return true;
}
开发者ID:mengtest,项目名称:Air-Hockey,代码行数:33,代码来源:GameLayer.cpp
示例4: onContactBegin
bool PFMPlayer::onContactBegin(cocos2d::PhysicsContact &contact)
{
if(contact.getShapeA()->getBody() == getPhysicsBody() ||
contact.getShapeB()->getBody() == getPhysicsBody())
{
PhysicsBody* other = contact.getShapeA()->getBody() == getPhysicsBody()?contact.getShapeB()->getBody() : contact.getShapeA()->getBody();
switch (other->getTag()) {
case PFMPhysicsBodyTypeEnemyBullet:
{
PFMBullet* bullet = dynamic_cast<PFMBullet*>(other->getNode());
if(bullet != NULL)
{
health -= bullet->damage;
}
other->getOwner()->removeFromParentAndCleanup(true);
break;
}
case PFMPhysicsBodyTypeEnemy:
other->getOwner()->removeFromParentAndCleanup(true);
break;
default:
break;
}
}
return true;
}
开发者ID:tomcat2088,项目名称:PlaneFightMaker,代码行数:26,代码来源:PFMPlayer.cpp
示例5: 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
示例6: switchMoveActionAfter
bool ContactManager::switchMoveActionAfter(const cocos2d::PhysicsContact &contact){
int body_tag = 0;
//找到碰撞物体
if(contact.getShapeA()->getBody()->getNode()->getTag()==PROTAGONIST_TAG){
node_Pro = contact.getShapeA()->getBody()->getNode();
node_else =contact.getShapeB()->getBody()->getNode();
body_tag = node_else->getTag();
}else{
node_Pro = contact.getShapeB()->getBody()->getNode();
node_else = contact.getShapeA()->getBody()->getNode();
body_tag = node_else->getTag();
}
switch((body_tag/1000)*1000){
case SECTION_TAG:{
ContactManager::onContactSeparatePro_Section();
break;
}
}
return false;
}
开发者ID:yjq13,项目名称:PrisonBreak_v1.1,代码行数:25,代码来源:ContactManager.cpp
示例7: 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
示例8: onContactBegin
bool MonsterDevil::onContactBegin(cocos2d::PhysicsContact& contact)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = (BaseComponent*)bodyA->getNode();
auto componentB = (BaseComponent*)bodyB->getNode();
BaseComponent* enemyComponent;
bool isComponentA = true;
//어떤것 끼리 부딪혔는지는 안가르쳐주기 때문에
//여기서 어느쪽이 monsterDevil인지 밝혀낸다.
if (componentA->getType() == getType())
{
enemyComponent = componentB;
isComponentA = true;
}
else
{
enemyComponent = componentA;
isComponentA = false;
}
//FLOOR 충돌 무시
if (enemyComponent->getType() == OT_FLOOR)
{
return false;
}
//미사일이랑 충돌 처리
if (enemyComponent->getPhysicsBody()->getCategoryBitmask() == PHYC_MISSILE)
{
Missile* missile = static_cast<Missile*>(enemyComponent);
//수류탄은 뎀 안 입음
if (missile->getType() == OT_MISSILE_GRENADE)
{
return false;
}
//몹이 쏜 건 안 맞음.
if (!missile->isPlayerMissile())
{
return false;
}
float damage = missile->getDamage();
m_Info.m_CurrentHp -= damage * 100 / (100 + m_Info.m_DefensivePower);
//사망
if (m_Info.m_CurrentHp <= 0)
{
m_IsDead = true;
}
}
return true;
}
开发者ID:highjin,项目名称:ProjectArthas,代码行数:59,代码来源:MonsterDevil.cpp
示例9: onContactBegin
bool LevelThree::onContactBegin(cocos2d::PhysicsContact &contact)
{
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeB()->getBody();
//On contact between player and any enemy, spike, or laser. Kill player. Check Lives. Run reset/Game Over.
return true;
}
开发者ID:LpxHiggsy,项目名称:BigLittleWorld,代码行数:9,代码来源:LevelThree.cpp
示例10: ContactDetect
static bool ContactDetect(cocos2d::PhysicsContact & contact, cocos2d::Layer * layer, int * score)
{
cocos2d::Node * nodeA = contact.getShapeA()->getBody()->getNode();
cocos2d::Node * nodeB = contact.getShapeB()->getBody()->getNode();
if (nodeA && nodeB)
{
int maskA = nodeA->getPhysicsBody()->getContactTestBitmask();
int maskB = nodeB->getPhysicsBody()->getContactTestBitmask();
switch (maskA | maskB)
{
case 0b0101 :
{
// EnemyFighter with Fighter
Fighter * fighter = ((maskA == 0b0100) ? (Fighter *)nodeA : (Fighter *)nodeB);
EnemyFighter * enemy = ((maskA == 0b0001) ? (EnemyFighter *)nodeA : (EnemyFighter *)nodeB);
FighterWithEnemy(fighter, enemy, score);
break;
}
case 0b0110 :
{
// EnemyBullet with Fighter
Fighter * fighter;
EnemyBullet * bullet;
if (maskA == 0b0100)
{
fighter = dynamic_cast<Fighter *>(nodeA);
bullet = dynamic_cast<EnemyBullet *>(nodeB);
}
else
{
fighter = dynamic_cast<Fighter *>(nodeB);
bullet = dynamic_cast<EnemyBullet *>(nodeA);
}
FighterWithBullet(fighter, bullet, score);
break;
}
case 0b1001 :
{
// Bullet with EnemyFighter
EnemyFighter * enemy = ((maskA == 0b0001) ? (EnemyFighter *)nodeA : (EnemyFighter *)nodeB);
Bullet * bullet = ((maskA == 0b1000) ? (Bullet *)nodeA : (Bullet *)nodeB);
EnemyWithBullet(enemy, bullet, layer, score);
break;
}
default:
break;
}
}
return false;
}
开发者ID:LucienLIUFL,项目名称:Project,代码行数:57,代码来源:ContactLogic.hpp
示例11: 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
示例12: onContactBegin
bool GameLayer::onContactBegin(cocos2d::PhysicsContact& contact)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = static_cast<BaseComponent*>( bodyA->getNode() );
auto componentB = static_cast<BaseComponent*>( bodyB->getNode() );
bool resA = componentA->onContactBegin(contact);
bool resB = componentB->onContactBegin(contact);
return resA && resB;
}
开发者ID:highjin,项目名称:ProjectArthas,代码行数:11,代码来源:GameLayer.cpp
示例13: 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
示例14: onCollisionBegin
/** 碰撞开始事件
* @2015/12/28 14:40
*/
bool guaiwu_js::onCollisionBegin(const cocos2d::PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
PhysicsBody* temp =nullptr;
log("弹簧 A:%d B:%d",bodyA->getTag(),bodyB->getTag());
if(bodyA->getTag() == 400001){
temp = bodyB;
bodyB = bodyA;
bodyA = temp;
}
if(bodyB->getTag() == 400001)
{
if (bodyA->getTag() ==400008)
{
//设置怪物 停止移动
isMove =false;
//切换动画吃东西
this->removeFromParent();
}
if (bodyA->getTag() == 400010) {
this->iskeyl = !this->iskeyl;
this->iskeyr = !this->iskeyr;
this->setScaleX(-this->getScaleX());
log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
switch (bodyA->getTag()) {
case 400006:
if (bodyA->getNode() !=nullptr)
{
bodyA->getNode()->removeFromParent();
}
setEat();
break;
case 555555:
//僵死碰到车
guaiwu_js::killcar();
break;
case 600001:
break;
default:
break;
}
}
return true;
}
开发者ID:jian22446688,项目名称:DesertTour,代码行数:56,代码来源:guaiwu_js.cpp
示例15: switch
/** 碰撞开始事件
* @2015/12/16 11:28
*/
bool Level_1::onCollisionBegin(const cocos2d::PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
PhysicsBody* temp =nullptr;
//log("A:%d B:%d",bodyA->getTag(),bodyB->getTag());
if(bodyA->getTag() == 555555)
{
temp = bodyB;
bodyB = bodyA;
bodyA = temp;
}
if(bodyB->getTag() == 555555)
{
//log("A:%d",bodyA->getTag());
// 100001 物理世界
// 555555 主要车的
// 300001 悬浮的物体
// 400001 第一关的怪物
// 600001 弹簧的物体
if (bodyA->getTag()== 400001)
{
MainCar_R* car =(MainCar_R*)bodyB->getNode()->getParent()->getParent();
//car->removeFromParent();
car->setBodyEnable();
}
switch (bodyA->getTag()) {
case 400001:
log("第一关的怪物");
bodyB->setEnabled(false);
break;
case 300001:
log("悬浮的物体");
break;
case 600001:
log("弹簧的物体");
break;
default:
break;
}
}
return true;
}
开发者ID:jian22446688,项目名称:DesertTour,代码行数:56,代码来源:Level_1.cpp
示例16: onContactBegan
bool UT_Map::onContactBegan(cocos2d::PhysicsContact &contact){
auto nodeA = contact.getShapeA()->getBody()->getNode();
auto nodeB = contact.getShapeB()->getBody()->getNode();
// cocos2d::log( " nodeA name %s" , nodeA->getName().c_str() );
// cocos2d::log( " nodeB name %s" , nodeB->getName().c_str() );
if( nodeA == body || nodeB == body){
body_move_r = !body_move_r;
}else{
// cocos2d::log( " can not match ");
}
return true;
}
开发者ID:cyrusNMA,项目名称:test01,代码行数:15,代码来源:UT_Map.cpp
示例17: 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
示例18: onContactSeparate
void GameLayer::onContactSeparate(cocos2d::PhysicsContact& contact)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
auto componentA = static_cast<BaseComponent*>( bodyA->getNode() );
auto componentB = static_cast<BaseComponent*>( bodyB->getNode() );
if (componentA != nullptr)
{
componentA->onContactSeparate(contact);
}
if (componentB != nullptr)
{
componentB->onContactSeparate(contact);
}
}
开发者ID:highjin,项目名称:ProjectArthas,代码行数:16,代码来源:GameLayer.cpp
示例19: 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
示例20: switchMoveAction
bool ContactManager::switchMoveAction(const cocos2d::PhysicsContact &contact){
int body_tag = 0;
//找到碰撞物体
if(contact.getShapeA()->getBody()->getNode()->getTag()==PROTAGONIST_TAG){
node_Pro = contact.getShapeA()->getBody()->getNode();
node_else =contact.getShapeB()->getBody()->getNode();
body_tag = node_else->getTag();
}else{
node_Pro = contact.getShapeB()->getBody()->getNode();
node_else = contact.getShapeA()->getBody()->getNode();
body_tag = node_else->getTag();
}
switch((body_tag/1000)*1000){
case SECTION_TAG:{
ContactManager::onContactBeginPro_Section();
break;
}
case JAILER_TAG:{
ContactManager::onContactBeginPro_Jailer();
break;
}
case MOUSE_TAG:{
ContactManager::onContactBeginPro_Mouse();
break;
}
case COIN_TAG:{
ContactManager::onContactBeginPro_Coin();
break;
}
case WALL_TAG:{
ContactManager::onContactBeginPro_Wall();
break;
}
case SECTION_END_TAG:{
ContactManager::onContactBeginPro_End();
break;
}
}
return false;
}
开发者ID:yjq13,项目名称:PrisonBreak_v1.1,代码行数:44,代码来源:ContactManager.cpp
注:本文中的cocos2d::PhysicsContact类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论