Cocos2dx3.2 summary of the development of RPG Flighting (15th), as well as source code sharing, cocos2dx3.0label
I. Preface
This Flighting series of tutorials has been written for two days in one breath, and it is about to end here. Next, I will explain some things that I didn't mention before, but I think it is necessary to explain them.
Ii. Text
1. Appearance of monsters
I have already mentioned XXXMessageUtil one by one. In fact, StateMessageUtil is quite special. First, let's take a look at the StateMessage Excel table (level)
You can see the previous fields. I will mainly talk about the monster fields.
The monster field indicates the monster queue of this level, which is separated by "| ".
class StageMessage{public:int id;string name;int reward_money;int reward_exp;int boss;string reward_item;deque<MonsterMessage> monsterDeq;};
We can see that our StageMessage also has a corresponding queue 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 (); // The initialization queue 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 ;}
Initialize the monster queue where the code starts
After getting the queue, we can check the number of monsters in the FlightLayer. If there are fewer monsters than the number specified (I am going to have four here), we will find one
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. source code sharing
Source code: Click to open the link
Before uploading, I successfully run on the VS2012 + cocos2dx3.2 platform.
3. the packaged apk
The last time we wiped out the stars, we said there was a problem with porting it to the Android platform. This time I also transplanted it specially, And the android platform can run it.
APK: Click to open the link
So far, Cocos2dx 3.2 has finished developing the RPG Flighting series. Thank you.
My csdn address: http://blog.csdn.net/hezijian22
Email Address: 578690286@qq.com
If you have any questions or suggestions, please feel free to contact me. Thank you.