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 OrxyRoad.cc |
---|
31 | @brief Implementation of the OrxyRoad class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "OrxyRoad.h" |
---|
35 | #include "OrxyRoadShip.h" // Necessary for getPlayer function. Do NOT include this in Header! |
---|
36 | #include "OrxyRoadCube.h" |
---|
37 | #include "core/CoreIncludes.h" |
---|
38 | #include "Highscore.h" |
---|
39 | #include "infos/PlayerInfo.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | RegisterUnloadableClass(OrxyRoad); |
---|
44 | |
---|
45 | OrxyRoad::OrxyRoad(Context* context) : Deathmatch(context) |
---|
46 | { |
---|
47 | RegisterObject(OrxyRoad); |
---|
48 | |
---|
49 | bEndGame = false; |
---|
50 | lives = 1; |
---|
51 | level = 1; |
---|
52 | point = 0; |
---|
53 | bShowLevel = false; |
---|
54 | multiplier = 1; |
---|
55 | b_combo = false; |
---|
56 | counter = 5000; |
---|
57 | pattern = 3; |
---|
58 | lastPosition = 0; |
---|
59 | roadWidth = 3000; |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | // spawn enemy every 3.5 seconds |
---|
66 | //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&OrxyRoad::spawnEnemy, this))); |
---|
67 | comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&OrxyRoad::comboControll, this))); |
---|
68 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
69 | this->center_ = nullptr; |
---|
70 | |
---|
71 | this->setHUDTemplate("OrxyRoadHUD"); |
---|
72 | } |
---|
73 | |
---|
74 | void OrxyRoad::levelUp() |
---|
75 | { |
---|
76 | level++; |
---|
77 | if (getPlayer() != nullptr) |
---|
78 | { |
---|
79 | for (int i = 0; i < 7; i++) |
---|
80 | { |
---|
81 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
82 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
83 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
84 | chunk5->setScale(10); |
---|
85 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
86 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
87 | chunk5->Explode(); |
---|
88 | |
---|
89 | } |
---|
90 | } |
---|
91 | addPoints(multiplier * 42); |
---|
92 | multiplier *= 2; |
---|
93 | toggleShowLevel(); |
---|
94 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&OrxyRoad::toggleShowLevel, this))); |
---|
95 | } |
---|
96 | int OrxyRoad::generateStreet(int type, OrxyRoadShip* player){ |
---|
97 | int trafficVelocities[]= {20,1000,500, 200}; |
---|
98 | int numObjects[] = {60,10,40,60}; // default, spaceship, sattellite, asteroid |
---|
99 | int streetSize[] = {3 , 1, 2, 4}; |
---|
100 | int trackWidth = 800; |
---|
101 | |
---|
102 | for(int j = 0; j < streetSize[type]; j++)//width of Street |
---|
103 | { |
---|
104 | for(int i = -numObjects[type]/2; i<numObjects[type]/2; i++) |
---|
105 | { |
---|
106 | OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext()); |
---|
107 | cubeList.push_back(cube); |
---|
108 | switch(type) |
---|
109 | { |
---|
110 | case 0 : cube->addTemplate("asteroid");//default |
---|
111 | break; |
---|
112 | case 1: |
---|
113 | |
---|
114 | cube->addTemplate("spacecruiser");//spaceship |
---|
115 | |
---|
116 | break; |
---|
117 | case 2: cube->addTemplate("spacecruiser");//satellite |
---|
118 | break; |
---|
119 | case 3: cube->addTemplate("asteroid");//asteroid |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | int distance = trafficVelocities[type]; //Todo better calculation of distance between objects |
---|
124 | |
---|
125 | cube->setPosition(player->getWorldPosition() + Vector3(1000.0f+j*trackWidth, 0.0f, i*600.0f+j*trackWidth)); |
---|
126 | |
---|
127 | /* experimental */ |
---|
128 | |
---|
129 | cube->setVelocity(0,0,trafficVelocities[type]); |
---|
130 | |
---|
131 | /* experimental */ |
---|
132 | |
---|
133 | |
---|
134 | //stEntity->setScale3D(50,50,50); |
---|
135 | } |
---|
136 | } |
---|
137 | return streetSize[type] * trackWidth; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | void OrxyRoad::tick(float dt) |
---|
144 | { |
---|
145 | SUPER(OrxyRoad, tick, dt); |
---|
146 | |
---|
147 | OrxyRoadShip* player = this->getPlayer(); |
---|
148 | if (player != nullptr) |
---|
149 | { |
---|
150 | currentPosition = player->getWorldPosition().x; |
---|
151 | counter = counter + (currentPosition - lastPosition); |
---|
152 | lastPosition = currentPosition; |
---|
153 | point = (int) currentPosition; |
---|
154 | player->speed = 830.0f - (point / 1000); |
---|
155 | |
---|
156 | for(unsigned int i=0; i < cubeList.size();i++) |
---|
157 | { |
---|
158 | if(cubeList.at(i)->getPosition().x < currentPosition-3000) |
---|
159 | { |
---|
160 | cubeList.at(i)->destroy(); |
---|
161 | cubeList.erase(cubeList.begin()+i); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | if(counter >= 3000) |
---|
169 | { |
---|
170 | int type = rand() % 4; |
---|
171 | orxout(user_info) << "Random : "<<type<< endl; |
---|
172 | |
---|
173 | roadWidth = generateStreet(type,player);//Generate street to specific type type = 0 default, type = 1 space ship type = 2 statellite/cubes, type = 3 asteroids |
---|
174 | counter = 0; |
---|
175 | |
---|
176 | //pattern %= 2; |
---|
177 | //pattern ++; |
---|
178 | |
---|
179 | } |
---|
180 | |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | OrxyRoadShip* OrxyRoad::getPlayer() |
---|
185 | { |
---|
186 | for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>()) |
---|
187 | { |
---|
188 | return ship; |
---|
189 | } |
---|
190 | return nullptr; |
---|
191 | } |
---|
192 | |
---|
193 | void OrxyRoad::costLife() |
---|
194 | { |
---|
195 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this))); |
---|
196 | lives = 0; |
---|
197 | }; |
---|
198 | |
---|
199 | void OrxyRoad::comboControll() |
---|
200 | { |
---|
201 | if (b_combo) |
---|
202 | multiplier++; |
---|
203 | // if no combo was performed before, reset multiplier |
---|
204 | else |
---|
205 | multiplier = 1; |
---|
206 | b_combo = false; |
---|
207 | } |
---|
208 | |
---|
209 | void OrxyRoad::start() |
---|
210 | { |
---|
211 | orxout() << "start" << endl; |
---|
212 | for(unsigned int i=0; i< cubeList.size();i++) |
---|
213 | { |
---|
214 | cubeList.at(i)->destroy(); |
---|
215 | cubeList.erase(cubeList.begin()+i); |
---|
216 | |
---|
217 | } |
---|
218 | cubeList.clear(); |
---|
219 | // Set variable to temporarily force the player to spawn. |
---|
220 | this->bForceSpawn_ = false; |
---|
221 | |
---|
222 | if (this->center_ == nullptr) // abandon mission! |
---|
223 | { |
---|
224 | orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl; |
---|
225 | GSLevel::startMainMenu(); |
---|
226 | return; |
---|
227 | } |
---|
228 | Deathmatch::start(); |
---|
229 | } |
---|
230 | |
---|
231 | void OrxyRoad::playerPreSpawn(PlayerInfo* player) |
---|
232 | { |
---|
233 | this->playerInfo_ = player; |
---|
234 | if(lives <= 0) |
---|
235 | { |
---|
236 | this->end(); |
---|
237 | } |
---|
238 | |
---|
239 | // Reset all the cubes |
---|
240 | /* |
---|
241 | orxout() << "prespawn" << endl; |
---|
242 | for(int i=0; i< cubeList.size();i++) |
---|
243 | { |
---|
244 | cubeList.at(i)->destroy(); |
---|
245 | cubeList.erase(cubeList.begin()+i); |
---|
246 | } |
---|
247 | cubeList.clear(); |
---|
248 | lives = 1; |
---|
249 | point = 0; |
---|
250 | lastPosition = 0; |
---|
251 | */ |
---|
252 | } |
---|
253 | |
---|
254 | void OrxyRoad::addPoints(int numPoints) |
---|
255 | { |
---|
256 | if (!bEndGame) |
---|
257 | { |
---|
258 | point += numPoints * multiplier; |
---|
259 | b_combo = true; |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | void OrxyRoad::end() |
---|
264 | { |
---|
265 | // DON'T CALL THIS! |
---|
266 | // Deathmatch::end(); |
---|
267 | // It will misteriously crash the game! |
---|
268 | // Instead startMainMenu, this won't crash. |
---|
269 | if (Highscore::exists()) |
---|
270 | { |
---|
271 | int score = this->getPoints(); |
---|
272 | Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_); |
---|
273 | } |
---|
274 | GSLevel::startMainMenu(); |
---|
275 | } |
---|
276 | } |
---|