cocos2dx3.2開發 RPG《Flighting》(十五)最後的總結說明,以及源碼分享,cocos2dx3.0label

來源:互聯網
上載者:User

cocos2dx3.2開發 RPG《Flighting》(十五)最後的總結說明,以及源碼分享,cocos2dx3.0label

一、前言

這次的Flighting系列教程一口氣寫了2天,到這裡就要結束了。接下來我說明補充一下一些前面沒有提到,但是我覺得有必要講一下的。


二、本文

1.怪物的出場

前面已經說了一個個的XXXMessageUtil,其實StateMessageUtil是比較特別的。首先我們先看看StateMessage的Excel表(關卡)

前面的欄位大家可以參透參透,我主要講一講monster欄位

monster欄位表示這個關卡的怪物對隊列,用“|”隔開

class StageMessage{public:int id;string name;int reward_money;int reward_exp;int boss;string reward_item;deque<MonsterMessage> monsterDeq;};

可以看到,我們的StageMessage也相應的有一個隊列monsterDeq

void StageMessageUtil::init(){std::string  jsonStr = cocos2d::FileUtils::getInstance()->getStringFromFile("Json/StageMessage.json");rapidjson::Document _mDoc;std::string mstr = jsonStr;RETURN_IF(NULL==mstr.c_str()||!mstr.compare(""));_mDoc.Parse<0>(mstr.c_str());RETURN_IF(_mDoc.HasParseError()||!_mDoc.IsObject());const rapidjson::Value &pArr = _mDoc["json"];CCLOG("Size = %d",pArr.Capacity());for(int i=0;i<pArr.Capacity();++i){StageMessage stage;const rapidjson::Value &temp = pArr[i];int key = temp["id"].GetInt();stage.id = temp["id"].GetInt();stage.name = temp["name"].GetString();stage.boss = temp["boss"].GetInt();stage.reward_money = temp["reward_money"].GetInt();stage.reward_exp = temp["reward_exp"].GetInt();stage.reward_item = temp["reward_item"].GetString();//這裡開始初始化隊列string monsterStr = temp["monster"].GetString();char c[64];strcpy(c,monsterStr.c_str());char* s = strtok(c,"|");while(s != NULL){int id_num;stringstream ss;ss << s;ss >> id_num;CCLOG("GET ID:%d",id_num);MonsterMessage msg = MonsterMessageUtil::getInstance()->getMessageById(id_num);stage.monsterDeq.push_back(msg);s = strtok(NULL,"|");}CCLOG("DEQ SIZE = %d",stage.monsterDeq.size());stageMap.insert(make_pair(key,stage));}CCLOG("STAGE MAP SIZE = %d",stageMap.size());return;}
初始化怪物隊列的工作在代碼標註的哪裡開始

得到隊列以後,我們在FlightLayer裡面可以檢測現在有多少個怪物,如果少於規定個數(我這裡是4個),就出來一個

void FlightLayer::updateMonster(){int count = 0;for(auto it=m_rolesArray.begin();it!=m_rolesArray.end();++it){if((**it)->getRoleType() == Role::ROLE_TYPE_MONSTER){++count;}}if(count < 4){if(m_monsterDeq.size() == 0){return;}MonsterMessage msg = *m_monsterDeq.begin();m_monsterDeq.pop_front();Monster* monster = Monster::create(msg.r_name,this);monster->initWithMessage(msg);monster->setPosition(2000,260);this->addRole(monster);CCLOG("ADD MONSTER:%s TO LAYER",msg.name.c_str());}return;}


2.源碼分享

源碼:點擊開啟連結

我在上傳之前在VS2012+cocos2dx3.2平台下運行成功。


3.已經打包好的apk

上次消滅星星大家說移植到Android平台有問題,這次我特意也移植了,android平台是可以啟動並執行。

APK:點擊開啟連結

至此,整個Cocos2dx 3.2開發RPG《Flighting》系列到此結束,謝謝大家。

我的csdn地址:http://blog.csdn.net/hezijian22

郵箱地址:578690286@qq.com

如有問題或指教,歡迎與我交流,謝謝。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.