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 FlappyOrx.cc |
---|
31 | @brief Implementation of the FlappyOrx class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "FlappyOrx.h" |
---|
35 | #include "Highscore.h" |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/EventIncludes.h" |
---|
38 | #include "core/command/Executor.h" |
---|
39 | #include "core/config/ConfigValueIncludes.h" |
---|
40 | |
---|
41 | #include "gamestates/GSLevel.h" |
---|
42 | #include "chat/ChatManager.h" |
---|
43 | |
---|
44 | // ! HACK |
---|
45 | #include "infos/PlayerInfo.h" |
---|
46 | |
---|
47 | #include "FlappyOrxCenterPoint.h" |
---|
48 | #include "FlappyOrxShip.h" |
---|
49 | #include "FlappyOrxAsteroid.h" |
---|
50 | |
---|
51 | #include "core/command/ConsoleCommand.h" |
---|
52 | #include "worldentities/ExplosionPart.h" |
---|
53 | |
---|
54 | |
---|
55 | namespace orxonox |
---|
56 | { |
---|
57 | RegisterUnloadableClass(FlappyOrx); |
---|
58 | |
---|
59 | FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context) |
---|
60 | { |
---|
61 | RegisterObject(FlappyOrx); |
---|
62 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
63 | this->center_ = nullptr; |
---|
64 | bEndGame = false; |
---|
65 | lives = 1; |
---|
66 | level = 0; |
---|
67 | point = 0; |
---|
68 | bShowLevel = false; |
---|
69 | sDeathMessage = "Welcome to FlappyOrx\nPress Space to start!"; |
---|
70 | bIsDead = true; |
---|
71 | multiplier = 1; |
---|
72 | b_combo = false; |
---|
73 | this->spawnDistance=200; |
---|
74 | this->tubeOffsetX=500; |
---|
75 | this->setHUDTemplate("FlappyOrxHUD"); |
---|
76 | } |
---|
77 | |
---|
78 | void FlappyOrx::updatePlayerPos(int x){ |
---|
79 | |
---|
80 | if(this->tubes.size()==0||x-tubes.back()+tubeOffsetX>spawnDistance){ |
---|
81 | spawnTube(); |
---|
82 | this->tubes.push(x+tubeOffsetX); |
---|
83 | } |
---|
84 | if(this->tubes.size()!=0&&x>this->tubes.front()){ |
---|
85 | this->tubes.pop(); |
---|
86 | levelUp(); |
---|
87 | } |
---|
88 | while((this->asteroids.front())->getPosition().x<x-300){ |
---|
89 | MovableEntity* deleteMe = asteroids.front(); |
---|
90 | asteroids.pop(); |
---|
91 | deleteMe->destroy(); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | void FlappyOrx::levelUp() |
---|
96 | { |
---|
97 | point++; |
---|
98 | spawnDistance = 300-3*point; |
---|
99 | getPlayer()->setSpeed(100+.5*point); |
---|
100 | toggleShowLevel(); |
---|
101 | //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this))); |
---|
102 | } |
---|
103 | |
---|
104 | FlappyOrxShip* FlappyOrx::getPlayer() |
---|
105 | { |
---|
106 | if (player == nullptr) |
---|
107 | { |
---|
108 | for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) { |
---|
109 | player = ship; |
---|
110 | } |
---|
111 | } |
---|
112 | return player; |
---|
113 | } |
---|
114 | |
---|
115 | void FlappyOrx::spawnTube() |
---|
116 | { |
---|
117 | int space = 120; |
---|
118 | int height = (float(rand())/RAND_MAX-0.5)*(280-space); |
---|
119 | |
---|
120 | if (getPlayer() == nullptr) |
---|
121 | return; |
---|
122 | |
---|
123 | Vector3 pos = player->getPosition(); |
---|
124 | |
---|
125 | asteroidField(pos.x+tubeOffsetX,height-space/2,0.8); |
---|
126 | asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8); |
---|
127 | } |
---|
128 | |
---|
129 | void FlappyOrx::asteroidField(int x, int y, float slope){ |
---|
130 | int r = 20; |
---|
131 | int noadd = 0; |
---|
132 | |
---|
133 | ClearAsteroids(); |
---|
134 | Circle newAsteroid = Circle(); |
---|
135 | newAsteroid.x=x; |
---|
136 | newAsteroid.y=y; |
---|
137 | newAsteroid.r=r; |
---|
138 | addIfPossible(newAsteroid); |
---|
139 | while(r>0){ |
---|
140 | if(slope>0) |
---|
141 | newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150; |
---|
142 | else |
---|
143 | newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y; |
---|
144 | |
---|
145 | newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope; |
---|
146 | newAsteroid.r=r; |
---|
147 | |
---|
148 | int i = addIfPossible(newAsteroid); |
---|
149 | if(i==0) |
---|
150 | noadd++; |
---|
151 | else if(i==2) |
---|
152 | r=0; |
---|
153 | if(noadd>=5){ |
---|
154 | noadd=0; |
---|
155 | r-=5; |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | void deleteAsteroid(MovableEntity* asteroid){ |
---|
161 | //center_->getContext().getObjectList().removeElement(asteroid); |
---|
162 | } |
---|
163 | |
---|
164 | void FlappyOrx::createAsteroid(Circle &c){ |
---|
165 | MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext()); |
---|
166 | |
---|
167 | |
---|
168 | if(c.r<=5) |
---|
169 | newAsteroid->addTemplate(Asteroid5[rand()%6]); |
---|
170 | else if(c.r<=10) |
---|
171 | newAsteroid->addTemplate(Asteroid10[rand()%6]); |
---|
172 | else if(c.r<=15) |
---|
173 | newAsteroid->addTemplate(Asteroid15[rand()%6]); |
---|
174 | else |
---|
175 | newAsteroid->addTemplate(Asteroid20[rand()%6]); |
---|
176 | |
---|
177 | newAsteroid->setPosition(Vector3(c.x, 0, c.y)); |
---|
178 | newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360)); |
---|
179 | newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360)); |
---|
180 | |
---|
181 | asteroids.push(newAsteroid); |
---|
182 | |
---|
183 | |
---|
184 | } |
---|
185 | |
---|
186 | void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center) |
---|
187 | { |
---|
188 | this->center_ = center; |
---|
189 | } |
---|
190 | |
---|
191 | void FlappyOrx::costLife() |
---|
192 | { |
---|
193 | |
---|
194 | }; |
---|
195 | |
---|
196 | bool FlappyOrx::isDead(){ |
---|
197 | return bIsDead; |
---|
198 | } |
---|
199 | |
---|
200 | std::string FlappyOrx::getDeathMessage(){ |
---|
201 | return sDeathMessage; |
---|
202 | } |
---|
203 | |
---|
204 | void FlappyOrx::comboControll() |
---|
205 | { |
---|
206 | if (b_combo) |
---|
207 | multiplier++; |
---|
208 | // if no combo was performed before, reset multiplier |
---|
209 | else |
---|
210 | multiplier = 1; |
---|
211 | b_combo = false; |
---|
212 | } |
---|
213 | |
---|
214 | void FlappyOrx::start() |
---|
215 | { |
---|
216 | // Set variable to temporarily force the player to spawn. |
---|
217 | this->bForceSpawn_ = true; |
---|
218 | |
---|
219 | if (this->center_ == nullptr) // abandon mission! |
---|
220 | { |
---|
221 | orxout(internal_error) << "FlappyOrx: No Centerpoint specified." << endl; |
---|
222 | GSLevel::startMainMenu(); |
---|
223 | return; |
---|
224 | } |
---|
225 | // Call start for the parent class. |
---|
226 | Deathmatch::start(); |
---|
227 | } |
---|
228 | void FlappyOrx::addPoints(int numPoints) |
---|
229 | { |
---|
230 | if (!bEndGame) |
---|
231 | { |
---|
232 | point += numPoints * multiplier; |
---|
233 | b_combo = true; |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | void FlappyOrx::death(){ |
---|
238 | bIsDead = true; |
---|
239 | sDeathMessage = "GameOver"; |
---|
240 | if (Highscore::exists()){ |
---|
241 | int score = this->getPoints(); |
---|
242 | if(score > Highscore::getInstance().getHighestScoreOfGame("Flappy Orx")) |
---|
243 | Highscore::getInstance().storeHighscore("Flappy Orx",score); |
---|
244 | } |
---|
245 | point = -1; |
---|
246 | level=-1; |
---|
247 | levelUp(); |
---|
248 | while (!tubes.empty()) |
---|
249 | { |
---|
250 | tubes.pop(); |
---|
251 | } |
---|
252 | while (!asteroids.empty()) |
---|
253 | { |
---|
254 | MovableEntity* deleteMe = asteroids.front(); |
---|
255 | asteroids.pop(); |
---|
256 | deleteMe->destroy(); |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | void FlappyOrx::end() |
---|
261 | { |
---|
262 | // DON'T CALL THIS! |
---|
263 | // Deathmatch::end(); |
---|
264 | // It will misteriously crash the game! |
---|
265 | // Instead startMainMenu, this won't crash. |
---|
266 | if (Highscore::exists()){ |
---|
267 | int score = this->getPoints(); |
---|
268 | if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade")) |
---|
269 | Highscore::getInstance().storeHighscore("Orxonox Arcade",score); |
---|
270 | |
---|
271 | } |
---|
272 | GSLevel::startMainMenu(); |
---|
273 | } |
---|
274 | } |
---|