您当前的位置: 首页 >  游戏

(NO.00003)iOS游戏简单的机器人投射游戏成形记(十二)

发布时间:2015-11-11 09:21:02 ,浏览量:0

回到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;
}
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    109273博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1145s