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 StarMatrix::clearMatrixOneByOne() { for(int i=0; i<ROW_NUM; i++) { for(int j=0; j<COL_NUM; j++) { if(stars[i][j] == nullptr) continue; showStarParticleEffect(stars[i][j]->getColor(),stars[i][j]->getPosition(),this); stars[i][j]->removeFromParentAndCleanup(true); stars[i][j] = nullptr; return; } } needClear = false; if(GAMEDATA::getInstance()->getCurScore() >= GAMEDATA::getInstance()->getNextScore()) { GAMEDATA::getInstance()->setCurLevel(GAMEDATA::getInstance()->getCurLevel() + 1); m_layer->gotoNextLevel(); } else { m_layer->gotoGameOver(); CCLOG("GAME OVER"); } }
void StarMatrix::deleteSelectedList() { if(selectedList.size() <= 1) { m_layer->hideLinkNum(); selectedList.at(0)->setSelected(false); return; } for(auto it = selectedList.begin();it != selectedList.end();it++) { Star* star = *it; showStarParticleEffect(star->getColor(),star->getPosition(),this); stars[star->getIndexI()][star->getIndexJ()] = nullptr; star->removeFromParentAndCleanup(true); Audio::getInstance()->playPop(); } showComboEffect(selectedList.size(),this); Audio::getInstance()->playCombo(selectedList.size()); refreshScore(); m_layer->showLinkNum(selectedList.size()); adjustMatrix(); if(isEnded()) { m_layer->floatLeftStarMsg(getLeftStarNum()); CCLOG("ENDED"); } }
void StarMatrix::deleteSelectedList(){ //播放消除音效 Audio::getInstance()->playPop(); for(auto it = selectedList.begin();it != selectedList.end();it++){ Star* star = *it; m_layer->showEveryScore(selectedListSize,5+(selectedListSize-selectedList.size())*5,selectedListSize-selectedList.size(),star->getPosition(),touchLeft); selectedList.pop_front(); //粒子效果 showStarParticleEffect(star->getColor(),star->getPosition(),this); stars[star->getIndexI()][star->getIndexJ()] = nullptr; star->removeFromParentAndCleanup(true); return; } clearOneByOne =false; //COMBO效果 showComboEffect(selectedListSize,this); m_layer->showLinkNum(selectedListSize); selectedListSize=0; acceptTouch =true; adjustMatrix(); if(isEnded()){ acceptTouch=false; m_layer->hideProps(); m_layer->floatLeftStarMsg(getLeftStarNum());//通知layer弹出剩余星星的信息 CCLOG("ENDED"); } }
void StarMatrix::deleteBombList(){ //播放消除音效 Audio::getInstance()->playPropBomb(); for(auto it = selectedList.begin();it != selectedList.end();it++){ Star* star = *it; //粒子效果 showStarParticleEffect(star->getColor(),star->getPosition(),this); stars[star->getIndexI()][star->getIndexJ()] = nullptr; star->removeFromParentAndCleanup(true); } selectedList.clear(); //COMBO效果 selectedListSize=0; acceptTouch =true; adjustMatrix(); if(isEnded()){ acceptTouch=false; m_layer->hideProps(); m_layer->floatLeftStarMsg(getLeftStarNum()); } }
void StarMatrix::doHammer(Star* s){ selectedList.clear(); selectedList.push_back(s); //播放消除音效 Audio::getInstance()->playPropBomb(); selectedList.pop_front(); m_layer->showEveryScore(selectedListSize,5+(selectedListSize-selectedList.size())*5,selectedListSize-selectedList.size(),s->getPosition(),touchLeft); //粒子效果 showStarParticleEffect(s->getColor(),s->getPosition(),this); stars[s->getIndexI()][s->getIndexJ()] = nullptr; s->removeFromParentAndCleanup(true); m_layer->showLinkNum(selectedListSize); selectedListSize=0; acceptTouch =true; adjustMatrix(); if(isEnded()){ acceptTouch=false; m_layer->hideProps(); m_layer->floatLeftStarMsg(getLeftStarNum());//通知layer弹出剩余星星的信息 CCLOG("ENDED"); } }