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

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