(No. 00003) iOS games simple robot projection game forming note (12)

Source: Internet
Author: User

(No. 00003) iOS games simple robot projection game forming note (12)

Return to Xcode and create the Level1 class, which inherits from CCNode.

Open Level1.m and add the following method to the initialization method:

-(void)didLoadFromCCB{    [self initBasket];    [self initRestrict];}

The following two methods are implemented respectively.

The first is initBasket:

-(void)initBasket{    CCActionMoveBy *mov1 = [CCActionMoveBy actionWithDuration:5 position:ccp(0, -0.7)];    CCActionMoveBy *mov2 = [CCActionMoveBy actionWithDuration:5 position:ccp(0, 0.7)];    CCActionSequence *seq = [CCActionSequence actions:mov1,mov2,nil];    CCActionRepeatForever *repeat = [CCActionRepeatForever actionWithAction:seq];    [_basket runAction:repeat];}

It is easy to use Action to move the basket and keep the Action repeating forever.

The following is the Restrict method:

-(void)initRestrict{    LevelRestrict *lr = [LevelRestrict sharedInstance];    lr.bulletCount = 10;    lr.timeCount = 60;    lr.scoreCount = 3;}

Each pass has a specific pass condition. The LevelRestrict class is used to save the conditions. bulletCount, timeCount, and scoreCount indicate the bullet limit, time limit, and score limit of the Level respectively.

Create a LevelRestrict class in Xcode and inherit from NSObject. Modify LevelRestrict. h as follows:

#import 
  
   @interface LevelRestrict : NSObject@property (nonatomic,assign) NSInteger bulletCount;@property (nonatomic,assign) NSInteger timeCount;@property (nonatomic,assign) NSInteger scoreCount;@property (nonatomic,strong) NSString *levelName;+(instancetype)sharedInstance;-(void)print;
  

Open LevelRestrict. m to implement the singleton method:

+(instancetype)sharedInstance{    static LevelRestrict *sharedLevelRestrict;    if (!sharedLevelRestrict) {        sharedLevelRestrict = [LevelRestrict new];    }    return sharedLevelRestrict;}

 

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.