void World::startVideo() { QSound::play("data/menu.wav"); Wall *base = new Wall(2); _playerBase = base; Tank *tank = new Tank; _playerTank = tank; _enemyLife = 0; _playerLife = 0; tank = new Tank; tank->setPos(QPoint(225,450)); tank->setTeam(0); tank->move(true); tank->setSpeed(3); _tankList.append(tank); tank = new Tank; tank->setPos(QPoint(175,510)); tank->setTeam(1); tank->move(true); tank->setSpeed(2); _tankList.append(tank); tank = new Tank; tank->setPos(QPoint(245,510)); tank->setTeam(1); tank->move(true); tank->setSpeed(2); _tankList.append(tank); _isVideo = true; }
void World::update() { if (_playerBase == nullptr) { gameOver(); } else if (_playerTank == nullptr) { if (_playerLife > 0) { _playerLife--; Tank *tank = new Tank; tank->setPos(_spawnPos[0]); _playerTank = tank; _tankList.append(tank); } else { gameOver(); } } else if (_tankList.size() < 3) { if (_enemyLife > 0) { _enemyLife--; Tank *tank = new Tank; tank->setTeam(1); tank->setPos(_spawnPos[_tankList.size()]); tank->setAngle(2); _tankList.append(tank); } } if (_isVideo) { playVideo(); } else { moveBots(); } updateTanks(); moveBullets(); }
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); } }
void World::playVideo() { if (_tankList.size() == 3) { _other++; if (_other % 30 == 0) { fire(_tankList[1]); } else if (_other % 51 == 0) { fire(_tankList[2]); } } else if (_tankList.size() == 2 & _other > 0 & _other < 1000) { _tankList[0]->move(false); _tankList[1]->move(false); _tankList[0]->rotate(3); _tankList[1]->rotate(1); _other = 0; } else if (_tankList.size() == 2 &_other == 0) { _other = -1; for (int q = 0; q < 8; q ++) { Tank *tank = new Tank; tank->setPos(QPoint(q * 50 + 12 * q + 6,-50)); tank->setTeam(0); tank->setAngle(2); tank->setSpeed(1); tank->move(true); _tankList.append(tank); } } else if (_other <= -1 & _other > -50) { _other--; } else if (_other == -50) { _other--; _tankList[0]->setAngle(2); _tankList[1]->setAngle(2); _tankList[0]->move(true); _tankList[1]->move(true); } else if (_other <= -51 & _tankList.size() == 10) { _other--; if (_other % 50 == 0) { for (int q = 0 ; q < 8; q ++) { fire(_tankList[q + 2]); } } } else if ( _tankList.size() == 8 & _other < 0) { Tank *tank = new Tank; tank->setTeam(2); tank->setPos(QPoint(156, - 70)); tank->setAngle(2); tank->setSpeed(1); tank->setSize(0); tank->move(true); _tankList.append(tank); } else if (_tankList.size() == 9 & _other < 0) { if (_tankList[8]->getPos().y() == 216) { _tankList[8]->move(false); _other = 0; } } else if (_tankList.size() == 9 & _other >= 0) { _other++; if (_other == 625) { for (int q = 0; q < _tankList.size() - 1; q++) { delete _tankList[0]; } _tankList.remove(0,8); for (int q = 0; q < 8; q ++) { Tank *tank = new Tank; tank->setPos(QPoint(-50,q * 50 + 12 * q + 6)); tank->setTeam(0); tank->setAngle(1); tank->setSpeed(rand() % 4 + 1); tank->move(true); _tankList.append(tank); } for (int q = 0; q < 8; q ++) { Tank *tank = new Tank; tank->setPos(QPoint(550,q * 50 + 12 * q + 6)); tank->setTeam(1); tank->setAngle(3); tank->setSpeed(rand() % 4 + 1); tank->move(true); _tankList.append(tank); } _other = 1000; } } else if (_other == 1000 & _tankList.size() != 1) { for (int q = 1; q < _tankList.size(); q ++) { int f = rand() % 2; if (f == 1) { fire(_tankList[q]); } } } else if (_other >= 1000 & _tankList.size() == 1){ _other++; if (_other == 1100) { delete _playerBase; delete _playerTank; gameOver(); loadMission(0); _isVideo = false; } } }