Exemplo n.º 1
0
void EnemyAI::addTank(float delta) {
    
    static float deltaTimes = 0.0f;
    deltaTimes += delta;
    if(deltaTimes >= 2.0f) {
        
        deltaTimes = 0.0f;
        int count = mEnemyTanks->count();
       
        if (count < 3)   //先从固定位置添加三个坦克
        {
            Tank* enemyTank = Tank::createTankWithTankType(enemyTankType[count], mTileMapInfo);
            enemyTank->setPosition(bornPoint[count]);
            enemyTank->setRotation(180.0f);
            mEnemyTanks->addObject(enemyTank);
        }else if(count == 3) {
            
            int tankTypeIndex = (int)(CCRANDOM_0_1() * 4) % 3;
            Tank* enemyTank = Tank::createTankWithTankType(enemyTankType[tankTypeIndex], mTileMapInfo);
            enemyTank->setPosition(bornPoint[tankTypeIndex]);
            enemyTank->setRotation(180.0f);
            mEnemyTanks->addObject(enemyTank);
        }
        
    }
    
    
    
}
Exemplo n.º 2
0
void Protocol::ReceiveTankPosition(QByteArray array)
{
    struct PTankData *data;
    data = (struct PTankData *) array.data();
    Tank* t = scene->getTank(data->id);
    t->setPos(data->x, data->y);
    t->setRotation(data->angle);
    t->setSendValue(false);

    if(data->move_up == 1) {
        t->MoveFoward(true);
    } else {
        t->MoveFoward(false);
    }

    if(data->move_right == 1) {
        t->RotateRight(true);
    } else {
        t->RotateRight(false);
    }

    if(data->move_left == 1) {
        t->RotateLeft(true);
    } else {
        t->RotateLeft(false);
    }

    if(data->fire_on == 1) {
        t->Fire();
    }
}
Exemplo n.º 3
0
void Protocol::ReceiveMap(QByteArray array)
{
    struct PTankMap *pmap;
    pmap = (struct PTankMap *) array.data();
    for(int i=0; i<pmap->total_tank; i++) {
        struct PTankData *ptdata;
        ptdata = &(pmap->tanks[i]);
        if(pmap->total_tank > scene->NumTankOnGame()) {
            scene->CreateTank(QPointF(ptdata->x, ptdata->y),
                       ptdata->angle);
        } else {
            if(ptdata->id != scene->id_tank) {
                Tank *t = scene->getTank(i);
                t->setPos(ptdata->x, ptdata->y);
                t->setRotation(ptdata->angle);

                if(ptdata->move_up == 1) {
                    t->MoveFoward(true);
                } else {
                    t->MoveFoward(false);
                }

                if(ptdata->move_right == 1) {
                    t->RotateRight(true);
                } else {
                    t->RotateRight(false);
                }

                if(ptdata->move_left == 1) {
                    t->RotateLeft(true);
                } else {
                    t->RotateLeft(false);
                }
                if(ptdata->fire_on == 1) {
                    t->Fire();
                }

            }
        }
    }
    if(!scene->HasControl()) {
        scene->CreateControls(pmap->total_tank-1);
    }
}