[11844] | 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 "3DPacman.h" |
---|
| 35 | #include "core/CoreIncludes.h" |
---|
[11859] | 36 | #include "PacmanGelb.h" |
---|
| 37 | #include "PacmanGhost.h" |
---|
| 38 | #include "PacmanPointSphere.h" |
---|
[11844] | 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | RegisterUnloadableClass(3DPacman); |
---|
| 43 | |
---|
| 44 | 3DPacman::3DPacman(Context* context) : Deathmatch(context) |
---|
| 45 | { |
---|
| 46 | RegisterObject(3DPacman); |
---|
| 47 | |
---|
[11859] | 48 | lives = 3; |
---|
| 49 | point = 0: |
---|
[11844] | 50 | level = 1; |
---|
[11862] | 51 | Vector3 startposplayer = Vector3(0,10,245); |
---|
[11844] | 52 | |
---|
| 53 | } |
---|
| 54 | |
---|
[11859] | 55 | void 3DPacman::levelUp() |
---|
[11844] | 56 | { |
---|
[11859] | 57 | this->end(); |
---|
| 58 | } |
---|
[11844] | 59 | |
---|
[11859] | 60 | |
---|
| 61 | PacmanGhost[4] ghosts; |
---|
| 62 | PacmanPointSphere[1] spheres; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | void 3DPacman::tick(float dt) |
---|
| 66 | { |
---|
| 67 | int i = 0; |
---|
| 68 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
| 69 | ghosts[i] = nextghost; |
---|
| 70 | i++; |
---|
[11844] | 71 | } |
---|
| 72 | |
---|
[11859] | 73 | player = this->getPlayer(); |
---|
[11844] | 74 | if (player != nullptr) |
---|
| 75 | { |
---|
[11859] | 76 | currentPosition = player->getWorldPosition(); |
---|
| 77 | } |
---|
[11844] | 78 | |
---|
[11859] | 79 | bool bcolli = false; |
---|
| 80 | for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){ |
---|
| 81 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition) |
---|
| 82 | } |
---|
| 83 | if(collis){ |
---|
| 84 | this->catched(); |
---|
| 85 | } |
---|
[11844] | 86 | |
---|
[11862] | 87 | i = 0; |
---|
| 88 | for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ |
---|
| 89 | if(collis(nextsphere.getPosition(), currentPosition)){ |
---|
| 90 | takePoint(nextsphere); |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
[11859] | 94 | SUPER(3DPacman, tick, dt); |
---|
[11844] | 95 | |
---|
[11859] | 96 | } |
---|
[11844] | 97 | |
---|
| 98 | |
---|
[11859] | 99 | bool 3DPacman::collis(Vector3 one, Vector3 other){ |
---|
| 100 | if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1)) |
---|
| 101 | return true; |
---|
| 102 | return false; |
---|
| 103 | } |
---|
[11844] | 104 | |
---|
[11859] | 105 | void 3DPacman::catched(){ |
---|
[11862] | 106 | if(!lives) this->end(); |
---|
[11859] | 107 | --lives; |
---|
| 108 | this->posreset(); |
---|
| 109 | } |
---|
[11844] | 110 | |
---|
[11859] | 111 | void 3DPacman::posreset(){ |
---|
| 112 | int i = 0; |
---|
| 113 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
[11862] | 114 | nextghost.resetGhost(); |
---|
[11859] | 115 | i++; |
---|
[11844] | 116 | } |
---|
[11862] | 117 | player.setPosition(startposplayer); |
---|
[11844] | 118 | } |
---|
| 119 | |
---|
[11862] | 120 | void 3DPacman::takePoint(PacmanPointSphere* taken){ |
---|
| 121 | ++point; |
---|
| 122 | if(point == totallevelpoint) this->levelUp; |
---|
[11859] | 123 | |
---|
[11862] | 124 | Vector3 postaken = taken.getPosition(); |
---|
| 125 | postaken.y = -50; |
---|
| 126 | taken.setPosition(postaken); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
[11859] | 130 | PacmanGelb* 3DPacman::getPlayer() |
---|
[11844] | 131 | { |
---|
[11859] | 132 | for (PacmanGelb* ship : ObjectList<PacmanGelb>()) |
---|
[11844] | 133 | { |
---|
| 134 | return ship; |
---|
| 135 | } |
---|
| 136 | return nullptr; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[11859] | 140 | void 3DPacman::start() |
---|
[11844] | 141 | { |
---|
| 142 | orxout() << "start" << endl; |
---|
[11859] | 143 | |
---|
[11844] | 144 | Deathmatch::start(); |
---|
| 145 | } |
---|
| 146 | |
---|
[11859] | 147 | void 3DPacman::playerPreSpawn(PlayerInfo* player) |
---|
[11844] | 148 | { |
---|
| 149 | this->playerInfo_ = player; |
---|
| 150 | if(lives <= 0) |
---|
| 151 | { |
---|
| 152 | this->end(); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
[11859] | 157 | void 3DPacman::end() |
---|
[11844] | 158 | { |
---|
| 159 | if (Highscore::exists()) |
---|
| 160 | { |
---|
| 161 | int score = this->getPoints(); |
---|
[11859] | 162 | Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); |
---|
[11844] | 163 | } |
---|
| 164 | GSLevel::startMainMenu(); |
---|
| 165 | } |
---|
| 166 | } |
---|