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