[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: |
---|
| 23 | * Florian Zinggeler |
---|
| 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 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[11915] | 40 | RegisterClass(Pacman); |
---|
[11898] | 41 | |
---|
| 42 | Pacman::Pacman(Context* context) : Deathmatch(context) |
---|
| 43 | { |
---|
| 44 | RegisterObject(Pacman); |
---|
| 45 | |
---|
[11931] | 46 | // firstGame = true; //needed for the HUD |
---|
[11915] | 47 | lives = 10; |
---|
[11898] | 48 | point = 0; |
---|
| 49 | level = 1; |
---|
| 50 | |
---|
[11931] | 51 | // setHUDTemplate("PacmanOrxHUD"); |
---|
| 52 | // scoreboardTemplate_ = ""; |
---|
[11898] | 53 | } |
---|
| 54 | |
---|
| 55 | void Pacman::levelUp() |
---|
| 56 | { |
---|
| 57 | this->end(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | PacmanGhost* ghosts[4]; |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | void Pacman::tick(float dt) |
---|
| 65 | { |
---|
[11915] | 66 | SUPER(Pacman, tick, dt); |
---|
| 67 | |
---|
[11898] | 68 | int i = 0; |
---|
| 69 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
| 70 | ghosts[i] = nextghost; |
---|
| 71 | i++; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | player = this->getPlayer(); |
---|
| 75 | if (player != nullptr) |
---|
| 76 | { |
---|
| 77 | currentPosition = player->getWorldPosition(); |
---|
| 78 | } |
---|
| 79 | |
---|
[11915] | 80 | |
---|
[11898] | 81 | bcolli = false; |
---|
| 82 | for(int nrghost = 0; (nrghost<3) && (!bcolli); ++nrghost){ |
---|
| 83 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
[11915] | 84 | //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl; |
---|
[11898] | 85 | } |
---|
[11915] | 86 | |
---|
[11898] | 87 | if(bcolli){ |
---|
[11915] | 88 | this->catched(); |
---|
[11898] | 89 | } |
---|
| 90 | |
---|
| 91 | i = 0; |
---|
| 92 | for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ |
---|
| 93 | if(collis(nextsphere->getPosition(), currentPosition)){ |
---|
| 94 | takePoint(nextsphere); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[11933] | 98 | for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){ |
---|
| 99 | if(collis(next->getPosition(), currentPosition)){ |
---|
| 100 | setAfraid(); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
[11898] | 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | bool Pacman::collis(Vector3 one, Vector3 other){ |
---|
[11931] | 108 | if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10)) |
---|
[11898] | 109 | return true; |
---|
| 110 | return false; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void Pacman::catched(){ |
---|
[11933] | 114 | |
---|
| 115 | if(!afraid) { |
---|
[11898] | 116 | if(!lives) this->end(); |
---|
| 117 | --lives; |
---|
| 118 | this->posreset(); |
---|
[11933] | 119 | } |
---|
| 120 | else{ |
---|
| 121 | |
---|
| 122 | for(int nrghost = 0; nrghost<3; ++nrghost){ |
---|
| 123 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
| 124 | if(bcolli) ghosts[nrghost]->resetGhost(); |
---|
| 125 | bcolli = false; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void setAfraid(){ |
---|
| 131 | afraid = true; |
---|
[11898] | 132 | } |
---|
| 133 | |
---|
| 134 | void Pacman::posreset(){ |
---|
| 135 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
| 136 | nextghost->resetGhost(); |
---|
| 137 | } |
---|
| 138 | player->setPosition(startposplayer); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | void Pacman::takePoint(PacmanPointSphere* taken){ |
---|
| 142 | ++point; |
---|
| 143 | if(point == totallevelpoint) this->levelUp(); |
---|
| 144 | Vector3 postaken = taken->getPosition(); |
---|
| 145 | postaken.y = -50; |
---|
| 146 | taken->setPosition(postaken); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | PacmanGelb* Pacman::getPlayer() |
---|
| 151 | { |
---|
| 152 | for (PacmanGelb* ship : ObjectList<PacmanGelb>()) |
---|
| 153 | { |
---|
| 154 | return ship; |
---|
| 155 | } |
---|
| 156 | return nullptr; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | int Pacman::getPoints(){ |
---|
| 160 | return point; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | void Pacman::start() |
---|
| 165 | { |
---|
| 166 | Deathmatch::start(); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | void Pacman::end() |
---|
| 171 | { |
---|
[11931] | 172 | /* |
---|
| 173 | firstGame = false; |
---|
| 174 | |
---|
| 175 | //Set randomized deathmessages |
---|
| 176 | if(point<7) sDeathMessage = DeathMessage7[rand()%(DeathMessage7.size())]; |
---|
| 177 | else if(point<20) sDeathMessage = DeathMessage20[rand()%(DeathMessage20.size())]; |
---|
| 178 | else if(point<30) sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())]; |
---|
| 179 | else sDeathMessage = DeathMessageover30[rand()%(DeathMessageover30.size())]; |
---|
| 180 | |
---|
| 181 | //Update Highscore |
---|
[11898] | 182 | if (Highscore::exists()) |
---|
| 183 | { |
---|
[11931] | 184 | int score = this->getPoints(); |
---|
| 185 | Highscore::getInstance().storeScore("Pacman", score, this->getPlayer()->getPlayer()); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | if (Highscore::exists()) |
---|
| 190 | { |
---|
[11898] | 191 | //int score = this->getPoints(); |
---|
| 192 | //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); |
---|
| 193 | } |
---|
[11931] | 194 | */ |
---|
[11898] | 195 | GSLevel::startMainMenu(); |
---|
| 196 | } |
---|
| 197 | } |
---|