這是前段時間完成的了,一直沒總結起來
因為剛好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;}主要是當飛機和敵機不進行碰撞檢測的時候,就是飛機無敵的時候。