Exemplo n.º 1
0
void EnemyAI::tankAction(float delta) {
    
    CCObject* pObj;
    
    // int nCount = 0;
    CCARRAY_FOREACH(mEnemyTanks, pObj){
        
        Tank* tank = (Tank*)pObj;
        
        //坦克自动移动,碰到墙壁自动换方向  
        int Rotation = tank->getRotation();
       //  printf("this:com:%d",Rotation);
        // 须要修改
      //    printf("com:%d\n",Rotation / 90 + 1);
        
        tank->command((enumOrder)(Rotation / 90 + 1));
        
        /*
        if(nCount == 0) {
            printf("com:%d\n",Rotation / 90 + 1);
             printf("ro:%d\n",Rotation);
        }
        nCount++;
        */
        //printf("%d\n",Rotation / 90 + 1);
        
        /*
        if (!tank->command((enumOrder)(Rotation / 90 + 1)))
        {
            int n = (int)(CCRANDOM_0_1() * 5) % 5;
            if (n != 0)
                tank->command((enumOrder)n);
        }
        */
        
        //每隔一秒开一次火 
        tank->setBulletDelta(tank->getBulletDelta()+ delta);
        if (tank->getBulletDelta() > 1)
        {
            //开火后,如果子弹在飞行中,归零计时
            if (tank->command(cmdFire))
            {
                tank->setBulletDelta(0.0);
            }
        }
        
        //检测坦克之间的碰撞
        
        
        
        //如果坦克阻塞,换个方向
        
        /*
        f (tank->getBlock())
            tank->setRotation((int)(CCRANDOM_0_1() * 3.2) * 90);
         */
        
        //如果上面的判断完成后,坦克根据自己的阻塞状态移动
        
         // tank->move();
        
        
    }