Cocos2d-x 3.2 Monopoly game project development-Part 2 linked land payments toll, cocos2d-x Project Development

Source: Internet
Author: User

Cocos2d-x 3.2 Monopoly game project development-Part 2 linked land payments toll, cocos2d-x Project Development

When you move to a plot of another role, you can calculate the tolls you need to pay based on whether the current plot is contiguous or not. The calculation method is the sum of the tolls for each plot.

First, obtain the x y coordinate of the block passing by the current walking role (the coordinate of the Land layer), and then obtain the coordinate of the role (the coordinate of GL, which needs to be converted to the coordinate in map ),

Then compare the two coordinate values horizontally and vertically.

Location A: The method for finding the Left Block is used as an example.

1. Convert role A into coordinates in map

2. Add the sprite object of the current plot 0 to the container to play the fade-in and fade-out animation.

3. Whether the x coordinate of plot 0 is equal to the x coordinate of map of Role A. If the x coordinate is equal, it indicates that the current role has the opposite plot at the top or bottom.

4. Obtain the coordinates of adjacent 1 on the left of plot 0

5. Obtain the GID value of Block 1

6. Determine the GID value of Block 1

7. Add the toll based on the GID level of the No. 1 plot

8. Add the sprite Block 1 to the container.

9. continue to search for the adjacent No. 2 plot on the left. The solution is the same as that of No. 1 plot.

10. If there is no land block on the left, exit the search cycle for the land block on the left and continue searching for the land block on the right.



Void GameBaseScene: payTolls (int payTag, float x, float y, int playerTag) Call the displayArea method to describe the float x parameter first: float y indicates the horizontal coordinate value of blocks in the land Layer. float y indicates the ordinate value of blocks in the land Layer. RicherPlayer * player: The currently walking role int building_javastiledid: 1 level int building_2_tiledID: 2 level int building_3_tiledID: the return value of Level 3 of the pass-by plot indicates the total toll of other contiguous plots except the current plot. int GameBaseScene :: displayArea (float x, float y, RicherPlayer * player, int building_1_tiledID, int buildin G_2_tiledID, int building_3_tiledID) {int sumMoney = 0; // The initial value of float retX = Util: GL2map (player-> getPosition (), _ map ). x; // convert the role coordinates to the coordinates in the map if (x = retX) // compare whether the x values of the map coordinates are equal, if they are equal, the current role has a block of the other side. {Float leftX = x-1; // coordinate float rightX = x + 1 on the left of the current plot; // The coordinate int leftGID = landLayer-> getTileGIDAt (ccp (leftX, y) of the adjacent right side of the current plot )); // obtain the GID value of the adjacent left block int rightGID = landLayer-> getTileGIDAt (ccp (rightX, y); // obtain the GID value of the adjacent right block displayVector. pushBack (landLayer-> getTileAt (ccp (x, y); // puts the sprite object of the current plot into the container, so that the animation while (leftGID! = 0 & (leftGID = building_1_tiledID | leftGID = building_2_tiledID | leftGID = required) // you can determine the GID of the adjacent left-side plot {if) // if the GID of the adjacent left block is the block of level 1, add the toll plus {sumMoney + = land_blk_money;} if (leftGID = building_2_tiledID) // if the GID of the adjacent left plot is a Level 2 plot, add the tolls {sumMoney + = land_level_0000money;} if (leftGID = building_3_tiledID) // If the GID of the adjacent left plot is a Level 3 plot, add the toll plus {sumMoney + = LAND_LEVEL_2_MONEY;} d IsplayVector. pushBack (landLayer-> getTileAt (ccp (leftX, y); // put the sprite of the adjacent left block into the container leftX-= 1; // continue to search for the leftGID = landLayer-> getTileGIDAt (ccp (leftX, y) of the adjacent left plot; // obtain the GID value of the plot if (leftGID = 0) // if there are no plots on the left, exit the {break;} log ("leftGID: % d", leftGID);} while (rightGID! = 0 & (rightGID = building_effectiledid | rightGID = building_2_tiledID | rightGID = required) // determine the GID of the adjacent right block {if (rightGID = building_effectiledid) // if the GID of the adjacent right plot is the plot of Grade 1, add the toll plus {sumMoney + = land_blk_money;} if (rightGID = building_2_tiledID) // if the GID of the adjacent right plot is a Level 2 plot, add the toll plus {sumMoney + = land_level_0000money;} if (rightGID = building_3_tiledID) // If the GID of the adjacent right plot is a grade 3 plot, add the tolls {sumMoney + = LAND_LEVEL_2_MO NEY;} displayVector. pushBack (landLayer-> getTileAt (ccp (rightX, y); // put the sprite on the adjacent right side into the container rightX + = 1; // continue to search for the adjacent right plot rightGID = landLayer-> getTileGIDAt (ccp (rightX, y); // obtain the plot GID value if (rightGID = 0) // if there is no block on the right, exit the {break;} log ("rightGID: % d", rightGID) of the block on the right );}} // The method for finding a block from top to bottom is the same as that for the left and right logic ......................... // Play the sprite animation in the container. The effect is that adjacent plots fade in and out for (auto it = displayVector. begin (); it! = DisplayVector. end (); it ++) {(Sprite *) (* it)-> runAction (Sequence: create (landFadeOut-> clone (), landFadeIn-> clone (), NULL);} return sumMoney;} void GameBaseScene: payTolls (int payTag, float x, float y, int playerTag) {int money = 0; if (payTag = msg_pay_tolls_alipay tag) {money = land_blk_money;} if (payTag = MSG_PAY_TOLLS_2_TAG) {money = land_level_0000money;} if (payTag = MSG_PAY_TOLLS_3_TAG) {money = LAND_LEVEL_2_MONEY ;} // first clear the container displayVector. clear (); RicherPlayer * landOwner = getPlayerByTiled (buy_land_x, buy_land_y); switch (playerTag) {case PLAYER_1_TAG: {// get the total land transfer fee int retMoney = displayArea (x, y, player1, primary, primary, secondary); // update the role's corresponding fund refreshMoneyLabel (landOwner, money + retMoney); refreshMoneyLabel (player1,-(money + retMoney); icationicationcenter :: getInstance ()-> postNotification (MSG_PICKONE_TOGO, String: createWithFormat ("% d", MSG_PICKONE_TOGO_TAG); break;} case PLAYER_2_TAG: {int retMoney = displayArea (x, y, player2, example, example, player+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


To be continued ..................

Related Article

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.