bool MonsterD::onContactBegin(PhysicsContact &contact) { switch (contact.getShapeA()->getBody()->getContactTestBitmask() | contact.getShapeB()->getBody()->getContactTestBitmask()) { case ARROW_BIT_MASK | MONSTER1_BIT_MASK://箭射中怪物 { //this->removeFromParentAndCleanup(true); auto a = contact.getShapeA()->getBody()->getNode(); auto b = contact.getShapeB()->getBody()->getNode(); log("dispear!!!!!!!!!!!!!!!"); if (a != NULL) { if (UserDefault::getInstance()->getBoolForKey(SOUND_KEY)) { SimpleAudioEngine::getInstance()->playEffect(sound_4); } a->removeFromParentAndCleanup(true); } if (b != NULL) { if (UserDefault::getInstance()->getBoolForKey(SOUND_KEY)) { SimpleAudioEngine::getInstance()->playEffect(sound_4); } b->removeFromParentAndCleanup(true); //long bt = b->getTag();// tilemap->removeChildByTag(); //b->removeFromParentAndCleanup(true); //log("bt %d", bt); //if (-1 < bt < 10001)tilemap->getLayer("pengzhuang")->removeChildByTag(bt); } } break; default: break; } return true; }
bool GameplayLayer::HandleCollision(const PhysicsContact& contact) { if(!player->isAlive || player->isInvulnerable) return false; if(contact.getShapeA()->getTag() == 3 || contact.getShapeB()->getTag() == 3) { if(!player->jumpAnimation->isDone()) { player->IncreaseScore(); playerScoreLabel->setString(String::createWithFormat("%d", (int)player->score)->getCString()); CCLOG("JUMP"); return false; } } else if(contact.getShapeA()->getTag() == 4 || contact.getShapeB()->getTag() == 4) { if(!player->duckAnimation->isDone()) { player->IncreaseScore(); playerScoreLabel->setString(String::createWithFormat("%d", (int)player->score)->getCString()); CCLOG("DUCK"); return false; } } player->Knockback(); std::cout << "Player Hit" << std::endl; return false; }
void Coins::remove(const PhysicsContact &contact, Layer *layer) { if(COIN_BITMASK == contact.getShapeA()->getBody()->getCollisionBitmask()) { contact.getShapeA()->getBody()->removeFromWorld(); layer->removeChild(contact.getShapeA()->getBody()->getNode()); } else { contact.getShapeB()->getBody()->removeFromWorld(); layer->removeChild(contact.getShapeB()->getBody()->getNode()); } }
bool GameScene24::onContactBegin(PhysicsContact& contact) { auto nodeA = (Sprite*)contact.getShapeA()->getBody()->getNode(); auto nodeB = (Sprite*)contact.getShapeB()->getBody()->getNode(); if (nodeA->getTag() == 13 && nodeB->getTag() == 14) { success(); } if (nodeB->getTag() == 13 && nodeA->getTag() == 14) { success(); } if (nodeB->getTag() == 14 && nodeA->getTag() != 14) { lose(); } if (nodeA->getTag() == 14 && nodeB->getTag() != 14) { lose(); } return true; }
bool HelloWorld::onCollision(PhysicsContact& contact) { CCLOG("Collision detected"); auto playerShape = _sprPlayer->getPhysicsBody()->getFirstShape(); if(playerShape != contact.getShapeA() && playerShape != contact.getShapeB()) { return false; } if(_muteItem -> isVisible()) { //CocosDenshion /*SimpleAudioEngine::getInstance()->stopBackgroundMusic(); SimpleAudioEngine::getInstance()->playEffect("uh.wav");*/ //New audio engine AudioEngine::stopAll(); AudioEngine::play2d("uh.mp3"); } UserDefault::getInstance()->setIntegerForKey("score",_score); _director->replaceScene(TransitionFlipX::create(1.0, GameOver::createScene())); auto body = _sprBomb -> getPhysicsBody(); body->setVelocity(Vect()); body->applyTorque(100900.5f); return false; }
bool Player::onContactBegin(PhysicsContact& contact) { auto nodeA = contact.getShapeA()->getBody()->getNode(); auto nodeB = contact.getShapeB()->getBody()->getNode(); GameObject * other; if (dynamic_cast<Player*>(nodeA) == this) { other = dynamic_cast<GameObject*>(nodeB); } else if (dynamic_cast<Player*>(nodeB) == this) { other = dynamic_cast<GameObject*>(nodeA); } if (other->type == GameObjectType::DESTRUCTIBLE) { endGame(); //end game screen } else { acceleration += 10; } return true; }
bool YellowWall::contactLogicPreSolve(PhysicsContact& contact, PhysicsContactPreSolve& solve, ContactLogic *logic) { PhysicsBody* body1 = contact.getShapeA()->getBody(); PhysicsBody* body2 = contact.getShapeB()->getBody(); if ((body1->getTag() == Type_Flag && body2->getTag() == Type_BoxSprite) || (body1->getTag() == Type_BoxSprite && body2->getTag() == Type_Flag)) { if (!this->m_bIsContactFlag) { this->m_bIsContactFlag = true; this->schedule(schedule_selector(YellowWall::updateState), 0.1f); } if (this->m_bIsWin) { logic->setWinState(true); } return false; } if (body1->getTag() == Type_Flag || body2->getTag() == Type_Flag) { return false; } return true; }
bool Coin::onContactBegin(PhysicsContact& contact) { auto nodeA = contact.getShapeA()->getBody()->getNode(); auto nodeB = contact.getShapeB()->getBody()->getNode(); GameObject * other; if (dynamic_cast<Coin*>(nodeA) == this) { other = dynamic_cast<GameObject*>(nodeB); } else if (dynamic_cast<Coin*>(nodeB) == this) { other = dynamic_cast<GameObject*>(nodeA); } if (other->type == GameObjectType::DESTRUCTIBLE) { } else { } return true; }
bool GameLayer::onContactBegin(PhysicsContact& contact) { auto b_1 = (Sprite*)contact.getShapeA()->getBody()->getNode(); auto b_2 = (Sprite*)contact.getShapeB()->getBody()->getNode(); if (b_1 == ball && b_1->getTag() == 100) { log("FromBall"); BallisTouch = true; } else if(b_2 == ball && b_2->getTag() == 100) { log("FromBall"); BallisTouch = true; }else if (b_1->getPhysicsBody()->getCategoryBitmask()==ColliderTypeBall && b_1->getTag() != 100) { auto randomColor = rand()%4; showStarParticleEffect(randomColor, bird->getPosition(), this); } else if(b_2->getPhysicsBody()->getCategoryBitmask()==ColliderTypeBall && b_2->getTag() != 100) { auto randomColor = rand()%4; showStarParticleEffect(randomColor, bird->getPosition(), this); } else { this->gameOver(); unschedule(schedule_selector(GameLayer::addBallObstacle)); } return true; }
void BrokableWall::contactLogicSeperate( PhysicsContact &contact, ContactLogic *logic ) { PhysicsBody* body1 = contact.getShapeA()->getBody(); PhysicsBody* body2 = contact.getShapeB()->getBody(); if (body1 != nullptr && body2 != nullptr) { if (body1->getTag() == Type_BoxSprite || body2->getTag() == Type_BoxSprite) { Vec2 velocity = body1->getVelocity() + body2->getVelocity(); if (m_bIsCanContact && velocity.getLengthSq() > 10 * 10) { m_durability--; if (m_durability <= 0) { this->removeFromParent(); } else { m_bIsCanContact = false; this->schedule(schedule_selector(BrokableWall::updateContactState), 0.1f); } } } } }
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; }
bool Level_2Scene::onContactBegan(PhysicsContact &contact) { auto nodeEnemy = contact.getShapeA()->getBody()->getNode();//could be enemy or visa veras auto nodeProjectile = contact.getShapeB()->getBody()->getNode();//could be projectile or visa versa nodeEnemy->removeFromParent();//remove the enemy CCLOG("removed"); SimpleAudioEngine::getInstance()->playEffect(DEATH_SOUND_SFX);//enemy dying sound nodeProjectile->removeFromParent();//remove the projectile CCLOG("point added"); score++; __String * tempScore = __String::createWithFormat("%i", score); scoreLabel->setString(tempScore->getCString()); //if score reaches 10 new level or end game scene with transmitions to gameOverscene or new scene if (score == 1) { auto scene = Level_3_Scene::createScene(); Director::getInstance()->replaceScene(TransitionFade::create(TRANSATION_TIME, scene)); } return true; }
bool SoaringLayer::onContactBegin(PhysicsContact& contact) { Node* nodes[2]; nodes[0] = contact.getShapeA()->getBody()->getNode(); nodes[1] = contact.getShapeB()->getBody()->getNode(); if (nodes[0] && nodes[1]) { for (int i = 0; i < 2; i++) { int j = (i + 1) % 2; if (nodes[i]->getTag() == FLYPLANT_TAG) { FlyPlant *flyPlant = dynamic_cast<FlyPlant*>(nodes[i]); if (flyPlant) { flyPlant->onContactBegin(nodes[j]); } } if (nodes[i]->getTag() == OBSTACLE_TAG) { Obstacle *obstacle = dynamic_cast<Obstacle*>(nodes[i]); if (obstacle) { obstacle->onContactBegin(nodes[j]); } } } } return false; }
bool GameController::onContactBegin(PhysicsContact & contact) { if( contact.getShapeA()->getBody()->getNode()->getTag() == contact.getShapeB()->getBody()->getNode()->getTag()) { log("onContactBegin"); if(arrow->getPhysicsBody()) { arrow->getPhysicsBody()->setVelocity(Vec2(0, 0)); board_body->setVelocity(Vec2::ZERO); } //upper_body_layer->removeChild(arrow); //transitioning from tip to no-tip arrow arrow->setVisible(false); noTipArrow->setVisible(true); //angle float angle = arrow->getPhysicsBody()->getRotation(); noTipArrow->setRotation(angle); //position Vec2 point = contact.getContactData()->points[0]; label->setString(std::to_string(point.y)); noTipArrow->setPosition(Vec2(noTipArrow->getPosition().x, point.y - (board_layer->getPosition().y))); return true; } return true; }
bool CognitoWorld::onContactBegan(PhysicsContact &contact) { if(lvlConfigData.at("SetImmortal").asBool()) return false; auto node = contact.getShapeA(); int nodeBitMask = node->getCategoryBitmask(); if(nodeBitMask == PhysicsCategory::Obstacle) { stopGame(false); return true; } node = contact.getShapeB(); nodeBitMask = node->getCategoryBitmask(); if(nodeBitMask == PhysicsCategory::Obstacle) { stopGame(false); return true; } return false; }
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; }
bool 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); _eventDispatcher->dispatchEvent(&contact); } return ret ? contact.resetResult() : false; }
bool Breakout::onConcactBegan(PhysicsContact& contact) { auto nodeA = contact.getShapeA()->getBody()->getNode(); auto nodeB = contact.getShapeB()->getBody()->getNode(); if (nodeA->getTag() == 1 || nodeB->getTag() == 1) { if(time > 0) dead(); } else { //播放碰撞音效 SimpleAudioEngine::getInstance()->playEffect("music/meet_stone.wav"); //陨石爆炸并消失 ParticleSystemQuad* fireWorks; if (nodeA->getTag() != 100) { nodeA->getPhysicsBody()->setName("isContact"); if (nodeA->getTag() == 10) { blood -= 10; fireWorks = ParticleSystemQuad::create("fire1.plist"); } else if (nodeA->getTag() / 10000 == 20) { blood -= 15; fireWorks = ParticleSystemQuad::create("fire2.plist"); } else { blood -= 20; fireWorks = ParticleSystemQuad::create("fire3.plist"); } fireWorks->setPosition(nodeA->getPosition()); this->removeChild(nodeA); } else { nodeB->getPhysicsBody()->setName("isContact"); if (nodeB->getTag() == 10) { blood -= 10; fireWorks = ParticleSystemQuad::create("fire1.plist"); } else if (nodeB->getTag() == 20) { blood -= 15; fireWorks = ParticleSystemQuad::create("fire2.plist"); } else { blood -= 20; fireWorks = ParticleSystemQuad::create("fire3.plist"); } fireWorks->setPosition(nodeB->getPosition()); this->removeChild(nodeB); } this->addChild(fireWorks, 1); for (int i = 0; i < enemys.size(); i++) { if (enemys.at(i)->getName() == "isContact") { enemys.erase(enemys.begin() + i); } } pT->setPercentage(blood); if (blood <= 0) dead(); } return true; }
bool HelloWorld::onContactBegan(PhysicsContact& contact){ auto nodeA = contact.getShapeA()->getBody()->getNode(); auto nodeB = contact.getShapeB()->getBody()->getNode(); nodeA->removeFromParent(); nodeB->removeFromParent(); return true; }
bool hitTest(PhysicsContact& contact, int mask) { PhysicsBody* a = contact.getShapeA()->getBody(); PhysicsBody* b = contact.getShapeB()->getBody(); int tagA = a->getTag(); int tagB = b->getTag(); int tag = tagA | tagB; return (tag & mask) == mask; }
bool PhysicListener::onPhysicContactBegin(PhysicsContact& contact){ auto spriteA = (Sprite*)contact.getShapeA()->getBody()->getNode(); auto spriteB = (Sprite*)contact.getShapeB()->getBody()->getNode(); log("p=============p===%d===%d===",spriteA->getTag(),spriteB->getTag()); if ((spriteA->getTag()==2||spriteA->getTag()==10)&&(spriteB->getTag()==2||spriteB->getTag()==10)) { // Director::getInstance()->replaceScene(MainScene::create()); log("======墙壁撞到Player======"); } return true; };
bool GameScene::dealWithContact(PhysicsContact& contact) { //log("contact begin!"); //获取两个碰撞的节点 auto node1 = contact.getShapeA()->getBody()->getNode(); auto node2 = contact.getShapeB()->getBody()->getNode(); if (!node1 || !node2) return false; auto tag1 = node1->getTag(); auto tag2 = node2->getTag(); //如果碰撞的是子弹和敌方飞机 if ((tag1 == HERO_BULLET_TAG && tag2 == ENEMY_TAG) || (tag2 == HERO_BULLET_TAG && tag1 == ENEMY_TAG)) { PlaneEnemy* enemy = nullptr; if (tag1 == HERO_BULLET_TAG) { node1->removeFromParent(); enemy = ((PlaneEnemy*)node2); } else { node2->removeFromParent(); enemy = ((PlaneEnemy*)node1); } hitEnemy(enemy); } //如果碰撞的是我方战机和敌机 if ((tag1 == HERO_TAG && tag2 == ENEMY_TAG) || (tag2 == HERO_TAG && tag1 == ENEMY_TAG)) { _eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE); //不再接受触摸事件 PlaneHero *hero = nullptr; PlaneEnemy *enemy = nullptr; if (tag1 == HERO_TAG) { hero = ((PlaneHero*)node1); enemy = ((PlaneEnemy*)node2); } else { hero = ((PlaneHero*)node2); enemy = ((PlaneEnemy*)node1); } hitEnemy(enemy); hitHero(hero); } return true; }
bool PlayMapSix::onContactBegin(PhysicsContact &contact) { switch (contact.getShapeA()->getBody()->getContactTestBitmask() | contact.getShapeB()->getBody()->getContactTestBitmask()) { //注意整个解决方法中各类中碰撞处理函数中的 case的值不要相同,同一个的碰撞只能有一个地方在处理 /*case ARROW_BIT_MASK | MONSTER1_BIT_MASK://箭射中怪物 { //dead->removeFromParentAndCleanup(true); MA1->removeFromParentAndCleanup(true); } break;*/ case ARROW_BIT_MASK|CAN_DISPEAR_BIT_MASK: { auto a = contact.getShapeA()->getBody()->getNode(); auto b = contact.getShapeB()->getBody()->getNode(); log("dispear!!!!!!!!!!!!!!!"); if (a != NULL) { long at = a->getTag();// tilemap->removeChildByTag(); if (UserDefault::getInstance()->getBoolForKey(SOUND_KEY)) { SimpleAudioEngine::getInstance()->playEffect(sound_5); } a->removeFromParentAndCleanup(true); log("at %d", at); long bt = b->getTag(); log("bt %d", bt); if (-1 < at < 10001) { do { tilemap->getLayer("collideLayer")->removeChildByTag(at); } while (tilemap->getLayer("collideLayer")->getChildByTag(at)); } } if (b!= NULL) { //long bt = b->getTag();// tilemap->removeChildByTag(); //b->removeFromParentAndCleanup(true); //log("bt %d", bt); //if (-1 < bt < 10001)tilemap->getLayer("pengzhuang")->removeChildByTag(bt); } }break; default: break; } return true; }
Point Blocks::remove(const PhysicsContact &contact, Layer *layer) { float x = 0; float y = 0; if(BLOCKS_BITMASK == contact.getShapeA()->getBody()->getCollisionBitmask()) { x = contact.getShapeA()->getBody()->getPosition().x; y = contact.getShapeA()->getBody()->getPosition().y; contact.getShapeA()->getBody()->removeFromWorld(); layer->removeChild(contact.getShapeA()->getBody()->getNode()); } else { x = contact.getShapeB()->getBody()->getPosition().x; y = contact.getShapeB()->getBody()->getPosition().y; contact.getShapeB()->getBody()->removeFromWorld(); layer->removeChild(contact.getShapeB()->getBody()->getNode()); } return Point(x, y); }
void HelloWorld::onContactSeperate(PhysicsContact& contact){ //接触结束 auto a = contact.getShapeA()->getTag(); auto b = contact.getShapeB()->getTag(); if ((a * b) == PLAYER_TAG * EDGE_TAG){ isContact = false; } else if ((a*b) == PLAYER_TAG * ENEMY_TAG_ZERO){ player1->contactNumber--; } log("onContactSeperate"); }
bool HelloWorld::onContactBegin(const PhysicsContact& contact) { PhysicsBody* a = contact.getShapeA()->getBody(); PhysicsBody* b = contact.getShapeB()->getBody(); this->removeChild(a->getNode()); this->removeChild(b->getNode()); return true; }
bool LevelFifteen::onContactBegin(const PhysicsContact& contact) { // 当碰撞的两个对象,是hero和吐出来的刚体的时候,处理 if (((contact.getShapeA()->getBody()->getCategoryBitmask() & 2) == 2) && ((contact.getShapeB()->getBody()->getCategoryBitmask() & 1) == 1)) { contact.getShapeA()->getBody()->getNode()->removeFromParent(); ++nTimes; test3->setString(String::createWithFormat("%d", nTimes)->getCString()); test3->setScale(2.0f); } if (((contact.getShapeA()->getBody()->getCategoryBitmask() & 1) == 1) && ((contact.getShapeB()->getBody()->getCategoryBitmask() & 2) == 2)) { contact.getShapeB()->getBody()->getNode()->removeFromParent(); ++nTimes; test3->setString(String::createWithFormat("%d", nTimes)->getCString()); test3->setScale(2.0f); } if (((contact.getShapeA()->getBody()->getCategoryBitmask() & 8) == 8) && ((contact.getShapeB()->getBody()->getCategoryBitmask() & 2) == 2)) { contact.getShapeB()->getBody()->getNode()->removeFromParent(); } if (((contact.getShapeA()->getBody()->getCategoryBitmask() & 2) == 2) && ((contact.getShapeB()->getBody()->getCategoryBitmask() & 8) == 8)) { contact.getShapeA()->getBody()->getNode()->removeFromParent(); } return true; }
bool TankContainer::onContactBegin(PhysicsContact& contact) { PhysicsBody* bodyA = contact.getShapeA()->getBody(); PhysicsBody* bodyB = contact.getShapeB()->getBody(); if ((bodyA->getTag() == 1) && (bodyB->getTag() == 1)) //tanks { CCLOG("Contact 2 tanks"); return true; } if ((bodyA->getTag() == 10) && (bodyB->getTag() == 10)) //bullets { CCLOG("Contact 2 bullets"); return true; } if (((bodyA->getTag() == 1) && (bodyB->getTag() == 10)) || ((bodyB->getTag() == 1) && (bodyA->getTag() == 10))) { Tank* tank; BulletAbstract* bullet; if (bodyA->getTag() == 1) { tank = dynamic_cast<Tank*>(bodyA->getNode()); bullet = dynamic_cast<BulletAbstract*>(bodyB->getNode()); } else { tank = dynamic_cast<Tank*>(bodyB->getNode()); bullet = dynamic_cast<BulletAbstract*>(bodyA->getNode()); } if (bullet->getLifeTime() >= 1.97) { ;// return false; } CCLOG("Contact bullets and tank"); if (tank) tank->destroy(); if (bullet) bullet->destroy(); } return true; /* else { bodyA->setVelocity(Vec2(0, 0)); bodyB->setVelocity(Vec2(0, 0)); return true; }*/ }
bool TollgateMapLayer::onContactBegin(PhysicsContact& contact){ auto nodeA = contact.getShapeA()->getBody()->getNode(); auto nodeB = contact.getShapeB()->getBody()->getNode(); if (nodeA && nodeB){ auto tagA = nodeA->getTag(); auto tagB = nodeB->getTag(); if (nodeA->getTag() == BULLET_ONETAG&&nodeB->getTag() == BULLET_ONETAG){ return false; } else if (nodeA->getTag() == BULLET_ONETAG){ auto bullet = (BulletBase*)nodeA; auto monster = (Entity*)nodeB; auto atkValue = bullet->getiAtkValue(); monster->hurtMe(atkValue); nodeA->removeFromParentAndCleanup(true); } else if (nodeB->getTag() == BULLET_ONETAG){ auto bullet = (BulletBase*)nodeB; auto monster = (Entity*)nodeA; auto atkValue = bullet->getiAtkValue(); monster->hurtMe(20*atkValue); nodeB->removeFromParentAndCleanup(true); } else if (nodeA->getTag() == BULLET_SEVERALTAG&&nodeB->getTag() == BULLET_SEVERALTAG){ return false; } else if (nodeA->getTag() == BULLET_SEVERALTAG){ auto bullet = (BulletBase*)nodeA; auto monster = (Entity*)nodeB; auto atkValue = bullet->getiAtkValue(); monster->hurtMe(atkValue); } else if (nodeB->getTag() == BULLET_SEVERALTAG){ auto bullet = (BulletBase*)nodeB; auto monster = (Entity*)nodeA; auto atkValue = bullet->getiAtkValue(); monster->hurtMe(atkValue); } else if (nodeA->getTag() == MONSTERTAG&&nodeB->getTag() == MONSTERBODYTAG){ auto monster = (Entity*)nodeA; monster->setchangebodySpeed(30); } else if (nodeB->getTag() == MONSTERTAG&&nodeA->getTag() == MONSTERBODYTAG){ auto monster = (Entity*)nodeB; monster->setchangebodySpeed(30); } } return true; }
bool Level1::onContactBegin(PhysicsContact& contact) { for (auto shape : { contact.getShapeA(), contact.getShapeB() }) { if (shape->getBody()->getCategoryBitmask() == Enemy::categoryBitmask) { Enemy* enemy = dynamic_cast<Enemy*>(shape->getBody()->getNode()->getParent()); enemy->die(); } } return false;//dont solve collision }