首页 > 系统 > Android > 正文

Android实现消水果游戏代码分享

2019-10-23 20:01:22
字体:
来源:转载
供稿:网友

消水果游戏大家都玩过吧,今天小编给大家分享实现消水果游戏的代码,废话不多说了,具体代码如下所示:

 

  1.  #include "InGameScene.h" 
  2. #include "PauseLayer.h" 
  3. #include "ScoreScene.h" 
  4. #include "AppDelegate.h" 
  5. extern "C" 
  6.   void showAds() 
  7.   { 
  8.   } 
  9.   void hideAds() 
  10.   { 
  11.   } 
  12. using namespace cocos2d; 
  13. using namespace CocosDenshion; 
  14. bool InGameScene::isPaused = false
  15. unsigned int InGameScene::level = 1; 
  16. unsigned int InGameScene::background = 1; 
  17. unsigned int InGameScene::bomb = 2; 
  18. const unsigned int InGameScene::randomDrop[8] = {0, 5, 2, 7, 1, 4, 3, 6}; 
  19. const char *InGameScene::strMode[3] = {"Simple""Normal""Expert"}; 
  20. const unsigned int InGameScene::limitTime[3] = {60, 60, 60}; 
  21. const unsigned int InGameScene::baseScore[3] = {20, 50, 100}; 
  22. const unsigned int InGameScene::limitScore[3] = {6000, 10000, 12000}; 
  23. const unsigned int InGameScene::limitFireball[3] = {100, 70, 30}; 
  24. const unsigned int InGameScene::limitCrazy[3] = {8, 10, 6}; 
  25. void InGameScene::reset() 
  26.   InGameScene::isPaused = false
  27. InGameScene::InGameScene() 
  28.   : m_nDiamondScale(1.0f) 
  29.   , m_nMagicCount(0) 
  30.   , m_pMagicProgress(NULL) 
  31.   , m_nTime(0) 
  32.   , m_nScore(0) 
  33.   , m_nTempScore(0) 
  34.   , m_nDiamondRow(0) 
  35.   , m_nDiamondLine(0) 
  36.   , m_bIsReadyGoEnd(false
  37.   , m_pPause(NULL) 
  38.   , m_pDiamondBatchNode(NULL) 
  39.   , m_pRemovedDiamond(NULL) 
  40.   , m_pScoreLable(NULL) 
  41.   , m_pTimerBar(NULL) 
  42.   , m_pMoveLable(NULL) 
  43.   , m_pTargetLable(NULL) 
  44.   , m_bFireballMode(false
  45.   , m_bError(false
  46.   , m_nTimeCount(0) 
  47.   , m_nCrazyCount(0) 
  48.   , m_bIsCrazyMode(false
  49.   , m_nDiamondCount(0) 
  50.   , m_pEffectDict(NULL) 
  51.   , m_startType(-1) 
  52.   , m_moveStatus(-1) 
  53.   , moves_number_(0) 
  54. InGameScene::~InGameScene() 
  55.   CC_SAFE_RELEASE_NULL(m_pPause); 
  56.   CC_SAFE_RELEASE_NULL(m_pMagicProgress); 
  57.   CC_SAFE_RELEASE_NULL(m_pMoveLable); 
  58.   CC_SAFE_RELEASE_NULL(m_pTargetLable); 
  59.   CC_SAFE_RELEASE_NULL(m_pTimerBar); 
  60.   CC_SAFE_RELEASE_NULL(m_pScoreLable); 
  61.   CC_SAFE_RELEASE_NULL(m_pDiamondBatchNode); 
  62.   CC_SAFE_RELEASE_NULL(m_pRemovedDiamond); 
  63.   CC_SAFE_RELEASE_NULL(m_pEffectDict); 
  64. void InGameScene::onEnter() 
  65.   Image::setPVRImagesHavePremultipliedAlpha(true); 
  66.   this->setTouchEnabled(true); 
  67.   Layer::onEnter(); 
  68. void InGameScene::onExit() 
  69.   Layer::onExit(); 
  70. Scene *InGameScene::scene() 
  71.   Scene *scene = NULL; 
  72.   do 
  73.   { 
  74.     scene = Scene::create(); 
  75.     CC_BREAK_IF(! scene); 
  76.     InGameScene *layer = InGameScene::create(); 
  77.     CC_BREAK_IF(! layer); 
  78.     scene->addChild(layer); 
  79.   } 
  80.   while (0); 
  81.   return scene; 
  82. bool InGameScene::init() 
  83.   bool bRet = false
  84.   do 
  85.   { 
  86.     CC_BREAK_IF(! Layer::init()); 
  87.     auto listener = EventListenerTouchOneByOne::create(); 
  88.     listener->setSwallowTouches(false); 
  89.     listener->onTouchBegan = CC_CALLBACK_2(InGameScene::onTouchBegan, this); 
  90.     listener->onTouchEnded = CC_CALLBACK_2(InGameScene::onTouchEnded, this); 
  91.     listener->onTouchMoved = CC_CALLBACK_2(InGameScene::onTouchMoved, this); 
  92.     _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); 
  93.     hideAds(); 
  94.     InGameScene::isPaused = false
  95.     m_nDiamondRowMax = 8; 
  96.     m_nDiamondLineMax = 9; 
  97.     m_nDiamondScale = 1.12f; 
  98.     InGameScene::level = UserDefault::getInstance()->getIntegerForKey("level"); 
  99.     m_nDiamondCount = InGameScene::level + 3; 
  100.     if (m_nDiamondCount < 3 || m_nDiamondCount > 5) 
  101.     { 
  102.       break
  103.     } 
  104.     m_nTime = InGameScene::limitTime[InGameScene::level]; 
  105.     m_nTime = 1200; 
  106.     Size winSize = Director::getInstance()->getWinSize(); 
  107.     auto sp = Sprite::create("gui/df.png"); 
  108.     addChild(sp, -3); 
  109.     sp->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); 
  110.     auto sp_top = Sprite::create("gui/top_bar.png"); 
  111.     addChild(sp_top, 3); 
  112.     sp_top->setPosition(Vec2(winSize.width / 2, 1280 - 97)); 
  113.     m_pRemovedDiamond = __Array::create(); 
  114.     m_pRemovedDiamond->retain(); 
  115.     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("effects/effects-800x_port_mdpi.plist"); 
  116.     m_pScoreLable = Label::createWithCharMap("gui/white_font.png", 25, 29, '0'); 
  117.     m_pScoreLable->retain(); 
  118.     m_pScoreLable->setString("0"); 
  119.     m_pScoreLable->setPosition(Vec2(583, 1280-55)); 
  120.     this->addChild(m_pScoreLable, 100); 
  121.     m_pMoveLable = Label::createWithCharMap("gui/white_font.png", 25, 29, '0'); 
  122.     m_pMoveLable->retain(); 
  123.     m_pMoveLable->setPosition(Vec2(583, 1280-140)); 
  124.     m_pMoveLable->setString("50"); 
  125.     addChild(m_pMoveLable,100); 
  126.     m_pTargetLable = Label::createWithCharMap("gui/white_font.png", 25, 29, '0'); 
  127.     m_pTargetLable->retain(); 
  128.     m_pTargetLable->setPosition(Vec2(116, 1280-58)); 
  129.     m_pTargetLable->setString("1000"); 
  130.     addChild(m_pTargetLable,100); 
  131.     //创建暂停按钮 
  132.     auto *pPauseItem = MenuItemImage::create("gui/game_stop.png""gui/game_stop.png"this, menu_selector(InGameScene::menuPauseCallback)); 
  133.     pPauseItem->setPosition(Vec2(46, 1280-142)); 
  134.     Menu *pMenu = Menu::create(pPauseItem, NULL); 
  135.     CC_BREAK_IF(! pMenu); 
  136.     pMenu->setPosition(Vec2::ZERO); 
  137.     this->addChild(pMenu, 200); 
  138.  
  139.     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gems/gemTexture-800x_port_mdpi.plist"); 
  140.     m_pDiamondBatchNode = SpriteBatchNode::create("gems/gemTexture-800x_port_mdpi.png"); 
  141.     m_pDiamondBatchNode->retain(); 
  142.     this->addChild(m_pDiamondBatchNode); 
  143.     this->playReadyGo(); 
  144.     this->addFirstDiamond(); 
  145.     this->scheduleUpdate(); 
  146.     m_pEffectDict = __Dictionary::create(); 
  147.     m_pEffectDict->retain(); 
  148.     drawBg(); 
  149.     bRet = true
  150.   } 
  151.   while (0); 
  152.   return bRet; 
  153. void InGameScene::playReadyGo() 
  154.   if (UserDefault::getInstance()->getBoolForKey("isEffectEnabled"false)) 
  155.   { 
  156.     SimpleAudioEngine()->playEffect("sounds/readyGo.ogg"); 
  157.   } 
  158.   LabelTTF *readyGo = LabelTTF::create("Ready""fonts/Verdana Bold.ttf", 60.0f); 
  159.   readyGo->setPosition(Vec2(400, 750)); 
  160.   this->addChild(readyGo); 
  161.   readyGo->setScale(0.1f); 
  162.   readyGo->runAction(Sequence::create( 
  163.               CCScaleTo::create(1.1f, 1.0f), 
  164.               DelayTime::create(.3f), 
  165.               CallFuncN::create(this, callfuncN_selector(InGameScene::readyCallback)), 
  166.               NULL)); 
  167. void InGameScene::readyCallback(Node *pSender) 
  168.   LabelTTF *p = (LabelTTF *)pSender; 
  169.   p->setFontSize(65.f); 
  170.   p->setString("Go!!!"); 
  171.   p->runAction(Sequence::create( 
  172.            DelayTime::create(.7f), 
  173.            CallFuncN::create(this, callfuncN_selector(InGameScene::goCallback)), 
  174.            NULL)); 
  175. void InGameScene::goCallback(Node *pSender) 
  176.   this->removeChild(pSender); 
  177. void InGameScene::addFirstDiamond() 
  178.   SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gems/gemTexture-800x_port_mdpi.plist"); 
  179.   this->schedule(schedule_selector(InGameScene::addDiamond), 1.2f / (m_nDiamondRowMax * m_nDiamondLineMax)); 
  180. Vec2 InGameScene::getPositionByRowAndLine(int row, int line) 
  181.   float x = CELL_WIDTH * row + OFFSET_X; 
  182.   float y = CELL_HEIGHT * line + OFFSET_Y; 
  183.   return Vec2(x, y); 
  184. void InGameScene::addDiamond(float delta) 
  185.   int diamondType = rand() % 5; 
  186.   Diamond *pDiamond = Diamond::createWithSpriteFrameName(Diamond::TypeStr[diamondType]); 
  187.   pDiamond->setType(diamondType); 
  188.   pDiamond->setPosition(Vec2(CELL_WIDTH * randomDrop[m_nDiamondRow] + 50, 1280 + CELL_HEIGHT)); 
  189.   pDiamond->setScale(0.9); 
  190.   m_pDiamondBatchNode->addChild(pDiamond); 
  191.   pDiamond->setMoving(true); 
  192.   pDiamond->runAction(Sequence::create( 
  193.               MoveTo::create(.25f, Vec2(CELL_WIDTH * randomDrop[m_nDiamondRow] + OFFSET_X, CELL_HEIGHT * m_nDiamondLine + OFFSET_Y)), 
  194.               CallFuncN::create(this, callfuncN_selector(InGameScene::addEndCallback)), 
  195.               NULL)); 
  196.   m_pDiamond[m_nDiamondLine][randomDrop[m_nDiamondRow]] = pDiamond; 
  197.   if (++m_nDiamondRow == m_nDiamondRowMax) 
  198.   { 
  199.     m_nDiamondRow = 0; 
  200.     ++m_nDiamondLine; 
  201.   } 
  202.   if (m_nDiamondLine == m_nDiamondLineMax) 
  203.   { 
  204.     m_bIsReadyGoEnd = true//首次播放宝石掉落动画结束 
  205.     this->unschedule(schedule_selector(InGameScene::addDiamond)); //宝石添加动画结束 
  206.     if (! InGameScene::isPaused) 
  207.     { 
  208. //      m_pTimerBar->runAction(MoveTo::create(float(InGameScene::limitTime[InGameScene::level]), Vec2(-380, 95))); 
  209. //      this->schedule(schedule_selector(InGameScene::updateTime), 1.0f); //开始计时 
  210.     } 
  211.   } 
  212. void InGameScene::drawBg() 
  213.   for(auto line = 0; line < m_nDiamondLineMax; line++) 
  214.   { 
  215.     for(auto row = 0; row < 7; row++) 
  216.     { 
  217.       auto sp1 = Sprite::create("gui/b1.png"); 
  218.       auto sp2 = Sprite::create("gui/b2.png"); 
  219.       if(line%2 == 0) 
  220.       { 
  221.         if(row%2 == 0) 
  222.         { 
  223.           sp1->setPosition(getPositionByRowAndLine(row, line)); 
  224.           sp2->setVisible(false); 
  225.         } 
  226.         else 
  227.         { 
  228.           sp2->setPosition(getPositionByRowAndLine(row, line)); 
  229.           sp1->setVisible(false); 
  230.         } 
  231.       } 
  232.       else 
  233.       { 
  234.         if(row%2 == 0) 
  235.         { 
  236.           sp2->setPosition(getPositionByRowAndLine(row, line)); 
  237.           sp1->setVisible(false); 
  238.         } 
  239.         else 
  240.         { 
  241.           sp1->setPosition(getPositionByRowAndLine(row, line)); 
  242.           sp2->setVisible(false); 
  243.         } 
  244.       } 
  245.       addChild(sp1, BG_ODER); 
  246.       addChild(sp2, BG_ODER); 
  247.     } 
  248.   } 
  249. #define PAN 0.000001 
  250. void InGameScene::DrawLine() 
  251.   auto line = Sprite::create("gui/line.png"); 
  252.   line->setPosition(last_position); 
  253.   line->setAnchorPoint(Vec2(1, 0.5)); 
  254.   addChild(line, -1); 
  255.   m_lineObjs.push_back(line); 
  256.   if (fabs(last_position.x - cur_position.x) < PAN) { 
  257.     if (last_position.y - cur_position.y > 1.0f) 
  258.     { 
  259.       // 向下 
  260.       line->setRotation(270); 
  261.     } 
  262.     else 
  263.     { 
  264.       line->setRotation(90); 
  265.     } 
  266.   } 
  267.   else if(fabs(last_position.y - cur_position.y) < PAN) 
  268.   { 
  269.     if (last_position.x - cur_position.x < 1.0f) { 
  270.       line->setRotation(180); 
  271.     } 
  272.   } 
  273.   else 
  274.   { 
  275.     if (last_position.x - cur_position.x < 1.0f) 
  276.     { 
  277.       if (last_position.y - cur_position.y < 1.0f) 
  278.       { 
  279.         line->setRotation(135); 
  280.       } 
  281.       else 
  282.       { 
  283.         line->setRotation(225); 
  284.       } 
  285.     } 
  286.     else 
  287.     { 
  288.       if (last_position.y - cur_position.y < 1.0f) 
  289.       { 
  290.         line->setRotation(45); 
  291.       } 
  292.       else 
  293.       { 
  294.         line->setRotation(315); 
  295.       } 
  296.     } 
  297.   } 
  298. bool InGameScene::isNearby(int line, int row, int _type) 
  299.   if (line > 0 && m_pDiamond[line-1][row]->getType() == _type) 
  300.   { 
  301.     return true
  302.   } 
  303.   if (line < m_nDiamondLineMax -1 && m_pDiamond[line+1][row]->getType() == _type) 
  304.   { 
  305.     return true
  306.   } 
  307.   if (row > 0 && m_pDiamond[line][row-1]->getType() == _type) 
  308.   { 
  309.     return true
  310.   } 
  311.   if (row < m_nDiamondRowMax - 1&& m_pDiamond[line][row+1]->getType() == _type) 
  312.   { 
  313.     return true
  314.   } 
  315.   if (line >0 && row > 3 && m_pDiamond[line-1][row-4]->getType() == _type) 
  316.   { 
  317.     return true
  318.   } 
  319.   if (line > 0&& row > 1 && m_pDiamond[line-1][row-2]->getType() == _type) 
  320.   { 
  321.     return true
  322.   } 
  323.   if (line < m_nDiamondLineMax && row < m_nDiamondRowMax - 2 && m_pDiamond[line+1][row+2]->getType() == _type) 
  324.   { 
  325.     return true
  326.   } 
  327.   if (line < m_nDiamondLineMax && row < m_nDiamondRowMax - 4 && m_pDiamond[line+1][row+4]->getType() == _type) 
  328.   { 
  329.     return true
  330.   } 
  331.   return false
  332. void InGameScene::onTouchMoved(Touch *pTouch, Event *pEvent) 
  333.   if (m_moveStatus==0) 
  334.   { 
  335.     return
  336.   } 
  337.   if(m_startType != -1) 
  338.   { 
  339.     return
  340.   } 
  341.   log("c"); 
  342.   Vec2 location = pTouch->getLocationInView(); 
  343.   location = Director::getInstance()->convertToGL(location); 
  344.   for (int line = 0; line < m_nDiamondLineMax; ++line) 
  345.   { 
  346.     for (int row = 0; row < m_nDiamondRowMax; ++row) 
  347.     { 
  348.       if(!m_pDiamond[line][row]) 
  349.       { 
  350.         continue
  351.       } 
  352.       if ((m_pDiamond[line][row])->boundingBox().containsPoint(location)) 
  353.       { 
  354.         // 还在原来的格子里 
  355.         if (m_pRemovedDiamond->containsObject(m_pDiamond[line][row])) 
  356.         { 
  357.           return
  358.         } 
  359.         ssize_t count = m_pRemovedDiamond->count(); 
  360.         if(count > 0) 
  361.         { 
  362.           // 颜色不是一样的 
  363.           if (m_pDiamond[line][row]->getType() != m_startType) 
  364.           { 
  365.             log("-- line end -- line(%d),row(%d)",line,row); 
  366.             m_moveStatus = 0; 
  367.             return
  368.           } 
  369. //          if (!isNearby(line, row, m_startType)) 
  370. //          { 
  371. //            
  372. //            return; 
  373. //          } 
  374.           cur_position = getPositionByRowAndLine(row, line); 
  375.           DrawLine(); 
  376.           last_position = cur_position; 
  377.           m_pDiamond[line][row]->setScale(1.05); 
  378.         } 
  379.         else 
  380.         { 
  381.         } 
  382.         // 将自己加入到队列中去 
  383.         m_pDiamond[line][row]->setTag(line * m_nDiamondRowMax + row); 
  384.         m_pRemovedDiamond->addObject(m_pDiamond[line][row]); 
  385.       } 
  386.     } 
  387.   } 
  388.   log("c-end"); 
  389. bool InGameScene::onTouchBegan(Touch *pTouch, Event *pEvent) 
  390.   if (! m_bIsReadyGoEnd) 
  391.   { 
  392.     return true
  393.   } 
  394.   if(m_startType != -1) 
  395.   { 
  396.     return true
  397.   } 
  398.   log("a"); 
  399.   m_lineObjs.clear(); 
  400.   m_pRemovedDiamond->removeAllObjects(); 
  401.   m_moveStatus = -1; 
  402.   Vec2 location = pTouch->getLocationInView(); 
  403.   location = Director::getInstance()->convertToGL(location); 
  404.   log("b"); 
  405.   for (int line = 0; line < m_nDiamondLineMax; ++line) 
  406.   { 
  407.     for (int row = 0; row < m_nDiamondRowMax; ++row) 
  408.     { 
  409.       if (m_pDiamond[line][row] && (! m_pDiamond[line][row]->getMoving())) 
  410.       { 
  411.         if ((m_pDiamond[line][row])->boundingBox().containsPoint(location)) 
  412.         { 
  413.           m_startType = m_pDiamond[line][row]->getType(); 
  414.           last_position = getPositionByRowAndLine(row, line); 
  415.           log("m_starType %d",m_startType); 
  416.           return true
  417.         } 
  418.       } 
  419.     } 
  420.   } 
  421.   log("a-end"); 
  422.   return true
  423. void InGameScene::onTouchEnded(Touch *pTouch, Event *pEvent) 
  424.   m_moveStatus = -1; 
  425.   m_startType = -1; 
  426.   log("d"); 
  427.   if(!handleSelectedDiamond()) 
  428.   { 
  429.     log("sdf"); 
  430.     return
  431.   } 
  432.   for(auto sp : m_lineObjs) 
  433.   { 
  434.     sp->removeFromParent(); 
  435.   } 
  436.   m_lineObjs.clear(); 
  437.   removeSelectedDiamond(); 
  438.   schedule(schedule_selector(InGameScene::addRemovedDiamond), 1/40); 
  439.   restoreOriginalDiamond(); 
  440.   log("d--end"); 
  441. void InGameScene::findSameDiamond(int type) 
  442.   m_pRemovedDiamond->removeAllObjects(); 
  443.   for (int line = 0; line < m_nDiamondLineMax; ++line) 
  444.   { 
  445.     for (int row = 0; row < m_nDiamondRowMax; ++row) 
  446.     { 
  447.       Diamond *diamond = m_pDiamond[line][row]; 
  448.       if (diamond && (! diamond->getMoving())) 
  449.       { 
  450.         if (diamond->getType() == type) 
  451.         { 
  452.           if (! m_pRemovedDiamond->containsObject(diamond)) 
  453.           { 
  454.             diamond->setTag(line * m_nDiamondRowMax + row); //用tag记录下可能被删除的宝石的位置 
  455.             m_pRemovedDiamond->addObject(diamond); 
  456.           } 
  457.         } 
  458.       } 
  459.     } 
  460.   } 
  461. //如果点击的宝石少于3个,则返回false,等于或多于3个则返回true 
  462. bool InGameScene::handleSelectedDiamond() 
  463.   auto count = m_pRemovedDiamond->count(); 
  464.   if (count < 2) 
  465.   { 
  466.     m_nCrazyCount = 0; 
  467.     if (m_bIsCrazyMode) 
  468.     { 
  469.       m_bIsCrazyMode = false
  470.       this->removeFireModeFlame(); 
  471.     } 
  472.     return false
  473.   } 
  474.   playJumpScore(count); 
  475.   return true
  476. //-------------播放连击动画---------------// 
  477. void InGameScene::playCombAnimation(unsigned int combCount) 
  478.   LabelTTF *comb = LabelTTF::create(__String::createWithFormat("Combo %d+", combCount)->getCString(), "fonts/Verdana Bold.ttf", 60.0f); 
  479.   comb->setPosition(Vec2(400, 750)); 
  480.   comb->setColor(ccc3(0, 255, 255)); 
  481.   this->addChild(comb); 
  482.   comb->setScale(0.1f); 
  483.   comb->runAction(Sequence::create( 
  484.             CCScaleTo::create(.5f, 1.0f), 
  485.             DelayTime::create(.2f), 
  486.             CallFuncN::create(this, callfuncN_selector(InGameScene::removeCombCallback)), 
  487.             NULL)); 
  488. void InGameScene::removeCombCallback(Node *pSender) 
  489.   this->removeChild(pSender); 
  490. //-------------播放连击动画-END--------------// 
  491. void InGameScene::update(float delta) 
  492.   ++m_nTimeCount; // 计数,大概60次是一秒的时间 
  493.   if (m_nTimeCount > 75) //未在限定时间内完成连击,连击失败 
  494.   { 
  495.     if (m_bIsCrazyMode) 
  496.     { 
  497.       m_bIsCrazyMode = false
  498.       this->removeFireModeFlame(); 
  499.     } 
  500.   } 
  501. //  if (m_nCrazyCount > InGameScene::limitCrazy[InGameScene::level]) 
  502. //  { 
  503. //    m_bIsCrazyMode = true; 
  504. //    m_nTimeCount = .0f; 
  505. //    m_nCrazyCount = 0; 
  506. //    this->playFireModeFlame(); 
  507. //  } 
  508. void InGameScene::displayErrorDiamond() 
  509.   m_bError = true
  510.   Diamond *removed = NULL; 
  511.   Ref *pObj = NULL; 
  512.   CCARRAY_FOREACH(m_pRemovedDiamond, pObj) 
  513.   { 
  514.     removed = (Diamond *)pObj; 
  515.     CC_BREAK_IF(! removed); 
  516.     removed->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName( 
  517.                    Diamond::TypeBwStr[removed->getType()])); 
  518.   } 
  519. void InGameScene::restoreOriginalDiamond() 
  520.   if (m_bError) 
  521.   { 
  522.     m_bError = false
  523.     Diamond *removed = NULL; 
  524.     Ref *pObj = NULL; 
  525.     CCARRAY_FOREACH(m_pRemovedDiamond, pObj) 
  526.     { 
  527.       removed = (Diamond *)pObj; 
  528.       CC_BREAK_IF(! removed); 
  529.       removed->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName( 
  530.                      Diamond::TypeStr[removed->getType()])); 
  531.     } 
  532.   } 
  533. //启动分数跳动增加的动画 
  534. void InGameScene::playJumpScore(int count) 
  535.   m_nTempScore = InGameScene::baseScore[InGameScene::level] * count + 2 * (count - 3); //2*(count-3)宝石超过3个的奖励分 
  536.   m_nScore += m_nTempScore; 
  537.   this->schedule(schedule_selector(InGameScene::playJumpScoreUpdate), 0.4f / 60); 
  538. //分数跳动增加的动画 
  539. void InGameScene::playJumpScoreUpdate(float delta) 
  540.   if (m_nTempScore < 0) 
  541.   { 
  542.     __String *strScore = __String::createWithFormat("%d", m_nScore); 
  543.     m_pScoreLable->setString(strScore->getCString()); 
  544.     this->unschedule(schedule_selector(InGameScene::playJumpScoreUpdate)); 
  545.     return
  546.   } 
  547.   __String *strScore = __String::createWithFormat("%d", m_nScore - m_nTempScore); 
  548.   m_pScoreLable->setString(strScore->getCString()); 
  549.   m_nTempScore -= InGameScene::baseScore[InGameScene::level] / 5; 
  550. //播放删除宝石时的动画 
  551. void InGameScene::playDiamondExplosion(const Vec2 pos) 
  552.   Vector<SpriteFrame * > diamondExplosionNormalFrame; 
  553.   for (int i = 1; i < 10; ++i) 
  554.   { 
  555.     SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(__String::createWithFormat("gem_explosion_normal%d.png", i)->getCString()); 
  556.     diamondExplosionNormalFrame.pushBack(frame); 
  557.   } 
  558.   Animation *diamondAnimation = Animation::createWithSpriteFrames(diamondExplosionNormalFrame, 0.05f); 
  559.   Sprite *explosion = Sprite::createWithSpriteFrameName("gem_explosion_normal1.png"); 
  560.   explosion->setPosition(pos); 
  561.   this->addChild(explosion); 
  562.   //播放完消失时的动画 
  563.   explosion->runAction(Sequence::create( 
  564.                Animate::create(diamondAnimation), 
  565.                //播放完消失时的动画后,删除它 
  566.                CallFuncN::create(this, callfuncN_selector(InGameScene::removeExplosionCallback)), 
  567.                NULL)); 
  568. //删除宝石消失时的动画 
  569. void InGameScene::removeExplosionCallback(Node *pSender) 
  570.   this->removeChild(pSender, true); 
  571. //--------------点击宝石后的查询、移除、填充等处理--START-------------// 
  572. void InGameScene::findSelectedDiamond(int line, int row) 
  573.   m_pRemovedDiamond->removeAllObjects(); 
  574.   // 递归查询相邻颜色相同的宝石 
  575.   findSelectedDiamond(line, row, m_pDiamond[line][row]->getType()); 
  576. //递归查出所有颜色一样且紧挨一起的宝石,并记录在m_pRemovedDiamond中 
  577. void InGameScene::findSelectedDiamond(int line, int row, int type) 
  578.   if (line < 0 || line == m_nDiamondLineMax || row < 0 || row == m_nDiamondRowMax) 
  579.   { 
  580.     return
  581.   } 
  582.   Diamond *diamond = m_pDiamond[line][row]; 
  583.   if (diamond && (! diamond->getMoving())) 
  584.   { 
  585.     if (diamond->getType() == type) 
  586.     { 
  587.       if (! m_pRemovedDiamond->containsObject(diamond)) 
  588.       { 
  589.         diamond->setTag(line * m_nDiamondRowMax + row); //用tag记录下可能被删除的宝石的位置 
  590.         m_pRemovedDiamond->addObject(diamond); 
  591.         findSelectedDiamond(line, row - 1, type); //递归左侧 
  592.         findSelectedDiamond(line, row + 1, type); //递归右侧 
  593.         findSelectedDiamond(line + 1, row, type); //递归上侧 
  594.         findSelectedDiamond(line - 1, row, type); //递归下侧 
  595.       } 
  596.     } 
  597.   } 
  598. void InGameScene::removeSelectedDiamond() 
  599.   Diamond *removed = NULL; 
  600.   Ref *pObj = NULL; 
  601.   CCARRAY_FOREACH(m_pRemovedDiamond, pObj) 
  602.   { 
  603.     removed = (Diamond *)pObj; 
  604.     if (removed == NULL) 
  605.     { 
  606.       continue
  607.     } 
  608.     this->playDiamondExplosion(removed->getPosition()); 
  609.     int tag = removed->getTag(); 
  610.     int line = tag / m_nDiamondRowMax, row = tag % m_nDiamondRowMax; 
  611.     m_pDiamondBatchNode->removeChild(removed, true); 
  612.     m_pDiamond[line][row] = NULL; 
  613.   } 
  614. //补齐被删掉的宝石 
  615. void InGameScene::addRemovedDiamond(float delta) 
  616.   int toLine, toRow; 
  617.   for (toLine = 0; toLine < m_nDiamondLineMax; ++toLine) 
  618.   { 
  619.     for (toRow = 0; toRow < m_nDiamondRowMax; ++toRow) 
  620.     { 
  621.       if (m_pDiamond[toLine][toRow] == NULL) //被删除掉的宝石的位置,即要掉落的目的地 
  622.       { 
  623.         int fromLine; 
  624.         for (fromLine = toLine + 1; fromLine < m_nDiamondLineMax; ++fromLine) 
  625.         { 
  626.           //被删除宝石的上方第一个存在,并处于固定状态,即没有在移动中的宝石 
  627.           if (m_pDiamond[fromLine][toRow]) 
  628.           { 
  629.             //播放宝石被添加时掉落的效果 
  630.             if (m_pDiamond[fromLine][toRow]->getMoving()) 
  631.             { 
  632.               m_pDiamond[fromLine][toRow]->stopAllActions(); 
  633.             } 
  634.             m_pDiamond[fromLine][toRow]->setMoving(true); 
  635.             m_pDiamond[fromLine][toRow]->runAction(Sequence::create( 
  636.                 MoveTo::create(0.25f, Vec2(100 * toRow + 50, 100 * toLine + 220)), 
  637.                 CallFuncN::create(this, callfuncN_selector(InGameScene::addEndCallback)), 
  638.                 NULL)); 
  639.             m_pDiamond[toLine][toRow] = m_pDiamond[fromLine][toRow]; 
  640.             m_pDiamond[fromLine][toRow] = NULL; 
  641.             return
  642.           } 
  643.         } 
  644.         if (fromLine == m_nDiamondLineMax) 
  645.         { 
  646.           int diamondType = rand() % 5; 
  647.           Diamond *pDiamond = Diamond::createWithSpriteFrameName(Diamond::TypeStr[diamondType]); 
  648.           pDiamond->setType(diamondType); 
  649.           pDiamond->setScale(0.9 ); //宝石放大,减少宝石间的间隙,才会彼此紧挨着 
  650.           pDiamond->setPosition(Vec2(100 * toRow + 50, 1280 + 100)); 
  651.           m_pDiamondBatchNode->addChild(pDiamond, 2); 
  652.           //播放宝石被添加时掉落的效果 
  653.           pDiamond->setMoving(true); 
  654.           pDiamond->runAction(Sequence::create( 
  655.                       MoveTo::create(.25f, Vec2(100 * toRow + 50, 100 * toLine + 220)), 
  656.                       CallFuncN::create(this, callfuncN_selector(InGameScene::addEndCallback)), 
  657.                       NULL)); 
  658.           //记录每个宝石的指针 
  659.           m_pDiamond[toLine][toRow] = pDiamond; 
  660.         } 
  661.         return
  662.       } 
  663.     } 
  664.   } 
  665.   if ((toLine == m_nDiamondLineMax) && (toRow == m_nDiamondRowMax)) 
  666.   { 
  667.     this->unschedule(schedule_selector(InGameScene::addRemovedDiamond)); 
  668.     m_moveStatus = -1; 
  669.     if (m_bFireballMode) 
  670.     { 
  671.       m_bFireballMode = false
  672.     } 
  673.   } 
  674. //宝石添加时滑动效果结束时,即宝石达到目的地时,计数减一,全部到达目的地时计数为零 
  675. void InGameScene::addEndCallback(Node *pSender) 
  676.   ((Diamond *)pSender)->setMoving(false); 
  677. //--------------点击宝石后的查询、移除、填充等处理--END-------------// 
  678. //-----------------游戏计时和处理相关方法--START---------------// 
  679. //时间一秒秒慢慢减少的效果,并时间将结束时,播放响应效果 
  680. void InGameScene::updateTime(float dt) 
  681.   //m_pTimeLable->setString(__String::createWithFormat("%02d", --m_nTime)->getCString()); 
  682.   switch (m_nTime) 
  683.   { 
  684.   case 9: 
  685.     if (UserDefault::getInstance()->getBoolForKey("isEffectEnabled"false)) 
  686.     { 
  687.       SimpleAudioEngine()->playEffect("sounds/Countdown.ogg"); 
  688.     } 
  689.     break
  690.   case 10: 
  691.     // m_pTimerBar->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("timerBar2.png")); 
  692.     break
  693.   case 5: 
  694.     // m_pTimerBar->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("timerBar3.png")); 
  695.     break
  696.   case 1: //时间到了,显示Time's Up 
  697.   { 
  698.     this->unschedule(schedule_selector(InGameScene::updateTime)); 
  699.     LabelTTF *timeUp = LabelTTF::create("Time's Up""fonts/Verdana Bold.ttf", 50.f); 
  700.     timeUp->setPosition(Vec2(400, 650)); 
  701.     this->addChild(timeUp); 
  702.     timeUp->runAction(Sequence::create( 
  703.                CCScaleTo::create(1.0f, 1.3f), 
  704.                CCCallFunc::create(this, callfunc_selector(InGameScene::timeUpCallback)), 
  705.                NULL)); 
  706.   } 
  707.   break
  708.   } 
  709.   //随机时间产生炸弹 
  710.   if (rand() % 60 < 3) 
  711.   { 
  712.     this->changeDiamondToBomb(); 
  713.   } 
  714. //时间到后,跳转到相应场景 
  715. void InGameScene::timeUpCallback() 
  716.   UserDefault::getInstance()->setIntegerForKey("LastScore", m_nScore); 
  717.   if (m_nScore >= (int)(InGameScene::limitScore[InGameScene::level])) 
  718.   { 
  719.     ++InGameScene::background; //胜利后可切到下一个场景 
  720.     if (InGameScene::background > 4) 
  721.     { 
  722.       InGameScene::background = 1; 
  723.     } 
  724.     UserDefault::getInstance()->setBoolForKey("isPass"true); 
  725.     // 判断是否超过了最高分 
  726.     __String *highScore = __String::createWithFormat("HighScore%d", InGameScene::level); 
  727.     if (m_nScore > UserDefault::getInstance()->getIntegerForKey(highScore->getCString(), -1)) 
  728.     { 
  729.       InGameScene::background = 5; 
  730.       UserDefault::getInstance()->setIntegerForKey(highScore->getCString(), m_nScore); 
  731.       //Scene *pScene = LevelUpScene::scene(); 
  732.       //Director::getInstance()->replaceScene(pScene); 
  733.       //return; 
  734.     } 
  735.   } 
  736.   else 
  737.   { 
  738.     UserDefault::getInstance()->setBoolForKey("isPass"false); 
  739.   } 
  740.   showAds(); //显示广告 
  741.   Scene *pScene = ScoreScene::scene(); 
  742.   Director::getInstance()->replaceScene(pScene); 
  743. //-----------------游戏计时和处理相关方法--END---------------// 
  744. void InGameScene::changeDiamondToBomb() 
  745.   int row = -1, line = -1; 
  746.   do 
  747.   { 
  748.     row = RANDOM_RANGE(0, m_nDiamondRowMax - 0.01); 
  749.     line = RANDOM_RANGE(0, m_nDiamondLineMax - 0.01); 
  750.   } 
  751.   while (m_pDiamond[line][row] == NULL || m_pDiamond[line][row]->getBomb()); 
  752.   m_pDiamond[line][row]->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName( 
  753.       Diamond::BombTypeStr[m_pDiamond[line][row]->getType()])); 
  754.   m_pDiamond[line][row]->setBomb(true); 
  755.   m_pDiamond[line][row]->runAction(Sequence::create( 
  756.                      DelayTime::create(1.5f), //1.5秒后把炸弹的贴图换回为宝石钻石 
  757.                      CallFuncN::create(this, callfuncN_selector(InGameScene::restoreBombToDiamondCallback)), 
  758.                      NULL)); 
  759. void InGameScene::restoreBombToDiamondCallback(Node *pSender) 
  760.   Diamond *p = (Diamond *)pSender; 
  761.   if (p) 
  762.   { 
  763.     p->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(Diamond::TypeStr[p->getType()])); 
  764.     p->setBomb(false); 
  765.   } 
  766. //-----------累积火球特效进度--START---------------// 
  767. void InGameScene::runStepFireball(unsigned int count, bool reset) 
  768. //  if (m_pMagicProgress) 
  769. //  { 
  770. //    if (reset) //重新计数 
  771. //    { 
  772. //      m_nMagicCount = 0; 
  773. //      m_pMagicProgress->runAction(CCProgressTo::create(0.1f, 0)); 
  774. //      return; 
  775. //    } 
  776. // 
  777. //    unsigned int limit = InGameScene::limitFireball[InGameScene::level]; 
  778. // 
  779. //    if (count > (limit - m_nMagicCount)) 
  780. //    { 
  781. //      m_pMagicProgress->runAction(Sequence::create( 
  782. //                      CCProgressTo::create(0.3f, 100.0f), 
  783. //                      CCCallFunc::create(this, callfunc_selector(InGameScene::addFireballCallback)),//随机放置Magic宝石 
  784. //                      CCProgressTo::create(0.1f, 0), 
  785. //                      NULL)); 
  786. //      m_nMagicCount = 0; 
  787. //    } 
  788. //    else 
  789. //    { 
  790. //      m_nMagicCount += count; 
  791. //      float percent = 100 * m_nMagicCount / limit; 
  792. //      m_pMagicProgress->runAction(CCProgressTo::create(10 * (count / limit), percent)); 
  793. //    } 
  794. //  } 
  795. void InGameScene::addFireballCallback() 
  796.   int row = -1, line = -1; 
  797.   do 
  798.   { 
  799.     row = RANDOM_RANGE(0, m_nDiamondRowMax - 0.01); 
  800.     line = RANDOM_RANGE(0, m_nDiamondLineMax - 0.01); 
  801.   } 
  802.   while (m_pDiamond[line][row] == NULL || m_pDiamond[line][row]->getFireball()); 
  803.   //一颗钻石在火焰中燃烧的动画 
  804.   Vector<SpriteFrame * >fireBallFrame; 
  805.   for (int i = 1; i < 9; ++i) 
  806.   { 
  807.     __String *str = __String::createWithFormat("diamond_fireball%d.png", i); 
  808.     SpriteFrame *p = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString()); 
  809.     fireBallFrame.pushBack(p); 
  810.   } 
  811.   Animation *fireBallAnimation = Animation::createWithSpriteFrames(fireBallFrame, 0.05f); 
  812.   Animate *fireBallAnimate = Animate::create(fireBallAnimation); 
  813.   m_pDiamond[line][row]->setFireball(true); 
  814.   m_pDiamond[line][row]->runAction(Sequence::create( 
  815.                      CCRepeat::create(fireBallAnimate, 4), //宝石燃烧播放次数,大概一秒多的时间后恢复 
  816.                      CallFuncN::create(this, callfuncN_selector(InGameScene::removeFireballCallback)), 
  817.                      NULL)); 
  818. void InGameScene::removeFireballCallback(Node *pSender) 
  819.   Diamond *p = (Diamond *)pSender; 
  820.   if (p) 
  821.   { 
  822.     p->setFireball(false); 
  823.     p->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(Diamond::TypeStr[p->getType()])); 
  824.   } 
  825. //-----------累积火球特效进度--END---------------// 
  826. //-----------播放火球掉落特效,并删除对应一列宝石-START------------// 
  827. void InGameScene::playFireballAnimation(int line, int row) 
  828.   m_nFireballline = m_nDiamondRowMax; 
  829.   m_nFireballRow = row; 
  830.   if (UserDefault::getInstance()->getBoolForKey("isEffectEnabled"false)) 
  831.   { 
  832.     SimpleAudioEngine()->playEffect("sounds/Special_Event_fireball.ogg"); 
  833.   } 
  834.   this->schedule(schedule_selector(InGameScene::removeLineDiamond), 0.06f); 
  835.   this->playFireballAnimation(m_pDiamond[line][row]); 
  836. //火球特效中,删除火球对应的一列宝石 
  837. void InGameScene::removeLineDiamond(float delta) 
  838.   if (m_pDiamond[m_nFireballline][m_nFireballRow]) 
  839.   { 
  840.     m_pDiamondBatchNode->removeChild(m_pDiamond[m_nFireballline][m_nFireballRow], true); 
  841.     m_pDiamond[m_nFireballline][m_nFireballRow] = NULL; 
  842.   } 
  843.   if (--m_nFireballline == -1) 
  844.   { 
  845.     this->unschedule(schedule_selector(InGameScene::removeLineDiamond)); 
  846.   } 
  847. //火球特效中,播放火球特效 
  848. void InGameScene::playFireballAnimation(Diamond *diamond) 
  849.   SpriteFrameCache::getInstance()->addSpriteFramesWithFile("effects/fireball0-800x_port_mdpi.plist"); 
  850.   SpriteFrameCache::getInstance()->addSpriteFramesWithFile("effects/fireball1-800x_port_mdpi.plist"); 
  851.   Vector<SpriteFrame *> fireballFrame; 
  852.   for (int i = 1; i < 17; ++i) 
  853.   { 
  854.     __String *fileName = __String::createWithFormat("fireball_down%d.png", i); 
  855.     SpriteFrame *p = SpriteFrameCache::getInstance()->getSpriteFrameByName(fileName->getCString()); 
  856.     fireballFrame.pushBack(p); 
  857.   } 
  858.   auto animation = Animation::createWithSpriteFrames(fireballFrame, 0.06f); 
  859.   auto *fireball = Sprite::createWithSpriteFrameName("fireball_down1.png"); 
  860.   fireball->setPosition(Vec2(diamond->getPositionX() + 35, 580)); 
  861.   this->addChild(fireball); 
  862.   fireball->runAction(Sequence::create( 
  863.               Animate::create(animation), 
  864.               CallFuncN::create(this, callfuncN_selector(InGameScene::addRemovedDiamondCallback)), 
  865.               NULL)); 
  866. //火球特效中,特效结束后清理工作 
  867. void InGameScene::addRemovedDiamondCallback(Node *pSender) 
  868.   this->removeChild(pSender); 
  869.   this->schedule(schedule_selector(InGameScene::addRemovedDiamond), 1 / 40); 
  870. //-----------播放火球掉落特效,并删除对应一列宝石-END------------// 
  871. //------------暂停按钮功能------------------// 
  872. void InGameScene::menuPauseCallback(Ref *pSender) 
  873.   InGameScene::isPaused = true
  874.   showAds(); //暂停游戏时显示广告 
  875.   //暂停时间更新 
  876.   //m_pTimerBar->stopAllActions(); 
  877.   //m_pTimeLable->stopAllActions(); 
  878.   this->unscheduleUpdate(); 
  879.   //暂停时间更新 
  880.   this->unschedule(schedule_selector(InGameScene::updateTime)); 
  881.   //弹出暂停框 
  882.   m_pPause = PauseLayer::create(); 
  883.   m_pPause->retain(); 
  884.   this->addChild(m_pPause); 
  885.   //启动暂停时间的更新函数,等待回复 
  886.   this->schedule(schedule_selector(InGameScene::updatePaused), 1 / 60); 
  887. //在暂停页面时,此函数等待恢复标志,并恢复相应效果 
  888. void InGameScene::updatePaused(float delta) 
  889.   if (! InGameScene::isPaused) 
  890.   { 
  891.     hideAds(); //结束暂停时,隐藏广告 
  892.     this->unschedule(schedule_selector(InGameScene::updatePaused)); 
  893.     this->removeChild(m_pPause); 
  894.     CC_SAFE_RELEASE_NULL(m_pPause); 
  895.     InGameScene::level = UserDefault::getInstance()->getIntegerForKey("level"); 
  896.     m_nDiamondCount = InGameScene::level + 3; 
  897.     //m_pTimerBar->runAction(MoveTo::create(float(m_nTime), Vec2(-380, 95))); 
  898.     this->scheduleUpdate(); 
  899.     this->schedule(schedule_selector(InGameScene::updateTime), 1.0f); 
  900.   } 
  901. //------------暂停按钮功能-END-----------------// 
  902. //-------------播放四周燃烧的火焰特效---------------// 
  903. void InGameScene::playFireModeFlame() 
  904.   SpriteFrameCache::getInstance()->addSpriteFramesWithFile("effects/firemode-800x_port_mdpi.plist"); 
  905.   //down 
  906.   Vector<SpriteFrame *> animationFrame1; 
  907.   char str[64] = {0}; 
  908.   for (int i = 1; i < 7; ++i) 
  909.   { 
  910.     sprintf(str, "firemodeFlameDown%d.png", i); 
  911.     SpriteFrame *p = SpriteFrameCache::getInstance()->getSpriteFrameByName(str); 
  912.     animationFrame1.pushBack(p); 
  913.   } 
  914.   Animation *animation1 = Animation::createWithSpriteFrames(animationFrame1, 0.12f); 
  915.   Sprite *p1 = Sprite::createWithSpriteFrameName("emptyPixelFireMode.png"); 
  916.   p1->setAnchorPoint(Vec2(0.5f, .0f)); 
  917.   p1->setPosition(Vec2(400, 0)); 
  918.   p1->setTag(2001); 
  919.   this->addChild(p1); 
  920.   p1->runAction(RepeatForever::create(Animate::create(animation1))); 
  921.   //right 
  922.   Vector<SpriteFrame *> animationFrame2; 
  923.   for (int i = 1; i < 7; ++i) 
  924.   { 
  925.     sprintf(str, "firemodeFlameSide%d.png", i); 
  926.     auto *p = SpriteFrameCache::getInstance()->getSpriteFrameByName(str); 
  927.     animationFrame2.pushBack(p); 
  928.   } 
  929.   Animation *animation2 = Animation::createWithSpriteFrames(animationFrame2, 0.12f); 
  930.   Sprite *p2 = Sprite::createWithSpriteFrameName("emptyPixelFireMode.png"); 
  931.   p2->setAnchorPoint(Vec2(1.0f, 0.5f)); 
  932.   p2->setPosition(Vec2(800, 640)); 
  933.   p2->setTag(2002); 
  934.   this->addChild(p2); 
  935.   p2->runAction(RepeatForever::create(Animate::create(animation2))); 
  936.   //left 
  937.   Vector<SpriteFrame *> animationFrame21; 
  938.   for (int i = 1; i < 7; ++i) 
  939.   { 
  940.     sprintf(str, "firemodeFlameSide%d.png", i); 
  941.     auto p = SpriteFrameCache::getInstance()->getSpriteFrameByName(str); 
  942.     animationFrame21.pushBack(p); 
  943.   } 
  944.   Animation *animation21 = Animation::createWithSpriteFrames(animationFrame21, 0.12f); 
  945.   Sprite *p21 = Sprite::createWithSpriteFrameName("emptyPixelFireMode.png"); 
  946.   p21->setFlipX(true); 
  947.   p21->setAnchorPoint(Vec2(.0f, 0.5f)); 
  948.   p21->setPosition(Vec2(0, 640)); 
  949.   p21->setTag(2003); 
  950.   this->addChild(p21); 
  951.   p21->runAction(RepeatForever::create(Animate::create(animation21))); 
  952.   //top 
  953.   Vector<SpriteFrame *> animationFrame3; 
  954.   for (int i = 1; i < 9; ++i) 
  955.   { 
  956.     sprintf(str, "firemodeFlameTop%d.png", i); 
  957.     SpriteFrame *p = SpriteFrameCache::getInstance()->getSpriteFrameByName(str); 
  958.     animationFrame3.pushBack(p); 
  959.   } 
  960.   Animation *animation3 = Animation::createWithSpriteFrames(animationFrame3, 0.12f); 
  961.   Sprite *p3 = Sprite::createWithSpriteFrameName("emptyPixelFireMode.png"); 
  962.   p3->setAnchorPoint(Vec2(0.5f, 1.0f)); 
  963.   p3->setPosition(Vec2(400, 1280)); 
  964.   p3->setTag(2004); 
  965.   this->addChild(p3); 
  966.   p3->runAction(RepeatForever::create(Animate::create(animation3))); 
  967.   //播放火燃烧音效 
  968.   unsigned int id = SimpleAudioEngine()->playEffect("sounds/Speed_Mode_atmosphere.ogg"true); 
  969.   m_pEffectDict->setObject(__String::createWithFormat("%d", id), "sounds/Speed_Mode_atmosphere"); 
  970. void InGameScene::removeFireModeFlame() 
  971.   //停止火燃烧音效 
  972.   unsigned int id = m_pEffectDict->valueForKey("sounds/Speed_Mode_atmosphere")->uintValue(); 
  973.   SimpleAudioEngine()->stopEffect(id); 
  974.   this->removeChildByTag(2001); 
  975.   this->removeChildByTag(2002); 
  976.   this->removeChildByTag(2003); 
  977.   this->removeChildByTag(2004); 
  978. //-------------播放四周燃烧的火焰特效-END--------------// 
  979. //-------------在双倍火焰模式时,点击宝石显示的"+2"贴图-------------// 
  980. void InGameScene::displayDoubleScore() 
  981.   SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gems/gemTexture-800x_port_mdpi.plist"); 
  982.   Sprite *doubleScore = Sprite::createWithSpriteFrameName("time_bonus.png"); 
  983.   doubleScore->setPosition(Vec2(400, 750)); 
  984.   this->addChild(doubleScore); 
  985.   doubleScore->setScale(0.3f); 
  986.   doubleScore->runAction(Sequence::create( 
  987.                 CCScaleTo::create(.5f, 1.5f), 
  988.                 DelayTime::create(.6f), 
  989.                 CallFuncN::create(this, callfuncN_selector(InGameScene::removeDoubleScoreCallback)), 
  990.                 NULL)); 
  991. void InGameScene::removeDoubleScoreCallback(Node *pSender) 
  992.   this->removeChild(pSender); 
  993. //-------------在双倍火焰模式时,点击宝石显示的"+2"贴图-END------------// 

注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表