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