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 | //Test |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | RegisterClass(Pacman); |
---|
41 | |
---|
42 | Pacman::Pacman(Context* context) : Deathmatch(context) |
---|
43 | { |
---|
44 | RegisterObject(Pacman); |
---|
45 | |
---|
46 | // firstGame = true; //needed for the HUD |
---|
47 | lives = 3; |
---|
48 | point = 0; |
---|
49 | level = 1; |
---|
50 | |
---|
51 | // setHUDTemplate("PacmanOrxHUD"); |
---|
52 | // scoreboardTemplate_ = ""; |
---|
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 | { |
---|
66 | SUPER(Pacman, tick, dt); |
---|
67 | |
---|
68 | //orxout() << timer << endl; |
---|
69 | //orxout() << afraid << endl; |
---|
70 | //orxout() << totallevelpoint << endl; |
---|
71 | |
---|
72 | |
---|
73 | if(afraid){ |
---|
74 | timer = timer - dt; |
---|
75 | if(timer<=0){ |
---|
76 | setNormal(); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | int i = 0; |
---|
81 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
82 | ghosts[i] = nextghost; |
---|
83 | i++; |
---|
84 | } |
---|
85 | |
---|
86 | player = this->getPlayer(); |
---|
87 | if (player != nullptr) |
---|
88 | { |
---|
89 | currentPosition = player->getWorldPosition(); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | bcolli = false; |
---|
94 | for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){ |
---|
95 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
96 | //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl; |
---|
97 | } |
---|
98 | |
---|
99 | if(bcolli){ |
---|
100 | this->catched(); |
---|
101 | } |
---|
102 | |
---|
103 | i = 0; |
---|
104 | for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ |
---|
105 | if(collis(nextsphere->getPosition(), currentPosition)){ |
---|
106 | takePoint(nextsphere); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){ |
---|
111 | if(next->taken(currentPosition)){ |
---|
112 | setAfraid(); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | bool Pacman::collis(Vector3 one, Vector3 other){ |
---|
120 | if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10)) |
---|
121 | return true; |
---|
122 | return false; |
---|
123 | } |
---|
124 | |
---|
125 | void Pacman::catched(){ |
---|
126 | |
---|
127 | if(!afraid) { |
---|
128 | if(!lives) this->end(); |
---|
129 | --lives; |
---|
130 | this->posreset(); |
---|
131 | } |
---|
132 | else{ |
---|
133 | for(int nrghost = 0; nrghost<8; ++nrghost){ |
---|
134 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
135 | if(bcolli) ghosts[nrghost]->resetGhost(); |
---|
136 | bcolli = false; |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | void Pacman::setAfraid(){ |
---|
142 | |
---|
143 | timer = 10; //Set timer to 10 seconds |
---|
144 | |
---|
145 | //Change normal Ghosts with afraid ones |
---|
146 | if(!afraid){ |
---|
147 | ghosts[0]->changewith(ghosts[4]); |
---|
148 | ghosts[1]->changewith(ghosts[5]); |
---|
149 | ghosts[2]->changewith(ghosts[6]); |
---|
150 | ghosts[3]->changewith(ghosts[7]); |
---|
151 | } |
---|
152 | |
---|
153 | afraid = true; |
---|
154 | } |
---|
155 | |
---|
156 | void Pacman::setNormal(){ |
---|
157 | |
---|
158 | timer = 0; |
---|
159 | |
---|
160 | //Change normal Ghosts with afraid ones |
---|
161 | ghosts[4]->changewith(ghosts[0]); |
---|
162 | ghosts[5]->changewith(ghosts[1]); |
---|
163 | ghosts[6]->changewith(ghosts[2]); |
---|
164 | ghosts[7]->changewith(ghosts[3]); |
---|
165 | |
---|
166 | afraid = false; |
---|
167 | } |
---|
168 | |
---|
169 | void Pacman::posreset(){ |
---|
170 | for(int i = 0; i<4; ++i){ |
---|
171 | ghosts[i]->resetGhost(); |
---|
172 | } |
---|
173 | player->setPosition(startposplayer); |
---|
174 | } |
---|
175 | |
---|
176 | void Pacman::takePoint(PacmanPointSphere* taken){ |
---|
177 | ++point; |
---|
178 | if(point == totallevelpoint) this->levelUp(); |
---|
179 | Vector3 postaken = taken->getPosition(); |
---|
180 | postaken.y = -50; |
---|
181 | taken->setPosition(postaken); |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | PacmanGelb* Pacman::getPlayer() |
---|
186 | { |
---|
187 | for (PacmanGelb* ship : ObjectList<PacmanGelb>()) |
---|
188 | { |
---|
189 | return ship; |
---|
190 | } |
---|
191 | return nullptr; |
---|
192 | } |
---|
193 | |
---|
194 | int Pacman::getPoints(){ |
---|
195 | return point; |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | void Pacman::start() |
---|
200 | { |
---|
201 | Deathmatch::start(); |
---|
202 | |
---|
203 | int i = 0; |
---|
204 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
205 | if(3<i){ |
---|
206 | nextghost->setPosition(0,-20,0); |
---|
207 | nextghost->dontmove = true; |
---|
208 | }; |
---|
209 | i++; |
---|
210 | } |
---|
211 | |
---|
212 | totallevelpoint = ObjectList<PacmanPointSphere>().size(); |
---|
213 | |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | void Pacman::end() |
---|
218 | { |
---|
219 | /* |
---|
220 | firstGame = false; |
---|
221 | |
---|
222 | //Set randomized deathmessages |
---|
223 | if(point<7) sDeathMessage = DeathMessage7[rand()%(DeathMessage7.size())]; |
---|
224 | else if(point<20) sDeathMessage = DeathMessage20[rand()%(DeathMessage20.size())]; |
---|
225 | else if(point<30) sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())]; |
---|
226 | else sDeathMessage = DeathMessageover30[rand()%(DeathMessageover30.size())]; |
---|
227 | |
---|
228 | //Update Highscore |
---|
229 | if (Highscore::exists()) |
---|
230 | { |
---|
231 | int score = this->getPoints(); |
---|
232 | Highscore::getInstance().storeScore("Pacman", score, this->getPlayer()->getPlayer()); |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | if (Highscore::exists()) |
---|
237 | { |
---|
238 | //int score = this->getPoints(); |
---|
239 | //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); |
---|
240 | } |
---|
241 | */ |
---|
242 | GSLevel::startMainMenu(); |
---|
243 | } |
---|
244 | } |
---|