Cocos2d-x 3.2 Monopoly Game project Development-16th part of the linked parcel paid tolls

Source: Internet
Author: User

When you go to other characters of the plot, according to whether the current plot is connected to the film, the unified calculation of the need to pay the tolls, even the calculation of the way, is the sum of the tolls of each parcel.

First get the x y coordinate (the land layer coordinates) of the block passing by the current walking character, then get the coordinates of the character (GL coordinates, need to convert to map coordinates),

The 2 coordinate values are then compared in a horizontal and vertical direction.

A location: A case study of the method of finding the left parcel

1. Convert role a coordinates to coordinates in map

2. Place the Sprite object of the current NO. 0 block into the container so that the fade-in animation can be played back

The x-coordinates of the 3 and No. 0 plots are equal to the X-values of the map coordinates of the role a, and if they are equal, the top or bottom of the current role has the other side's plots.

4. Get the coordinates of number No. 0 on the left adjacent to 1th

5. Get the GID value of block No. 1th

6. Judging the GID value of block No. 1th

7, according to the GID level of block 1th, add the tolls

8. Put the No. 1th plot sprite into the container

9, continue to find the left adjacent 2nd plots, the treatment method with the 1th plots

10. If there is no plot on the left, exit the loop to find the left parcel and continue looking for the right parcel



void Gamebasescene::p aytolls (int paytag,float x,float y, int playertag) call to Displayarea method first to explain the parameter float x: represented in land The horizontal axis value of the parcel in the layer, float y: Represents the ordinate value of the parcel in the land layer richerplayer* player: currently walking role int Building_1_tiledid: Passing parcel 1 level int Building _2_tiledid: Passing parcel 2 grade int building_3_tiledid: Passing parcel 3 level return value represents the toll sum of other patch plots in addition to the current parcel int gamebasescene::d isplayarea (float x, float y,richerplayer* player,int building_1_tiledid,int building_2_tiledid,int building_3_tiledid) {int SumMoney =0;// Tolls sum initial value float Retx = Util::gl2map (Player->getposition (), _map). x; Convert the character coordinates to the coordinates in the map if (x = = retx)//Compare the x values of the map coordinates for equality, if equal means that the top or bottom of the current role has each other's plots. {Float LEFTX = x-1;//The coordinate of the left side of the current parcel is RIGHTX = x + 1;//coordinate int leftgid = Landlayer->gettilegidat (CCP (LEFTX, Y)///Get the GID value int rightgid = Landlayer->gettilegidat (CCP (Rightx,y)) of the adjacent left parcel and/or get the GID value of the neighboring right plots Displayvector.pushback (Landlayer->gettileat (CCP (x, y))); Puts the sprite object of the current parcel into the container so that the fade-in animation is played back while (Leftgid! = 0 && (leftgid = = Building_1_tiledid | | leftgid = = Building_2 _tiledid | | LeFtgid = = Building_3_tiledid))//Determine the adjacent left parcel gid{if (Leftgid = = Building_1_tiledid)//If the GID of the adjacent left parcel is a parcel of level 1, add the tolls {Summoney + = Land_blank_money;} if (Leftgid = = Building_2_tiledid)//If the GID of the adjacent left parcel is a parcel of level 2, add the tolls {Summoney + = Land_level_1_money;} if (Leftgid = = Building_3_tiledid)//If the GID of the adjacent left parcel is a parcel of level 3, add the tolls {Summoney + = Land_level_2_money;} Displayvector.pushback (Landlayer->gettileat (CCP (Leftx,y))); Place the adjacent left parcel sprite into the container leftx-= 1;//continue to find the adjacent left parcel Leftgid = Landlayer->gettilegidat (CCP (leftx,y));//Get the plot GID value if ( Leftgid = = 0)//If there are no plots on the left, exit the loop that looks for the left parcel {break;} Log ("Leftgid:%d", leftgid);} while (Rightgid! = 0 && (rightgid = = Building_1_tiledid | | rightgid = = Building_2_tiledid | | rightgid = = Building_3 _TILEDID)//Judge adjacent right parcel gid{if (Rightgid = = Building_1_tiledid)//If the GID of the adjacent right parcel is a parcel of level 1, add the tolls {Summoney + = Land_blank_ Money;} if (Rightgid = = Building_2_tiledid)//If the GID of the adjacent right parcel is a parcel of level 2, add the tolls {Summoney + = Land_level_1_money;} if (Rightgid = = Building_3_tiledid)//If the GID of the adjacent right parcel is a parcel of level 3, add the tolls {Summoney + = Land_level_2_money;} DiSplayvector.pushback (Landlayer->gettileat (CCP (Rightx,y)));//Place the adjacent right parcel sprite into the container rightx + = 1;// Continue to find adjacent right parcel Rightgid = Landlayer->gettilegidat (CCP (rightx,y));//Get plot GID value if (Rightgid = = 0)//If there is no plot on the right, exit the loop looking for the right parcel { break;} Log ("Rightgid:%d", Rightgid);}} The method of finding plots up and down is the same as left and right logic, no longer tiring. ....//The animation of the sprite in the container, the effect is the adjacent parcel fade in for (auto It=displayvector.begin (); It!=displayvector.end (), and so on. ; it++) {(sprite*) (*it)->runaction (Sequence::create (Landfadeout->clone (), Landfadein->clone (), NULL));} return Summoney;}        void Gamebasescene::p aytolls (int paytag,float x,float y, int playertag) {int money = 0;   if (PayTag = = Msg_pay_tolls_1_tag) {money = Land_blank_money;} if (PayTag = = Msg_pay_tolls_2_tag) {money = Land_level_1_money;} if (PayTag = = Msg_pay_tolls_3_tag) {money = Land_level_2_money;} Clear the container first displayvector.clear (); richerplayer* landowner = getplayerbytiled (buy_land_x,buy_land_y); switch (playertag) {case player_1_tag:{// Get land tolls sum int retmoney = Displayarea (X,y,player1,player2_building_1_tilediD,player2_building_2_tiledid,player2_building_3_tiledid)///update the role corresponding funds Refreshmoneylabel (Landowner,money + RetMoney ); Refreshmoneylabel (player1,-(Money + Retmoney)); Notificationcenter::getinstance ()->postnotification (Msg_pickone_togo,string::createwithformat ("%d", MSG_ Pickone_togo_tag)); break;} Case Player_2_tag:{int Retmoney = Displayarea (X,y,player2,player1_building_1_tiledid,player1_building_2_tiledid, Player1_building_3_tiledid); Refreshmoneylabel (Landowner,money + Retmoney); Refreshmoneylabel (player2,-(Money + Retmoney)); Notificationcenter::getinstance ()->postnotification (Msg_pickone_togo,string::createwithformat ("%d", MSG_ Pickone_togo_tag)); break;}}}



Click to download the code

http://download.csdn.net/detail/lideguo1979/8330609


Not to be continued ..........

Cocos2d-x 3.2 Monopoly Game project Development-16th part of the linked parcel paid tolls

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.