实现分析 - Enemy

启动addEnemy的循环
Listing 5.18  GameplayLayer.m init method additions
[self schedule:@selector(addEnemy) interval:10.0f];


 addEnemy 作为对外的入口 - 内部统一用 createObjectOfType 来处理
 如果XXX (不再加入Enemy了),unschedule这个循环

 Listing 5.17  GameplayLayer.m addEnemy method
-(void)addEnemy {
CGSize screenSize = [CCDirector sharedDirector].winSize;
    RadarDish *radarDish = (RadarDish*)
     [sceneSpriteBatchNode getChildByTag:kRadarDishTagValue];
if (radarDish != nil) {
if ([radarDish characterState] != kStateDead) {
            [self createObjectOfType:kEnemyTypeAlienRobot
              withHealth:100
              atLocation:ccp(screenSize.width * 0.195f,
              screenSize.height * 0.1432f)
              withZValue:2];
        } else {
            [self unschedule:@selector(addEnemy)];
        }
    }
}



下面是CreateObjectOfType的一部分

-(void)createObjectOfType:(GameObjectType)objectType withHealth:(int)initialHealth atLocation:(CGPoint)spawnLocation withZValue:(int)ZValue {
  if (kEnemyTypeRadarDish == objectType) {
       CCLOG(@"Creating the Radar Enemy");
       RadarDish *radarDish =  [[RadarDish alloc] initWithSpriteFrameName:@"radar_1.png"];
       [radarDish setCharacterHealth:initialHealth];
       [radarDish setPosition:spawnLocation];
       [sceneSpriteBatchNode addChild:radarDish z:ZValue tag:kRadarDishTagValue];
       [radarDish release];

    } else if (kEnemyTypeAlienRobot == objectType) {
      CCLOG(@"Creating the Alien Robot");
      EnemyRobot *enemyRobot =  [[EnemyRobot alloc] initWithSpriteFrameName:@"an1_anim1.png"];
        [enemyRobot setCharacterHealth:initialHealth];
        [enemyRobot setPosition:spawnLocation];
        [enemyRobot changeState:kStateSpawning];
        [sceneSpriteBatchNode addChild:enemyRobot z:ZValue];
        [enemyRobot setDelegate:self];
        [enemyRobot release];
    } else if (kEnemyTypeSpaceCargoShip == objectType) {
    ......
 

创建了enemy后,它的状态会是 kStateSpawning




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值