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

來源:互聯網
上載者:User

(NO.00003)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;}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.