- Timestamp:
- Apr 12, 2018, 4:12:25 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/Pacman/3DPacman.cc
r11844 r11859 34 34 #include "3DPacman.h" 35 35 #include "core/CoreIncludes.h" 36 #include "PacmanGelb.h" 37 #include "PacmanGhost.h" 38 #include "PacmanPointSphere.h" 36 39 37 40 namespace orxonox … … 43 46 RegisterObject(3DPacman); 44 47 45 bEndGame = false;46 lives = 1;48 lives = 3; 49 point = 0: 47 50 level = 1; 48 point = 0;49 bShowLevel = false;50 multiplier = 1;51 b_combo = false;52 counter = 5000;53 pattern = 1;54 lastPosition = 0;55 // spawn enemy every 3.5 seconds56 //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this)));57 comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this)));58 this->numberOfBots_ = 0; //sets number of default bots temporarly to 059 this->center_ = nullptr;60 51 61 this->setHUDTemplate("DodgeRaceHUD");62 52 } 63 53 64 void DodgeRace::levelUp()54 void 3DPacman::levelUp() 65 55 { 66 level++; 67 if (getPlayer() != nullptr) 68 { 69 for (int i = 0; i < 7; i++) 70 { 71 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); 72 chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); 73 chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() 74 chunk5->setScale(10); 75 chunk5->setEffect1("Orxonox/explosion2b"); 76 chunk5->setEffect2("Orxonox/smoke6"); 77 chunk5->Explode(); 78 79 } 80 } 81 addPoints(multiplier * 42); 82 multiplier *= 2; 83 toggleShowLevel(); 84 showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this))); 56 this->end(); 85 57 } 86 58 87 void DodgeRace::tick(float dt) 59 60 PacmanGhost[4] ghosts; 61 PacmanPointSphere[1] spheres; 62 63 64 void 3DPacman::tick(float dt) 88 65 { 89 DodgeRaceShip* player = this->getPlayer(); 66 int i = 0; 67 for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ 68 ghosts[i] = nextghost; 69 i++; 70 } 71 72 i = 0: 73 for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ 74 spheres[i] = nextsphere; 75 i++; 76 } 77 78 player = this->getPlayer(); 90 79 if (player != nullptr) 91 80 { 92 currentPosition = player->getWorldPosition().x; 93 counter = counter + (currentPosition - lastPosition); 94 lastPosition = currentPosition; 95 point = (int) currentPosition; 96 player->speed = 830.0f - (point / 1000); 81 currentPosition = player->getWorldPosition(); 82 } 97 83 98 for(unsigned int i=0; i < cubeList.size();i++) 99 { 100 if(cubeList.at(i)->getPosition().x < currentPosition-3000) 101 { 102 cubeList.at(i)->destroy(); 103 cubeList.erase(cubeList.begin()+i); 104 } 105 } 84 bool bcolli = false; 85 for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){ 86 bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition) 87 } 88 if(collis){ 89 this->catched(); 90 } 106 91 107 if(counter >= 3000) 108 { 109 counter = 0; 110 for(int i = 0; i<6; i++) 111 { 112 DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext()); 113 cubeList.push_back(cube); 114 switch(pattern) 115 { 116 case 1: cube->addTemplate("DodgeRaceCube01"); 117 break; 118 case 2: cube->addTemplate("DodgeRaceCube02"); 119 break; 92 SUPER(3DPacman, tick, dt); 120 93 121 } 122 123 cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200))); 124 //stEntity->setScale3D(50,50,50); 125 } 94 } 126 95 127 96 128 pattern %= 2;129 pattern ++;130 97 131 }132 133 }134 SUPER(DodgeRace, tick, dt);98 bool 3DPacman::collis(Vector3 one, Vector3 other){ 99 if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1)) 100 return true; 101 return false; 135 102 } 136 103 137 DodgeRaceShip* DodgeRace::getPlayer() 104 void 3DPacman::catched(){ 105 if(lives) this->end(); 106 --lives; 107 this->posreset(); 108 } 109 110 void 3DPacman::posreset(){ 111 int i = 0; 112 for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ 113 ghosts[i] = nextghost; 114 i++; 115 } 116 117 } 118 119 120 PacmanGelb* 3DPacman::getPlayer() 138 121 { 139 for ( DodgeRaceShip* ship : ObjectList<DodgeRaceShip>())122 for (PacmanGelb* ship : ObjectList<PacmanGelb>()) 140 123 { 141 124 return ship; … … 144 127 } 145 128 146 void DodgeRace::costLife()147 {148 //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this)));149 lives = 0;150 };151 129 152 void DodgeRace::comboControll() 153 { 154 if (b_combo) 155 multiplier++; 156 // if no combo was performed before, reset multiplier 157 else 158 multiplier = 1; 159 b_combo = false; 160 } 161 162 void DodgeRace::start() 130 void 3DPacman::start() 163 131 { 164 132 orxout() << "start" << endl; 165 for(unsigned int i=0; i< cubeList.size();i++) 166 { 167 cubeList.at(i)->destroy(); 168 cubeList.erase(cubeList.begin()+i); 169 170 } 171 cubeList.clear(); 172 // Set variable to temporarily force the player to spawn. 173 this->bForceSpawn_ = false; 174 175 if (this->center_ == nullptr) // abandon mission! 176 { 177 orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl; 178 GSLevel::startMainMenu(); 179 return; 180 } 181 // Call start for the parent class. 133 182 134 Deathmatch::start(); 183 135 } 184 136 185 void DodgeRace::playerPreSpawn(PlayerInfo* player)137 void 3DPacman::playerPreSpawn(PlayerInfo* player) 186 138 { 187 139 this->playerInfo_ = player; … … 190 142 this->end(); 191 143 } 192 193 // Reset all the cubes194 /*195 orxout() << "prespawn" << endl;196 for(int i=0; i< cubeList.size();i++)197 {198 cubeList.at(i)->destroy();199 cubeList.erase(cubeList.begin()+i);200 }201 cubeList.clear();202 lives = 1;203 point = 0;204 lastPosition = 0;205 */206 144 } 207 145 208 void DodgeRace::addPoints(int numPoints)209 {210 if (!bEndGame)211 {212 point += numPoints * multiplier;213 b_combo = true;214 }215 }216 146 217 void DodgeRace::end()147 void 3DPacman::end() 218 148 { 219 149 // DON'T CALL THIS! … … 224 154 { 225 155 int score = this->getPoints(); 226 Highscore::getInstance().storeScore(" Dodge Race", score, this->playerInfo_);156 Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); 227 157 } 228 158 GSLevel::startMainMenu();
Note: See TracChangeset
for help on using the changeset viewer.