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" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | RegisterUnloadableClass(3DPacman); |
---|
40 | |
---|
41 | 3DPacman::3DPacman(Context* context) : Deathmatch(context) |
---|
42 | { |
---|
43 | RegisterObject(3DPacman); |
---|
44 | |
---|
45 | bEndGame = false; |
---|
46 | lives = 1; |
---|
47 | level = 1; |
---|
48 | point = 0; |
---|
49 | bShowLevel = false; |
---|
50 | multiplier = 1; |
---|
51 | b_combo = false; |
---|
52 | counter = 5000; |
---|
53 | pattern = 1; |
---|
54 | lastPosition = 0; |
---|
55 | // spawn enemy every 3.5 seconds |
---|
56 | //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this))); |
---|
57 | comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this))); |
---|
58 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
59 | this->center_ = nullptr; |
---|
60 | |
---|
61 | this->setHUDTemplate("DodgeRaceHUD"); |
---|
62 | } |
---|
63 | |
---|
64 | void DodgeRace::levelUp() |
---|
65 | { |
---|
66 | level++; |
---|
67 | if (getPlayer() != nullptr) |
---|
68 | { |
---|
69 | for (int i = 0; i < 7; i++) |
---|
70 | { |
---|
71 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
72 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
73 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
74 | chunk5->setScale(10); |
---|
75 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
76 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
77 | chunk5->Explode(); |
---|
78 | |
---|
79 | } |
---|
80 | } |
---|
81 | addPoints(multiplier * 42); |
---|
82 | multiplier *= 2; |
---|
83 | toggleShowLevel(); |
---|
84 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this))); |
---|
85 | } |
---|
86 | |
---|
87 | void DodgeRace::tick(float dt) |
---|
88 | { |
---|
89 | DodgeRaceShip* player = this->getPlayer(); |
---|
90 | if (player != nullptr) |
---|
91 | { |
---|
92 | currentPosition = player->getWorldPosition().x; |
---|
93 | counter = counter + (currentPosition - lastPosition); |
---|
94 | lastPosition = currentPosition; |
---|
95 | point = (int) currentPosition; |
---|
96 | player->speed = 830.0f - (point / 1000); |
---|
97 | |
---|
98 | for(unsigned int i=0; i < cubeList.size();i++) |
---|
99 | { |
---|
100 | if(cubeList.at(i)->getPosition().x < currentPosition-3000) |
---|
101 | { |
---|
102 | cubeList.at(i)->destroy(); |
---|
103 | cubeList.erase(cubeList.begin()+i); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | if(counter >= 3000) |
---|
108 | { |
---|
109 | counter = 0; |
---|
110 | for(int i = 0; i<6; i++) |
---|
111 | { |
---|
112 | DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext()); |
---|
113 | cubeList.push_back(cube); |
---|
114 | switch(pattern) |
---|
115 | { |
---|
116 | case 1: cube->addTemplate("DodgeRaceCube01"); |
---|
117 | break; |
---|
118 | case 2: cube->addTemplate("DodgeRaceCube02"); |
---|
119 | break; |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200))); |
---|
124 | //stEntity->setScale3D(50,50,50); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | pattern %= 2; |
---|
129 | pattern ++; |
---|
130 | |
---|
131 | } |
---|
132 | |
---|
133 | } |
---|
134 | SUPER(DodgeRace, tick, dt); |
---|
135 | } |
---|
136 | |
---|
137 | DodgeRaceShip* DodgeRace::getPlayer() |
---|
138 | { |
---|
139 | for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>()) |
---|
140 | { |
---|
141 | return ship; |
---|
142 | } |
---|
143 | return nullptr; |
---|
144 | } |
---|
145 | |
---|
146 | void DodgeRace::costLife() |
---|
147 | { |
---|
148 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this))); |
---|
149 | lives = 0; |
---|
150 | }; |
---|
151 | |
---|
152 | void DodgeRace::comboControll() |
---|
153 | { |
---|
154 | if (b_combo) |
---|
155 | multiplier++; |
---|
156 | // if no combo was performed before, reset multiplier |
---|
157 | else |
---|
158 | multiplier = 1; |
---|
159 | b_combo = false; |
---|
160 | } |
---|
161 | |
---|
162 | void DodgeRace::start() |
---|
163 | { |
---|
164 | orxout() << "start" << endl; |
---|
165 | for(unsigned int i=0; i< cubeList.size();i++) |
---|
166 | { |
---|
167 | cubeList.at(i)->destroy(); |
---|
168 | cubeList.erase(cubeList.begin()+i); |
---|
169 | |
---|
170 | } |
---|
171 | cubeList.clear(); |
---|
172 | // Set variable to temporarily force the player to spawn. |
---|
173 | this->bForceSpawn_ = false; |
---|
174 | |
---|
175 | if (this->center_ == nullptr) // abandon mission! |
---|
176 | { |
---|
177 | orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl; |
---|
178 | GSLevel::startMainMenu(); |
---|
179 | return; |
---|
180 | } |
---|
181 | // Call start for the parent class. |
---|
182 | Deathmatch::start(); |
---|
183 | } |
---|
184 | |
---|
185 | void DodgeRace::playerPreSpawn(PlayerInfo* player) |
---|
186 | { |
---|
187 | this->playerInfo_ = player; |
---|
188 | if(lives <= 0) |
---|
189 | { |
---|
190 | this->end(); |
---|
191 | } |
---|
192 | |
---|
193 | // Reset all the cubes |
---|
194 | /* |
---|
195 | orxout() << "prespawn" << endl; |
---|
196 | for(int i=0; i< cubeList.size();i++) |
---|
197 | { |
---|
198 | cubeList.at(i)->destroy(); |
---|
199 | cubeList.erase(cubeList.begin()+i); |
---|
200 | } |
---|
201 | cubeList.clear(); |
---|
202 | lives = 1; |
---|
203 | point = 0; |
---|
204 | lastPosition = 0; |
---|
205 | */ |
---|
206 | } |
---|
207 | |
---|
208 | void DodgeRace::addPoints(int numPoints) |
---|
209 | { |
---|
210 | if (!bEndGame) |
---|
211 | { |
---|
212 | point += numPoints * multiplier; |
---|
213 | b_combo = true; |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | void DodgeRace::end() |
---|
218 | { |
---|
219 | // DON'T CALL THIS! |
---|
220 | // Deathmatch::end(); |
---|
221 | // It will misteriously crash the game! |
---|
222 | // Instead startMainMenu, this won't crash. |
---|
223 | if (Highscore::exists()) |
---|
224 | { |
---|
225 | int score = this->getPoints(); |
---|
226 | Highscore::getInstance().storeScore("Dodge Race", score, this->playerInfo_); |
---|
227 | } |
---|
228 | GSLevel::startMainMenu(); |
---|
229 | } |
---|
230 | } |
---|