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 | namespace orxonox |
---|
55 | { |
---|
56 | RegisterUnloadableClass(FlappyOrx); |
---|
57 | |
---|
58 | FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context) |
---|
59 | { |
---|
60 | RegisterObject(FlappyOrx); |
---|
61 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
62 | this->center_ = nullptr; |
---|
63 | bEndGame = false; |
---|
64 | lives = 1; |
---|
65 | level = 0; |
---|
66 | point = 0; |
---|
67 | bShowLevel = false; |
---|
68 | multiplier = 1; |
---|
69 | b_combo = false; |
---|
70 | this->spawnDistance=300; |
---|
71 | this->tubeOffsetX=500; |
---|
72 | this->setHUDTemplate("FlappyOrxHUD"); |
---|
73 | } |
---|
74 | |
---|
75 | void FlappyOrx::updatePlayerPos(int x){ |
---|
76 | if(this->tubes.size()==0||x-this->tubes.back()-tubeOffsetX>spawnDistance){ |
---|
77 | spawnTube(); |
---|
78 | this->tubes.push(x+tubeOffsetX); |
---|
79 | } |
---|
80 | if(this->tubes.size()!=0&&x>this->tubes.front()){ |
---|
81 | this->tubes.pop(); |
---|
82 | levelUp(); |
---|
83 | point++; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | void FlappyOrx::levelUp() |
---|
88 | { |
---|
89 | level++; |
---|
90 | toggleShowLevel(); |
---|
91 | //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this))); |
---|
92 | } |
---|
93 | |
---|
94 | FlappyOrxShip* FlappyOrx::getPlayer() |
---|
95 | { |
---|
96 | if (player == nullptr) |
---|
97 | { |
---|
98 | for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) { |
---|
99 | player = ship; |
---|
100 | } |
---|
101 | } |
---|
102 | return player; |
---|
103 | } |
---|
104 | |
---|
105 | void FlappyOrx::spawnTube() |
---|
106 | { |
---|
107 | int space = 90; |
---|
108 | int height = (float(rand())/RAND_MAX-0.5)*(280-space); |
---|
109 | |
---|
110 | if (getPlayer() == nullptr) |
---|
111 | return; |
---|
112 | |
---|
113 | Vector3 pos = player->getPosition(); |
---|
114 | |
---|
115 | asteroidField(pos.x+tubeOffsetX,height-space/2,0.8); |
---|
116 | asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8); |
---|
117 | } |
---|
118 | |
---|
119 | void FlappyOrx::asteroidField(int x, int y, float slope){ |
---|
120 | int r = 20; |
---|
121 | int noadd = 0; |
---|
122 | |
---|
123 | ClearAsteroids(); |
---|
124 | Circle newAsteroid = Circle(); |
---|
125 | while(r>0){ |
---|
126 | if(slope>0) |
---|
127 | newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150; |
---|
128 | else |
---|
129 | newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y; |
---|
130 | |
---|
131 | newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope; |
---|
132 | newAsteroid.r=r; |
---|
133 | |
---|
134 | int i = addIfPossible(newAsteroid); |
---|
135 | if(i==0) |
---|
136 | noadd++; |
---|
137 | else if(i==2) |
---|
138 | r=0; |
---|
139 | if(noadd>=5){ |
---|
140 | noadd=0; |
---|
141 | r-=5; |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | void FlappyOrx::createAsteroid(Circle &c){ |
---|
147 | orxout() << "created Asteroid at x="<<c.x<<" y="<<c.y << std::endl; |
---|
148 | MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext()); |
---|
149 | if(c.r<=5) |
---|
150 | newAsteroid->addTemplate(Asteroid5[rand()%6]); |
---|
151 | else if(c.r<=10) |
---|
152 | newAsteroid->addTemplate(Asteroid10[rand()%6]); |
---|
153 | else if(c.r<=15) |
---|
154 | newAsteroid->addTemplate(Asteroid15[rand()%6]); |
---|
155 | else |
---|
156 | newAsteroid->addTemplate(Asteroid20[rand()%6]); |
---|
157 | |
---|
158 | newAsteroid->setPosition(Vector3(c.x, 0, c.y)); |
---|
159 | newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360)); |
---|
160 | newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360)); |
---|
161 | |
---|
162 | } |
---|
163 | |
---|
164 | void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center) |
---|
165 | { |
---|
166 | this->center_ = center; |
---|
167 | } |
---|
168 | |
---|
169 | void FlappyOrx::costLife() |
---|
170 | { |
---|
171 | lives--; |
---|
172 | multiplier = 1; |
---|
173 | // end the game in 30 seconds. |
---|
174 | if (lives <= 0) |
---|
175 | enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&FlappyOrx::end, this))); |
---|
176 | }; |
---|
177 | |
---|
178 | void FlappyOrx::comboControll() |
---|
179 | { |
---|
180 | if (b_combo) |
---|
181 | multiplier++; |
---|
182 | // if no combo was performed before, reset multiplier |
---|
183 | else |
---|
184 | multiplier = 1; |
---|
185 | b_combo = false; |
---|
186 | } |
---|
187 | |
---|
188 | void FlappyOrx::start() |
---|
189 | { |
---|
190 | // Set variable to temporarily force the player to spawn. |
---|
191 | this->bForceSpawn_ = true; |
---|
192 | |
---|
193 | if (this->center_ == nullptr) // abandon mission! |
---|
194 | { |
---|
195 | orxout(internal_error) << "FlappyOrx: No Centerpoint specified." << endl; |
---|
196 | GSLevel::startMainMenu(); |
---|
197 | return; |
---|
198 | } |
---|
199 | // Call start for the parent class. |
---|
200 | Deathmatch::start(); |
---|
201 | } |
---|
202 | void FlappyOrx::addPoints(int numPoints) |
---|
203 | { |
---|
204 | if (!bEndGame) |
---|
205 | { |
---|
206 | point += numPoints * multiplier; |
---|
207 | b_combo = true; |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | void FlappyOrx::end() |
---|
212 | { |
---|
213 | // DON'T CALL THIS! |
---|
214 | // Deathmatch::end(); |
---|
215 | // It will misteriously crash the game! |
---|
216 | // Instead startMainMenu, this won't crash. |
---|
217 | if (Highscore::exists()){ |
---|
218 | int score = this->getPoints(); |
---|
219 | if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade")) |
---|
220 | Highscore::getInstance().storeHighscore("Orxonox Arcade",score); |
---|
221 | |
---|
222 | } |
---|
223 | GSLevel::startMainMenu(); |
---|
224 | } |
---|
225 | } |
---|