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