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 | { |
---|
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 = 10; |
---|
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 | if(!timer){ |
---|
69 | timer = timer - dt; |
---|
70 | if(timer<=0){ |
---|
71 | afraid = false; |
---|
72 | timer = 0; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | int i = 0; |
---|
77 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
78 | ghosts[i] = nextghost; |
---|
79 | i++; |
---|
80 | } |
---|
81 | |
---|
82 | player = this->getPlayer(); |
---|
83 | if (player != nullptr) |
---|
84 | { |
---|
85 | currentPosition = player->getWorldPosition(); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | bcolli = false; |
---|
90 | for(int nrghost = 0; (nrghost<3) && (!bcolli); ++nrghost){ |
---|
91 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
92 | //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl; |
---|
93 | } |
---|
94 | |
---|
95 | if(bcolli){ |
---|
96 | this->catched(); |
---|
97 | } |
---|
98 | |
---|
99 | i = 0; |
---|
100 | for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){ |
---|
101 | if(collis(nextsphere->getPosition(), currentPosition)){ |
---|
102 | takePoint(nextsphere); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){ |
---|
107 | if(collis(next->getPosition(), currentPosition)){ |
---|
108 | setAfraid(); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | bool Pacman::collis(Vector3 one, Vector3 other){ |
---|
116 | if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10)) |
---|
117 | return true; |
---|
118 | return false; |
---|
119 | } |
---|
120 | |
---|
121 | void Pacman::catched(){ |
---|
122 | |
---|
123 | if(!afraid) { |
---|
124 | if(!lives) this->end(); |
---|
125 | --lives; |
---|
126 | this->posreset(); |
---|
127 | } |
---|
128 | else{ |
---|
129 | for(int nrghost = 0; nrghost<3; ++nrghost){ |
---|
130 | bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); |
---|
131 | if(bcolli) ghosts[nrghost]->resetGhost(); |
---|
132 | bcolli = false; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | void setAfraid(){ |
---|
138 | afraid = true; |
---|
139 | timer = 10; //Set timer to 10 seconds |
---|
140 | } |
---|
141 | |
---|
142 | void Pacman::posreset(){ |
---|
143 | for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){ |
---|
144 | nextghost->resetGhost(); |
---|
145 | } |
---|
146 | player->setPosition(startposplayer); |
---|
147 | } |
---|
148 | |
---|
149 | void Pacman::takePoint(PacmanPointSphere* taken){ |
---|
150 | ++point; |
---|
151 | if(point == totallevelpoint) this->levelUp(); |
---|
152 | Vector3 postaken = taken->getPosition(); |
---|
153 | postaken.y = -50; |
---|
154 | taken->setPosition(postaken); |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | PacmanGelb* Pacman::getPlayer() |
---|
159 | { |
---|
160 | for (PacmanGelb* ship : ObjectList<PacmanGelb>()) |
---|
161 | { |
---|
162 | return ship; |
---|
163 | } |
---|
164 | return nullptr; |
---|
165 | } |
---|
166 | |
---|
167 | int Pacman::getPoints(){ |
---|
168 | return point; |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | void Pacman::start() |
---|
173 | { |
---|
174 | Deathmatch::start(); |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | void Pacman::end() |
---|
179 | { |
---|
180 | /* |
---|
181 | firstGame = false; |
---|
182 | |
---|
183 | //Set randomized deathmessages |
---|
184 | if(point<7) sDeathMessage = DeathMessage7[rand()%(DeathMessage7.size())]; |
---|
185 | else if(point<20) sDeathMessage = DeathMessage20[rand()%(DeathMessage20.size())]; |
---|
186 | else if(point<30) sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())]; |
---|
187 | else sDeathMessage = DeathMessageover30[rand()%(DeathMessageover30.size())]; |
---|
188 | |
---|
189 | //Update Highscore |
---|
190 | if (Highscore::exists()) |
---|
191 | { |
---|
192 | int score = this->getPoints(); |
---|
193 | Highscore::getInstance().storeScore("Pacman", score, this->getPlayer()->getPlayer()); |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | if (Highscore::exists()) |
---|
198 | { |
---|
199 | //int score = this->getPoints(); |
---|
200 | //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); |
---|
201 | } |
---|
202 | */ |
---|
203 | GSLevel::startMainMenu(); |
---|
204 | } |
---|
205 | } |
---|