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 DodgeRace.cc |
---|
31 | @brief Implementation of the DodgeRace class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "DodgeRace.h" |
---|
35 | #include "DodgeRaceShip.h" // Necessary for getPlayer function. Do NOT include this in Header! |
---|
36 | #include "DodgeRaceCube.h" |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | RegisterUnloadableClass(DodgeRace); |
---|
41 | |
---|
42 | DodgeRace::DodgeRace(Context* context) : Deathmatch(context) |
---|
43 | { |
---|
44 | RegisterObject(DodgeRace); |
---|
45 | init(); |
---|
46 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
47 | this->center_ = 0; |
---|
48 | /* |
---|
49 | this->setHUDTemplate("DodgeRaceHUD"); // !!!!!!!!!!!!!!! change later*/ |
---|
50 | } |
---|
51 | |
---|
52 | void DodgeRace::init() |
---|
53 | { |
---|
54 | bEndGame = false; |
---|
55 | lives = 3; |
---|
56 | level = 1; |
---|
57 | point = 0; |
---|
58 | bShowLevel = false; |
---|
59 | multiplier = 1; |
---|
60 | b_combo = false; |
---|
61 | counter = 0; |
---|
62 | pattern = 1; |
---|
63 | lastPosition = 0; |
---|
64 | // spawn enemy every 3.5 seconds |
---|
65 | //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this))); |
---|
66 | comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this))); |
---|
67 | } |
---|
68 | |
---|
69 | void DodgeRace::levelUp() |
---|
70 | { |
---|
71 | level++; |
---|
72 | if (getPlayer() != NULL) |
---|
73 | { |
---|
74 | for (int i = 0; i < 7; i++) |
---|
75 | { |
---|
76 | WeakPtr<BigExplosion> chunk = new BigExplosion(this->center_->getContext()); |
---|
77 | chunk->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
78 | chunk->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
79 | chunk->setScale(20); |
---|
80 | } |
---|
81 | } |
---|
82 | addPoints(multiplier * 42); |
---|
83 | multiplier *= 2; |
---|
84 | toggleShowLevel(); |
---|
85 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this))); |
---|
86 | } |
---|
87 | |
---|
88 | void DodgeRace::tick(float dt) |
---|
89 | { |
---|
90 | if (getPlayer() != NULL) |
---|
91 | { |
---|
92 | //WeakPtr<DodgeRaceShip> ship = getPlayer(); |
---|
93 | |
---|
94 | currentPosition = getPlayer()->getWorldPosition().x; |
---|
95 | counter = counter + (currentPosition - lastPosition); |
---|
96 | lastPosition = currentPosition; |
---|
97 | |
---|
98 | for(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 | |
---|
111 | for(int i = 0; i<6; i++) |
---|
112 | { |
---|
113 | WeakPtr<DodgeRaceCube> cube = new DodgeRaceCube(this->center_->getContext()); |
---|
114 | cubeList.push_back(cube); |
---|
115 | switch(pattern) |
---|
116 | { |
---|
117 | case 1: cube->addTemplate("DodgeRaceCube01"); |
---|
118 | break; |
---|
119 | case 2: cube->addTemplate("DodgeRaceCube02"); |
---|
120 | break; |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | cube->setPosition(getPlayer()->getWorldPosition() + Vector3(5000, 0, -3600 + (i*1200))); |
---|
125 | //stEntity->setScale3D(50,50,50); |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | pattern %= 2; |
---|
130 | pattern ++; |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|
135 | SUPER(DodgeRace, tick, dt); |
---|
136 | } |
---|
137 | |
---|
138 | WeakPtr<DodgeRaceShip> DodgeRace::getPlayer() |
---|
139 | { |
---|
140 | if (player == NULL) |
---|
141 | { |
---|
142 | for (ObjectList<DodgeRaceShip>::iterator it = ObjectList<DodgeRaceShip>::begin(); it != ObjectList<DodgeRaceShip>::end(); ++it) |
---|
143 | { |
---|
144 | player = *it; |
---|
145 | } |
---|
146 | } |
---|
147 | return player; |
---|
148 | } |
---|
149 | /* |
---|
150 | void DodgeRace::spawnEnemy() |
---|
151 | { |
---|
152 | if (getPlayer() == NULL) |
---|
153 | return; |
---|
154 | |
---|
155 | for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++) |
---|
156 | { |
---|
157 | WeakPtr<DodgeRaceEnemy> newPawn; |
---|
158 | if (rand() % 42/(1 + level*level) == 0) |
---|
159 | { |
---|
160 | newPawn = new DodgeRaceEnemyShooter(this->center_->getContext()); |
---|
161 | newPawn->addTemplate("enemyinvadershooter"); |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | newPawn = new DodgeRaceEnemy(this->center_->getContext()); |
---|
166 | newPawn->addTemplate("enemyinvader"); |
---|
167 | } |
---|
168 | newPawn->setPlayer(player); |
---|
169 | newPawn->level = level; |
---|
170 | // spawn enemy at random points in front of player. |
---|
171 | newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200)); |
---|
172 | } |
---|
173 | } |
---|
174 | */ |
---|
175 | void DodgeRace::costLife() |
---|
176 | { |
---|
177 | orxout() << "CostLife" << endl; |
---|
178 | endGameTimer.setTimer(3.0f, false, createExecutor(createFunctor(&DodgeRace::end, this))); |
---|
179 | |
---|
180 | multiplier = 1; |
---|
181 | }; |
---|
182 | |
---|
183 | void DodgeRace::comboControll() |
---|
184 | { |
---|
185 | if (b_combo) |
---|
186 | multiplier++; |
---|
187 | // if no combo was performed before, reset multiplier |
---|
188 | else |
---|
189 | multiplier = 1; |
---|
190 | b_combo = false; |
---|
191 | } |
---|
192 | |
---|
193 | void DodgeRace::start() |
---|
194 | { |
---|
195 | orxout() << "start function called." << endl; |
---|
196 | init(); |
---|
197 | for(int i=0; i< cubeList.size();i++) |
---|
198 | { |
---|
199 | cubeList.at(i)->destroy(); |
---|
200 | cubeList.erase(cubeList.begin()+i); |
---|
201 | |
---|
202 | } |
---|
203 | cubeList.clear(); |
---|
204 | // Set variable to temporarily force the player to spawn. |
---|
205 | this->bForceSpawn_ = true; |
---|
206 | |
---|
207 | if (this->center_ == NULL) // abandon mission! |
---|
208 | { |
---|
209 | orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl; |
---|
210 | GSLevel::startMainMenu(); |
---|
211 | return; |
---|
212 | } |
---|
213 | // Call start for the parent class. |
---|
214 | Deathmatch::start(); |
---|
215 | } |
---|
216 | void DodgeRace::addPoints(int numPoints) |
---|
217 | { |
---|
218 | if (!bEndGame) |
---|
219 | { |
---|
220 | point += numPoints * multiplier; |
---|
221 | b_combo = true; |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | void DodgeRace::end() |
---|
226 | { |
---|
227 | // DON'T CALL THIS! |
---|
228 | // Deathmatch::end(); |
---|
229 | // It will misteriously crash the game! |
---|
230 | // Instead startMainMenu, this won't crash. |
---|
231 | GSLevel::startMainMenu(); |
---|
232 | } |
---|
233 | } |
---|