(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;}