(no.00005) iOS implementation Bomb man game (v): Initialization of Game data (ii)

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please tell me, if you feel good please support a lot of praise. Thank you! Hopy;)

Now let's take a look at each of the methods mentioned in the previous article, first, the Updatestatelabel method:

#pragma mark Mainscene game-related helper methods//Update lead status label in the format: fast and invincible burst through the wall through the bomb remote control-(void) updatestatelabel{NSString*state = [NSStringstringwithformat:@"%@%@%@%@%@%@", _isplayerspeedup? @"Speedy":@"    ", _player. Isinvincible? @"Unbeatable":@"    ",!_isfearbomb? @"Burst":@"    ", _player. Canacrossbrick? @"Through the wall.":@"    ", _player. Canacrossbomb? @"bullet-piercing":@"    ", _ismanualexplode? @"Remote Control":@"    "]; [_hudlayer updatestatelabel:state];}

The code is good to understand, is to create a status string based on the status of the current protagonist and then display in the label, of course, the preferred method is to use the icon to display, this can be left for later expansion.

Next look at the Initnowalltiles method, the function of this method is to traverse all non-wall tile coordinates, for the subsequent method calls to prepare, play a cache data for speed purposes:

//initialization is not all tile coordinates of the wall, but also excludes (0,0), (0,1), (1,0) three tile.-(void) initnowalltiles{CgpointBADTILEPOS1 = CCP (0,0);CgpointBadTilePos2 = CCP (0,1);CgpointBADTILEPOS3 = CCP (1,0); for(intx =0; X < _tilemap. Mapsize. Width; X + +) { for(inty =0; Y < _tilemap. Mapsize. Height; y++) {CgpointTilepos = CCP (x, y);if(Cgpointequaltopoint (Tilepos, badTilePos1) | |                Cgpointequaltopoint (Tilepos, badTilePos2) | | Cgpointequaltopoint (Tilepos, BADTILEPOS3)) {Continue; }Else if(! [ SelfIswallattilecoord:tilepos]) {[_notwalltiles addobject:[nsvalue Valuewithcgpoint:tilepos]]; }}} Nsassert (_notwalltiles. Count==249, @"_notwalltiles must equ 249");}

The code iterates through all the tile in turn, adding the coordinates of the non-wall tile to the _notwalltiles array, so that we can easily use the data in the subsequent randomly generated map method. Note that 3 coordinates are removed, respectively:

(0,0), (0,1) and (1,0)

Because the game lead bomber needs to produce in (0,0), so (0,1) and (1,0) naturally can not place bricks, otherwise the protagonist itself will be "dead end", and finally with an assertion to check the number of non-wall tile is 249, this is manually calculated in advance, a total of 30x10=300 tile, Minus the 6*8=48 wall, minus 3 of the above coordinates, and finally the remaining 249 tile can be manipulated.

(no.00005) iOS implementation Bomb man game (v): Initialization of Game data (ii)

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.