你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> (NO.00003)iOS游戲簡單的機器人投射游戲成形記(十二)

(NO.00003)iOS游戲簡單的機器人投射游戲成形記(十二)

編輯:IOS開發綜合

回到Xcode,新建Level1類,繼承於CCNode.

打開Level1.m在初始化方法中添加如下方法:

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

下面分別實現其中2個方法.

首先是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];
}

很簡單,就是用Action移動籃筐,並保持動作永遠循環.

下面是後面的Restrict方法:

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

每一關都有特定的過關條件,類LevelRestrict就是用來保存過條件的類,其中的bulletCount,timeCount和scoreCount分別表示該Level的子彈限制,時間限制以及分數限制.

在Xcode中新建LevelRestrict類,繼承於NSObject,修改LevelRestrict.h如下:

#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;

打開LevelRestrict.m,實現單例方法:

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

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved