cocos2d-x 我要入門——微信打飛機(9)

來源:互聯網
上載者:User

這是前段時間完成的了,一直沒總結起來

因為剛好3.0橫空出世,重新安裝vs2013,cocos2dx3.0 ,cocoStudio……

也是想把飛機移植到手機上,遇到了很多問題,用什麼方法移植,一直想在myeclipse裡安裝ADT外掛程式,用於建立安卓項目,卸載安裝出錯卸載安裝出錯,那兩天就是這麼過來的。後來還是簡單粗暴地解決了安卓環境的問題,直接下載整合ADT的eclipse。但還是在建立項目時候出錯了。至今未果。(當然也是噁心了太多天了,我暫且放下,結果,沉沒在各種作業當中,也沉浸在各種即將和好友見面的期待中,各種沒抵擋住,面壁自省中。。。)

廢話不說,先把我在偶爾教程中自己添加的那一部分總結出來。


我是在遊戲中,增加了兩個模式:普通模式和無敵模式(靈感出於舍友說有沒有不死的飛機)

用枚舉類型,建立兩個常量 ISSTRONG NOTSTRONG

GameLayer.h

enum Strong{ISSTRONG,NOTSTRONG,};


在Welcome介面設定2個Menu


(= =自己畫的)


在Welcome.h中

static Strong getStrong(); //用於擷取傳遞過來的常量值static Strong isStrong; 

Welcome.cpp

Strong WelcomeLayer::getStrong(){return isStrong;}


點擊普通模式,傳遞的就是NOTSTRONG

void WelcomeLayer::normalPlane(CCObject* pSender){isStrong = NOTSTRONG;CCScene* pSence = GameScene::create();CCTransitionMoveInB* animateScene=CCTransitionMoveInB::create(1.0f,pSence);CCDirector::sharedDirector()->replaceScene(animateScene);}
點擊無敵模式

void WelcomeLayer::strongPlane(CCObject* pSender){isStrong = ISSTRONG;CCScene* pSence = GameScene::create();CCTransitionMoveInB* animateScene=CCTransitionMoveInB::create(1.0f,pSence);CCDirector::sharedDirector()->replaceScene(animateScene);}


然後在對飛機的碰撞檢測中,判斷在Welcome介面點擊的哪個模式,傳遞的是哪個值,來進行碰撞與否。

在GameLayer.cpp中

switch (WelcomeLayer::getStrong()){case NOTSTRONG://enemy1&airplane checkcollosionCCARRAY_FOREACH(this->enemyLayer->m_pAllEnemy1, et){Enemy* enemy1 = (Enemy*)et;if (enemy1->getLife() > 0){if (airplaneRect.intersectsRect(enemy1->getBoundingBox())){this->unscheduleAllSelectors();this->bulletLayer->StopShoot();this->mutiBulletLayer->StopShoot();this->planeLayer->Blowup(score);return;}}}//enemy2&airplane checkcollosionCCARRAY_FOREACH(this->enemyLayer->m_pAllEnemy2, et){Enemy* enemy2 = (Enemy*)et;if (enemy2->getLife() > 0){if (airplaneRect.intersectsRect(enemy2->getBoundingBox())){this->unscheduleAllSelectors();this->bulletLayer->StopShoot();this->mutiBulletLayer->StopShoot();this->planeLayer->Blowup(score);return;}}}//enemy3&airplane checkcollosionCCARRAY_FOREACH(this->enemyLayer->m_pAllEnemy3, et){Enemy* enemy3 = (Enemy*)et;if (enemy3->getLife() > 0){if (airplaneRect.intersectsRect(enemy3->boundingBox())){this->unscheduleAllSelectors();this->bulletLayer->StopShoot();this->mutiBulletLayer->StopShoot();this->planeLayer->Blowup(score);return;}}}break;case ISSTRONG:break;}
主要是當飛機和敵機不進行碰撞檢測的時候,就是飛機無敵的時候。







聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.