void Game::updateBomb( int i) { Bomb *b = mapBombs[i]; b->nextSprite(); if( ( b->getStep() == 1 ) && ( SDL_GetTicks() >= b->getDateOfExplosion() - b->getDelay() / 2 ) ) { b->nextStep(); b->resetSprite(); } if( ( b->getStep() == 2 ) && ( SDL_GetTicks() >= b->getDateOfExplosion()) ) { b->nextStep(); b->resetSprite(); } if( ( b->getStep() == 3 ) ) { // Placement de l'explosion int x = b->getDimCoordEcranX(); int y = b->getDimCoordEcranY(); // Création d'une explosion à la place Explosion *e = new Explosion(x,y); // Ajout de l'explosion au Map correspondant mapExplosions.push_back(e); // Suppression de la bombe mapBombs.erase( mapBombs.begin() + i ); } }
void Stage::addBomb_e(Bomb &b){ mutex.lock(); b.setStage(this); m_bombs_e.push_back(b); mutex.unlock(); }
void BombCache::newOneInBuffer() { Bomb* bomb = new Bomb(true); bomb->autorelease(); bufferVec.insert(bufferVec.end(),bomb); }
GameObject * Player::GetBlockingGameObjectImmediatelyAboveAndToTheLeft() { GameObject * foundGameObject = 0; int playerLeft = this->GetCollisionBox().left; int playerTop = this->GetCollisionBox().top; foundGameObject = Universe::GetBlockAtPoint(playerLeft, playerTop - 1); if(!foundGameObject) { Bomb * foundBomb = Universe::GetBombAtPoint(playerLeft, playerTop - 1); if(foundBomb && !foundBomb->IsPlayerMovingOverAfterDropping(this)) { foundGameObject = foundBomb; } } return foundGameObject; }
GameObject * Player::GetBlockingGameObjectImmediatelyBelowAndToTheRight() { GameObject * foundGameObject = 0; int playerRight = this->GetCollisionBox().right; int playerBottom = this->GetCollisionBox().bottom; foundGameObject = Universe::GetBlockAtPoint(playerRight, playerBottom + 1); if(!foundGameObject) { Bomb * foundBomb = Universe::GetBombAtPoint(playerRight, playerBottom + 1); if(foundBomb && !foundBomb->IsPlayerMovingOverAfterDropping(this)) { foundGameObject = foundBomb; } } return foundGameObject; }
void Game::doDropBomb(Player *p) { // On vérifie que le joueur a au moins une bombe à poser if( p->getNbBomb() > 0 ) { // Instanciation d'une nouvelle bombe Bomb *b = new Bomb(); // Placement de la bombe aux coordonnées du joueur qui l'a posé int x = p->getDimCoordEcranX(); int y = p->getDimCoordEcranY() + p->getDimCoordSpriteH(); x = x - x % TILE_WIDTH; y = y - y % TILE_HEIGHT; b->setDimCoordEcranX(x); b->setDimCoordEcranY(y); // Décrémentation du nombre de bombes du joueur qui l'a posé p->dropBomb(); // Ajout de la bombe au Map correspondant mapBombs.push_back(b); } }
Bomb* SimpleStoresMgr::getNextBombImp() { Bomb* bomb = 0; Basic::PairStream* list = getWeapons(); if (list != 0) { Basic::List::Item* item = list->getFirstItem(); while (item != 0 && bomb == 0) { Basic::Pair* pair = (Basic::Pair*) item->getValue(); Bomb* p = dynamic_cast<Bomb*>( pair->object() ); if (p != 0) { if (p->isInactive() || p->isReleaseHold()) { bomb = (Bomb*) p->getPointer(); } } item = item->getNext(); } list->unref(); } return bomb; }
bool ArtificialPlayer::isDanger(std::vector<std::vector<AObject *> > &map, int x, int y) { for (unsigned int i = y; i > 0; --i) if (map[i][x]) { Bomb *bomb = dynamic_cast<Bomb *>(map[i][x]); if (bomb && bomb->getPower() >= y - i) return (true); break; } for (unsigned int i = x; i < map[y].size(); ++i) if (map[y][i]) { Bomb *bomb = dynamic_cast<Bomb *>(map[y][i]); if (bomb && bomb->getPower() >= i - x) return (true); break; } for (unsigned int i = y; i < map.size(); ++i) if (map[i][x]) { Bomb *bomb = dynamic_cast<Bomb *>(map[i][x]); if (bomb && bomb->getPower() >= i - y) return (true); break; } for (unsigned int i = x; i > 0; --i) if (map[y][i]) { Bomb *bomb = dynamic_cast<Bomb *>(map[y][i]); if (bomb && bomb->getPower() >= x - i) return (true); break; } return (false); }
int main() { start: vector<string> fileNames; //stores all the file names in the directory string dir_name = "./maps"; // current directory DIR *dir; struct dirent *ent; struct stat filestat; int i=1; // for warping, stores the warps positions int warpRow1[10]; int warpCol1[10]; int countOcc[10]; int warpRow2[10]; int warpCol2[10]; for(int a=0 ; a<10 ; a++) { warpRow1[a] = 10; warpCol1[a] = 10; countOcc[a] = 0; warpRow2[a] = 10; warpCol2[a] = 10; } int rows,columns,time; // to initialize the grid and world int play_row,play_col; // tracks player position int host = 0; // tracks number of hostages in the maze bool bombDeployed = false; // checks of bomb is deployed or not. value is true if deployed int deployedAtX, deployedAtY; // position of the bomb deployed on the maze // for counting the moves so that bomb can be exploded after 3 moves int count = 0; string move_choice; // to input the moves of the user ifstream gameMap; World myWorld; Grid myGrid; Player *player = new Player(); int choice; cout<<"Welcome to the 'Hostage Rescue' game. Press enter to continue"<<endl; start1: cin.clear(); cin.ignore(); cout<<"________________________________________"<<endl; cout<<"Welcome to the well-made game"<<endl; cout<<"----------------------------------------"<<endl; cout<<"1. Load the maze"<<endl; cout<<"2. Help" <<endl; cout<<"3. About"<<endl; cout<<"_________________________________________"<<endl; cin>>choice; cout<<endl; if(choice == 1) { int maze_choice; cout<<"__________________________________________________________________"<<endl; cout<<"Load the maze menu. select your maze "<<endl; cout<<"------------------------------------------------------------------"<<endl; if ((dir = opendir (dir_name.c_str())) != NULL) { /* print all the files and directories within directory */ cout << "Printing all the files in current directory..." << endl << endl; while ((ent = readdir (dir)) != NULL) { // Skip the file if it is invalid or it is a directory string filepath = dir_name + "/" + ent->d_name; if (stat( filepath.c_str(), &filestat )) continue; if (S_ISDIR( filestat.st_mode )) continue; cout << i<<")"<<ent->d_name << endl; i++; fileNames.push_back(ent->d_name); // storing in the vector } closedir (dir); } else { /* could not open directory */ cerr << strerror(errno) << endl; return EXIT_FAILURE; } cout<<"__________________________________________________________________"<<endl; cin>>maze_choice; //Loading the required level form maps folder for(int j=0 ; j<fileNames.size() ; j++) { if(j == maze_choice-1) { string fileName = ".\\maps\\"+fileNames.at(j); gameMap.open(fileName.c_str()); } } // check bounds of file if(gameMap.fail()) { cout << "error opening the file" << endl; exit(1); } else { // taking the rows and column of the grid as well as the maximum moves a player can //make in the form of time gameMap >> rows >> columns >> time; // declaring a 2-d array to store the map char **map = new char*[rows]; // storing the entire maze on the grid from the map array for(int i=0; i<rows; i++) { map[i] = new char[columns]; } char ch = gameMap.get(); // Initialising the map to declared 2-d array for (int r=0; r<rows; r++) { int c=0; char ch = gameMap.get(); while(ch!='\n' && !gameMap.eof()) { map[r][c] = ch; c++; ch = gameMap.get(); } } gameMap.close(); // creating a world object and initialising its rows, columns and time-limit values myWorld.setTime(time); myWorld.setMaxTime(time); // creating the required grid myGrid.setGridSize(rows,columns); // reading the map point by point for(int i=0 ; i<rows ; i++) { for(int j=0 ; j<columns ; j++) { // positioning the actors and putting them onto the grid if(map[i][j] == 'X') { Wall *wall = new Wall(); wall->setGrid(&myGrid); myGrid.getLocation(i, j)->setWall(wall); } else if(map[i][j] == 'B') { Box *box = new Box(); box->setGrid(&myGrid); myGrid.getLocation(i, j)->setBox(box); } else if(map[i][j] == 'o') { Bomb *bomb = new Bomb() ; bomb->setGrid(&myGrid); myGrid.getLocation(i, j)->setBomb(bomb); } else if(map[i][j] == 'E') { Exit *exitt = new Exit() ; exitt->setGrid(&myGrid); myGrid.getLocation(i, j)->setExit(exitt); } else if(map[i][j] == 'P') { myGrid.getLocation(i, j)->setPlayer(player); play_row = i; play_col = j; player->setGrid(&myGrid); player->setLocation(i,j); } else if(map[i][j] == 'H') { Hostage *hostage = new Hostage(); hostage->setGrid(&myGrid); myGrid.getLocation(i, j)->setHost(hostage); host++; } else if(map[i][j] == '.') { EmptySpace *emptyspace = new EmptySpace(); emptyspace->setGrid(&myGrid); myGrid.getLocation(i, j)->setEmptySpace(emptyspace); } else { Warp *warp = new Warp(map[i][j]); warp->setSymbol(map[i][j]); warp->setGrid(&myGrid); myGrid.getLocation(i, j)->setWarp(warp); if(countOcc[map[i][j] - '0'] > 0) { warpRow2[map[i][j] - '0'] = i; warpCol2[map[i][j] - '0'] = j; } else { warpRow1[map[i][j] - '0'] = i; warpCol1[map[i][j] - '0'] = j; } countOcc[map[i][j] - '0']++; } } } myGrid.display(cout); for(int t=0;t<10;t++) { if(countOcc[t]>0) { Warp *warp = new Warp(); warp->setSymbol(t+'0'); warp->setsrcRow(warpRow1[t]); warp->setsrcCol(warpCol1[t]); warp->setdestRow(warpRow2[t]); warp->setdestCol(warpCol2[t]); player->setWarps(warp); } } myWorld.setGrid(&myGrid); // setting the grid on the world // intitializing the status of the game myWorld.setTime(time); myWorld.setMoves(0); myWorld.setPlayer(player); player->setBombCollected(0); player->setMaxBomb(3); player->setHostRemain(host); player->setHostRescued(0); } }
void Player::update(float dt) { Global *global = Global::getInstance(); if (global->getInstance()->_playerObj != this) { return; } int a = global->multiBtn->getDirValue(); float angle = a; // log("----->%f %f %f", global->hitPosition.x, global->hitPosition.y, global->hitPosition.z); float rotation = calAngle(); this->setPlayerAngle(a); // log("-------> %f", rotation); // log("-----------> %f %f %f", barrelV.x, barrelV.y, barrelV.z); // rotation = rotation + 180 -90; if (global->multiBtn->getIsFired()) { this->setIsFired(global->multiBtn->getIsFired());////////////////////////////////////////// Bomb *bomb = Bomb::create(); m_curBomb = bomb; Physics3DRigidBodyDes rbDes; // rbDes.originalTransform.translate(global->_camera->getPosition3D()); rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createSphere(0.5f); Vec3 start = m_tank->getPosition3D(); bomb->set3DParams("model/box.c3t", "Icon.png", &rbDes, start, 0.5f); bomb->setRigidParams(Vec3::ONE, Vec3::ZERO, 0.5f, 0.4f); float l = 6.0f; float x0 = 0.0f, y0 = 0.0f, z0 = 0.0f; y0 = l * std::sin(angle * PI / 180); float l0 = l * std::cos(angle * PI / 180); x0 = start.x + l0 * std::sin(rotation * PI / 180); z0 = start.z + l0 * std::cos(rotation * PI / 180); Vec3 dir(x0, y0, z0);//方向向量 dir = dir - start; float power = 100; //power bomb->setDirAndPower(dir, power); bomb->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(bomb); ////////////////////////////////////////// global->multiBtn->setIsFired(false); } if (m_curBomb == nullptr) { return; } if (m_curBomb->getBombIsDead()) { setIsBombDidLanded(1); m_curBomb->setBombIsDead(0); // this->removeFromParent(); } }
int main(){ system("color 02"); Menu menuJeu; menuJeu.afficherMenuPrin(); // Instance Vaisseau Vaisseau monVaisseau; // Tableau Laser Laser mesLaser[MAX_LASER]; Bomb maBombe; int explosionDelay = 50; clock_t explosionTime = clock(); // Instance Martien //Martien MesMartiens1(2, 20); mesLaser[MAX_LASER].isAlive = false; for (int i = 0; i < MAX_LASER; i++){ mesLaser[i].isAlive = false; } // Chronometres Temps Laser Timer temps50(50); Timer temps100(100); Timer temps200(200); Timer temps300(300); while (true){ // Gestion des touches du jeux if (_kbhit() != 0) { char touche = _getch(); // Mouvement du vaisseau if (touche == 'l' || touche == 'k'){ if (touche == 'l' && monVaisseau.coord.getPositionX() < 40){ monVaisseau.modifierPosition(touche); } else if (touche == 'k' && monVaisseau.coord.getPositionX() > 0){ monVaisseau.modifierPosition(touche); } } // Trigger Laser if (touche == ' ' && !mesLaser[MAX_LASER].isAlive){ int i = 0; while (i < MAX_LASER && mesLaser[i].isAlive) i++; if (i < MAX_LASER) mesLaser[i].startLaser(monVaisseau.coord.getPositionX()); } // Trigger Bomb if (touche == 'a' && !maBombe.isAlive && !maBombe.isExploding){ maBombe.startLaser(monVaisseau.coord.getPositionX()); } // Explose Bomb if (touche == 's' && maBombe.isAlive){ maBombe.explosion(); } } // Gestion Temps Laser if (temps100.isReady()){ for (int i = 0; i < MAX_LASER; i++) mesLaser[i].moveLaser(); } // Gestion Temps de la bombe if (temps200.isReady()){ if (maBombe.isAlive){ maBombe.moveBomb(); } } // Gestion de l'explosion if (temps50.is){ explosionTime = clock(); maBombe.explosion(); } // Gestion du temps des martiens et du deplacement /* if (clock() >= martienTime + martienDelay){ martienTime = clock(); MesMartiens1.jiggleMartien(); } */ } return 0; }
void BombDropper::strike(Daniable*) { Bomb* bomb = NULL; if (this->getAmmo() > 0) { bomb = this->getAvailableBomb(); if (bomb != NULL) { this->ammo--; bomb->setStatus(EXPLOSIVE_EXPLOSION_COUNTDOWN); bomb->setOwner(this->getOwner()); bomb->setPosition(this->getPosition()); bomb->setDamage(this->getDamage()); bomb->setRectangle(bomb->getPosition(), bomb->getSprite() ); bomb->setDamage(this->getDamage()); bomb->startCountDown(5); bomb->setNeedsUpdate(true); //sendCreationAmmunition(bomb->serialize()); GameView::instance().getWorldView()->addAmmunition(bomb); } } }
int eventLoop(XInfo &xinfo, int start) { dList.push_front(new Text(xinfo.width/2 - 100, xinfo.height/2, "press space to start") ); XEvent event; unsigned long lastRepaint = 0; int small = 0; int left = 0; int right = 0; int up = 0; int down = 0; int pause = 0; int enable = 0; while(true) { if(XPending(xinfo.display) > 0 ) { XNextEvent(xinfo.display , &event); switch (event.type) { case KeyPress: handleKeyPress(xinfo, event,left,right,up,down,pause , start); enable = 1; break; case ConfigureNotify: handleResize(xinfo,event,small); break; } } //animation timing unsigned long end = now(); if ( end - lastRepaint > 1000000 / FPS ) { handleAnimation(xinfo, left, right , up , down , enable); int status = repaint(xinfo); if( status == 0 ) { enable = 0; cout << "land" << endl; dList.push_front(new Text(xinfo.width/2 - 100, 50, "YOU WIN") ); dList.push_front(new Text(xinfo.width/2 - 100, 100, "press \"SPACE\" to restart") ); dList.push_front(new Text(xinfo.width/2 - 100, 150, "press \"q\" to quit") ); status = repaint(xinfo); int p = 0; while ( p != 32 && p != 113) { XNextEvent(xinfo.display , &event); if(event.type == KeyPress) { p = (int) XLookupKeysym (&event.xkey, 0); } } if(p == 32) { return 1; } else { return 0; } } else if(status == 2) { enable = 0; bomb.reset(ship.getX(), ship.getY()); dList.push_front(&bomb); dList.push_front(new Text(xinfo.width/2 - 100, 50, "GAME OVER") ); dList.push_front(new Text(xinfo.width/2 - 100, 100, "press \"space\" to restart") ); dList.push_front(new Text(xinfo.width/2 - 100, 150, "press \"q\"to quit") ); status = repaint(xinfo); int p = 0; // 32 for space, 113 for "q" while ( p != 32 && p != 113) { XNextEvent(xinfo.display , &event); switch (event.type) { case KeyPress: p = (int) XLookupKeysym (&event.xkey, 0); case ConfigureNotify: break; } } if(p == 32) { return 1; } else { return 0; } } if(start == 3) { enable = 0; cout << "quit" << endl; return 0; } lastRepaint = now(); } //give the system time to do other things else if(XPending(xinfo.display) == 0 ) { usleep(1000000/FPS - (end - lastRepaint)); } } }