With the 18th part of the previous treatment, the question mark event, the character after walking, but also check whether there is a stay problem card, if any, increase the corresponding physical value
1, the new ITEM_STRENGTH_UP class, this class is used to show the character's physical rebound animation.
void Item_strength_up::additemspriteframecache () {Itemspriteframecache = Spriteframecache::getinstance (); Itemspriteframecache->addspriteframeswithfile ("Images/strength_up.plist", "images/strength_up.png"); Memset ( Name, 0,), for (int i=1; i<=14; i++) {sprintf (name, "Strength_up_%02d.png", I); Item_anim_vector.pushback ( Itemspriteframecache->getspriteframebyname (name));}} void Item_strength_up::setitemanimate () {if (! Animationcache::getinstance ()->getanimation ("Strength_up_animation")) {animationcache::getinstance () Addanimation (Animation::createwithspriteframes (item_anim_vector,0.1f), "strength_up_animation");} Normal_anmi = Animate::create (Animationcache::getinstance ()->getanimation ("Strength_up_animation"); Normal_anmi->retain ();}
2, in the Richergamecontroller class of Handlepropevent method, add points card judgment, if the stay position has points card, then send the MSG_STRENGTH_UP message of increasing physical strength
void Richergamecontroller::handlepropevent () {... if (Endid = = Gamebasescene::strength_30_tiledid) {String * str = String::createwithformat ("%d-%f-%f-%d",msg_strength_up30_tag,pointinmap.x,pointinmap.y,_richerplayer-> Gettag ()); Notificationcenter::getinstance ()->postnotification (MSG_STRENGTH_UP,STR); Return } if (Endid = = Gamebasescene::strength_50_tiledid) {String * str = string::createwithformat ("%d-%f-%f-%d", msg_strength_ Up50_tag,pointinmap.x,pointinmap.y,_richerplayer->gettag ()); Notificationcenter::getinstance ()->postnotification (MSG_STRENGTH_UP,STR); Return } if (Endid = = Gamebasescene::strength_80_tiledid) {String * str = string::createwithformat ("%d-%f-%f-%d", msg_strength_ Up80_tag,pointinmap.x,pointinmap.y,_richerplayer->gettag ()); Notificationcenter::getinstance ()->postnotification (MSG_STRENGTH_UP,STR); Return }}
3, Gamebasescene continue to register to increase the physical value of observation and processing code
void Gamebasescene::registernotificationobserver () {....... Notificationcenter::getinstance ()->addobserver (This,callfunco_selector (gamebasescene:: receivednotificationomsg), msg_strength_up,null);} Receivednotificationomsg calls the Doitemstrengthup method to specifically handle the physical value increase and the physical recovery animation of the playback void gamebasescene::receivednotificationomsg ( object* data) {... case msg_strength_up30_tag:{doitemstrengthup (Msg_strength_up30_tag, messagevector.at (3). )->intvalue ()); break;} Case Msg_strength_up50_tag:{doitemstrengthup (Msg_strength_up50_tag, messagevector.at (3)->intValue ()); Case Msg_strength_up80_tag:{doitemstrengthup (Msg_strength_up80_tag, messagevector.at (3)->intValue ());
4. After the physical animation has been played, call send Message Sendmsgdealaroundland to handle the next-to-right neighborhood parcel events
void Gamebasescene::d oitemstrengthup (int strengthup,int playertag) {int strengthvalue = 0;//based on the integral card value, Assign the corresponding value switch (strengthup) {case Msg_strength_up30_tag:{strengthvalue =30;break to Strengthvalue;} Case Msg_strength_up50_tag:{strengthvalue =50;break;} Case Msg_strength_up80_tag:{strengthvalue =80;break;}} Switch (playertag) {Case player_1_tag:{//settings item_strength_up visible in the position of the role, plays the animation, displays the toast. Playback complete Set item_strength_up invisible item_strength_up->setvisible (true); Item_strength_up->setposition (player1-> GetPosition ()-CCP (5,0)); sequence* action = sequence::create (Item_strength_up->getnormal_anmi (), Callfunc::create ([this] () {Item_strength _up->setvisible (FALSE);}), NULL); Item_strength_up->runaction (action); Cocostoast::createtoast (This, String::createwithformat ("%s%d", Languagestring::getinstance () Getlanguagestring (STRENGTH_UP)->getcstring (), Strengthvalue)->getcstring (),toast_show_time,player1-> GetPosition ()); Refreshstrengthlabel (Player1,strengthvalue); Scheduleonce (Schedule_selector (gamebasesceNe::sendmsgdealaroundland), 3.0f); break;} The case player_2_tag:{...}}...}
Effect
Click to download the code
Cocos2d-x 3.2 Monopoly Game project Development-21st part pick up points card recovery stamina