cocos2dx3.2 development RPG "flighting" (15) Final summary of the description, as well as source sharing

Source: Internet
Author: User
Tags strtok

First, preface

This flighting series of tutorials was written 2 days in a breath, and it's almost over. Next I would like to add a few things that are not mentioned earlier, but I think it is necessary to speak.


Second, the text

1. The appearance of Monsters

The front has said a xxxmessageutil, in fact, Statemessageutil is more special. First, let's take a look at Statemessage's Excel table (level)

Previous fields you can fathom, I mainly talk about the monster field

The Monster field represents the monster-to-queue for this level, with the "|" Separated

Class Stagemessage{public:int id;string name;int reward_money;int reward_exp;int boss;string reward_item;deque< Monstermessage> Monsterdeq;};

As you can see, our stagemessage also have a corresponding queue Monsterdeq

void Stagemessageutil::init () {std::string jsonstr = cocos2d::fileutils::getinstance ()->getstringfromfile ("Json/ Stagemessage.json "); Rapidjson::D ocument _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 ();//Here begins the initialization of the 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 work of the monster queue where the code callout starts

After getting the queue, we can detect how many monsters are present in the Flightlayer, if less than the specified number (I am here 4), come out a

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: Click to open link

I was running successfully under the vs2012+cocos2dx3.2 platform before uploading.


3. Already packaged APK

The last time we wiped out the stars, we said there was a problem with porting to the Android platform, and this time I migrated, and the Android platform was ready to run.

APK: Click to open link

At this point, the entire COCOS2DX 3.2 development RPG "flighting" series to this end, thank you.

My csdn Address: http://blog.csdn.net/hezijian22

Email address: [Email protected]

If you have any questions or advice, please feel free to contact me.


cocos2dx3.2 development RPG "flighting" (15) Final summary of the description, as well as source sharing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.