[11898] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[11984] | 23 | * Marc Dreher |
---|
[11898] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file 3DPacman.cc |
---|
| 31 | @brief Implementation of the 3DPacman class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "Pacman.h" |
---|
| 35 | #include "core/CoreIncludes.h" |
---|
| 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
[11915] | 39 | RegisterClass(Pacman); |
---|
[11898] | 40 | |
---|
[12313] | 41 | int PACMAN_INTERNAL_PACMAN_POSITION; |
---|
| 42 | |
---|
[11898] | 43 | Pacman::Pacman(Context* context) : Deathmatch(context) |
---|
| 44 | { |
---|
| 45 | RegisterObject(Pacman); |
---|
| 46 | |
---|
[11978] | 47 | lives = 3; |
---|
[11898] | 48 | point = 0; |
---|
| 49 | level = 1; |
---|
[12381] | 50 | laser = 5; //after that number of eaten pointSpheres, the laser appears |
---|
[11898] | 51 | |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void Pacman::levelUp() |
---|
| 55 | { |
---|
[11984] | 56 | //Reset each object |
---|
[11958] | 57 | for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ |
---|
| 58 | nextsphere->resetPacmanPointSphere(); |
---|
| 59 | } |
---|
| 60 | |
---|
[12389] | 61 | |
---|
| 62 | PacmanLaser* pos = *(ObjectList<PacmanLaser>().begin()); |
---|
| 63 | pos->resetPacmanLaser(); |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
[11958] | 67 | for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){ |
---|
| 68 | next->resetPacmanPointAfraid(); |
---|
| 69 | } |
---|
| 70 | |
---|
[11984] | 71 | //Level up ghosts |
---|
[11958] | 72 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
| 73 | nextghost->levelupvelo(); |
---|
| 74 | } |
---|
[11984] | 75 | //Reset ghosts and player |
---|
[11958] | 76 | this->posreset(); |
---|
[11979] | 77 | |
---|
[11984] | 78 | //Increase maximum of points and level |
---|
[11979] | 79 | totallevelpoint = ObjectList<PacmanPointSphere>().size() + totallevelpoint; |
---|
| 80 | level++; |
---|
[11898] | 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
[12316] | 84 | PacmanGhost* ghosts[8]; |
---|
[11898] | 85 | |
---|
| 86 | |
---|
| 87 | void Pacman::tick(float dt) |
---|
| 88 | { |
---|
[12316] | 89 | |
---|
[11915] | 90 | SUPER(Pacman, tick, dt); |
---|
| 91 | |
---|
[12316] | 92 | |
---|
[11984] | 93 | //Needed for gameover |
---|
[11976] | 94 | if(deathtime != 0){ |
---|
| 95 | dead(dt); |
---|
[12365] | 96 | |
---|
[12380] | 97 | |
---|
| 98 | |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | //ingame loop |
---|
| 102 | else{ |
---|
[12381] | 103 | |
---|
| 104 | //support by laser |
---|
[12389] | 105 | if(point > laser + 240*(level-1)){ |
---|
[12365] | 106 | |
---|
| 107 | for(PacmanPointSphere* pointer : ObjectList<PacmanPointSphere>()){ |
---|
[12380] | 108 | Vector3 pointSpherePosition = pointer->getPosition(); |
---|
[12365] | 109 | |
---|
[12381] | 110 | if(pointSpherePosition.y > 0){// pointSphere above surface =not eaten yet |
---|
[12380] | 111 | |
---|
| 112 | PacmanLaser* pos = *(ObjectList<PacmanLaser>().begin()); |
---|
[12365] | 113 | pos->setPosition(pointSpherePosition); |
---|
| 114 | break; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | } |
---|
[11954] | 121 | |
---|
[11984] | 122 | //Register ghosts |
---|
| 123 | int i = 0; |
---|
[12365] | 124 | for(PacmanGhost* nextghost: ObjectList<PacmanGhost>()){ |
---|
[11984] | 125 | ghosts[i] = nextghost; |
---|
| 126 | i++; |
---|
[11939] | 127 | } |
---|
[11984] | 128 | //Switch ghost to not-catchable, if timer is zero |
---|
| 129 | if(afraid){ |
---|
| 130 | timer = timer - dt; |
---|
| 131 | if(timer<=0){ |
---|
| 132 | setNormal(); |
---|
| 133 | } |
---|
| 134 | } |
---|
[11976] | 135 | |
---|
[11984] | 136 | //Get position of player |
---|
| 137 | player = this->getPlayer(); |
---|
| 138 | if (player != nullptr) |
---|
| 139 | { |
---|
| 140 | currentPosition = player->getWorldPosition(); |
---|
| 141 | } |
---|
[11898] | 142 | |
---|
[11984] | 143 | //Check for collision with ghosts |
---|
| 144 | bcolli = false; |
---|
| 145 | for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){ |
---|
| 146 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
| 147 | } |
---|
[11898] | 148 | |
---|
[11984] | 149 | if(bcolli){ |
---|
| 150 | this->catched(dt); |
---|
| 151 | } |
---|
[11915] | 152 | |
---|
[11984] | 153 | //Check for collision with PointSpheres and PacmanPointAfraid |
---|
| 154 | for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ |
---|
[12003] | 155 | if(nextsphere->taken(currentPosition)) |
---|
| 156 | takePoint(nextsphere); |
---|
[11898] | 157 | } |
---|
| 158 | |
---|
[11984] | 159 | for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){ |
---|
| 160 | if(next->taken(currentPosition)) |
---|
| 161 | setAfraid(); |
---|
[11933] | 162 | } |
---|
| 163 | |
---|
[11979] | 164 | } |
---|
[11976] | 165 | |
---|
[11898] | 166 | } |
---|
| 167 | |
---|
[11984] | 168 | //Check for collisions between to objects (compare float numbers) |
---|
[11898] | 169 | bool Pacman::collis(Vector3 one, Vector3 other){ |
---|
[12338] | 170 | if((abs(one.x-other.x)<19) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<19)) |
---|
[11898] | 171 | return true; |
---|
| 172 | return false; |
---|
| 173 | } |
---|
| 174 | |
---|
[11984] | 175 | //Decrease live or resetghost |
---|
[11976] | 176 | void Pacman::catched(float dt){ |
---|
[11933] | 177 | |
---|
[11984] | 178 | if(!this->afraid) { |
---|
| 179 | if(!this->lives){ |
---|
[11976] | 180 | deathtime = 5; |
---|
| 181 | this->dead(dt); |
---|
| 182 | } |
---|
[11898] | 183 | --lives; |
---|
| 184 | this->posreset(); |
---|
[11933] | 185 | } |
---|
| 186 | else{ |
---|
[11945] | 187 | for(int nrghost = 0; nrghost<8; ++nrghost){ |
---|
[11984] | 188 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
| 189 | if(bcolli) ghosts[nrghost]->resetGhost(); |
---|
| 190 | bcolli = false; |
---|
[11933] | 191 | } |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
[11984] | 195 | //Change ghost design (to afraid) |
---|
[11944] | 196 | void Pacman::setAfraid(){ |
---|
[11945] | 197 | |
---|
[11944] | 198 | timer = 10; //Set timer to 10 seconds |
---|
[11945] | 199 | |
---|
| 200 | //Change normal Ghosts with afraid ones |
---|
| 201 | if(!afraid){ |
---|
| 202 | ghosts[0]->changewith(ghosts[4]); |
---|
| 203 | ghosts[1]->changewith(ghosts[5]); |
---|
| 204 | ghosts[2]->changewith(ghosts[6]); |
---|
| 205 | ghosts[3]->changewith(ghosts[7]); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | afraid = true; |
---|
[11898] | 209 | } |
---|
| 210 | |
---|
[11984] | 211 | //Change ghost design (to not afraid) |
---|
[11945] | 212 | void Pacman::setNormal(){ |
---|
| 213 | |
---|
| 214 | timer = 0; |
---|
| 215 | |
---|
| 216 | //Change normal Ghosts with afraid ones |
---|
| 217 | ghosts[4]->changewith(ghosts[0]); |
---|
| 218 | ghosts[5]->changewith(ghosts[1]); |
---|
| 219 | ghosts[6]->changewith(ghosts[2]); |
---|
| 220 | ghosts[7]->changewith(ghosts[3]); |
---|
| 221 | |
---|
| 222 | afraid = false; |
---|
| 223 | } |
---|
| 224 | |
---|
[11984] | 225 | //Reset ghosts and plazer |
---|
[11898] | 226 | void Pacman::posreset(){ |
---|
[11956] | 227 | for(int i = 0; i<4; ++i){ |
---|
| 228 | ghosts[i]->resetGhost(); |
---|
[11898] | 229 | } |
---|
| 230 | player->setPosition(startposplayer); |
---|
| 231 | } |
---|
| 232 | |
---|
[11984] | 233 | //Collision with PointSphere |
---|
[11898] | 234 | void Pacman::takePoint(PacmanPointSphere* taken){ |
---|
| 235 | ++point; |
---|
[12380] | 236 | |
---|
[11979] | 237 | if(point == totallevelpoint){ |
---|
| 238 | this->levelUp(); |
---|
| 239 | return; |
---|
| 240 | } |
---|
[11898] | 241 | } |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | PacmanGelb* Pacman::getPlayer() |
---|
| 245 | { |
---|
| 246 | for (PacmanGelb* ship : ObjectList<PacmanGelb>()) |
---|
| 247 | { |
---|
| 248 | return ship; |
---|
| 249 | } |
---|
| 250 | return nullptr; |
---|
| 251 | } |
---|
| 252 | |
---|
[11984] | 253 | //Getter |
---|
| 254 | bool Pacman::getAfraid(){ |
---|
| 255 | return afraid; |
---|
| 256 | } |
---|
| 257 | //Getter |
---|
| 258 | int Pacman::getTimer(){ |
---|
| 259 | return timer; |
---|
| 260 | } |
---|
| 261 | //Getter |
---|
| 262 | int Pacman::getLevel(){ |
---|
| 263 | return level; |
---|
| 264 | } |
---|
| 265 | //Getter |
---|
[11898] | 266 | int Pacman::getPoints(){ |
---|
| 267 | return point; |
---|
| 268 | } |
---|
[11984] | 269 | //Getter |
---|
[11978] | 270 | int Pacman::getLives(){ |
---|
| 271 | return lives; |
---|
| 272 | } |
---|
[11984] | 273 | //Getter |
---|
| 274 | bool Pacman::isdead(){ |
---|
| 275 | return death; |
---|
| 276 | } |
---|
[11992] | 277 | //Getter |
---|
| 278 | int Pacman::getTotalpoints(){ |
---|
| 279 | return totallevelpoint; |
---|
| 280 | } |
---|
[11898] | 281 | |
---|
[11978] | 282 | |
---|
[11898] | 283 | void Pacman::start() |
---|
| 284 | { |
---|
| 285 | Deathmatch::start(); |
---|
[11954] | 286 | |
---|
[11984] | 287 | //Hide afraided ghosts under map |
---|
[11954] | 288 | int i = 0; |
---|
| 289 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
| 290 | if(3<i){ |
---|
| 291 | nextghost->setPosition(0,-20,0); |
---|
| 292 | nextghost->dontmove = true; |
---|
| 293 | }; |
---|
| 294 | i++; |
---|
| 295 | } |
---|
[11956] | 296 | |
---|
[11984] | 297 | //Set maximum of points of first level |
---|
[11956] | 298 | totallevelpoint = ObjectList<PacmanPointSphere>().size(); |
---|
| 299 | |
---|
[11898] | 300 | } |
---|
| 301 | |
---|
[11976] | 302 | void Pacman::dead(float dt){ |
---|
| 303 | death = true; |
---|
| 304 | |
---|
| 305 | deathtime = deathtime-dt; |
---|
| 306 | |
---|
| 307 | if(deathtime<0) |
---|
| 308 | this->end(); |
---|
| 309 | } |
---|
| 310 | |
---|
[11898] | 311 | void Pacman::end() |
---|
| 312 | { |
---|
| 313 | GSLevel::startMainMenu(); |
---|
| 314 | } |
---|
[12380] | 315 | } |
---|