| [11481] | 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 | 
|---|
| [11503] | 31 |     @brief Implementation of the FlappyOrx class. | 
|---|
| [11481] | 32 | */ | 
|---|
 | 33 |  | 
|---|
| [11503] | 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" | 
|---|
| [11481] | 40 |  | 
|---|
| [11503] | 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" | 
|---|
| [11529] | 49 | #include "FlappyOrxAsteroid.h" | 
|---|
| [11503] | 50 |  | 
|---|
 | 51 | #include "core/command/ConsoleCommand.h" | 
|---|
 | 52 | #include "worldentities/ExplosionPart.h" | 
|---|
 | 53 |  | 
|---|
| [11563] | 54 |  | 
|---|
| [11481] | 55 | namespace orxonox | 
|---|
 | 56 | { | 
|---|
 | 57 |     RegisterUnloadableClass(FlappyOrx); | 
|---|
 | 58 |  | 
|---|
 | 59 |     FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context) | 
|---|
 | 60 |     { | 
|---|
 | 61 |         RegisterObject(FlappyOrx); | 
|---|
| [11503] | 62 |         this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 | 
|---|
 | 63 |         this->center_ = nullptr; | 
|---|
 | 64 |         bEndGame = false; | 
|---|
| [11521] | 65 |         lives = 1; | 
|---|
| [11533] | 66 |         level = 0; | 
|---|
| [11503] | 67 |         point = 0; | 
|---|
 | 68 |         bShowLevel = false; | 
|---|
| [11566] | 69 |         sDeathMessage = "Welcome to FlappyOrx\nPress Space to start!"; | 
|---|
| [11565] | 70 |         bIsDead = true; | 
|---|
| [11503] | 71 |         multiplier = 1; | 
|---|
 | 72 |         b_combo = false; | 
|---|
| [11554] | 73 |         this->spawnDistance=200; | 
|---|
| [11529] | 74 |         this->tubeOffsetX=500; | 
|---|
| [11503] | 75 |         this->setHUDTemplate("FlappyOrxHUD"); | 
|---|
| [11481] | 76 |     } | 
|---|
 | 77 |  | 
|---|
| [11529] | 78 |     void FlappyOrx::updatePlayerPos(int x){ | 
|---|
| [11537] | 79 |  | 
|---|
| [11554] | 80 |         if(this->tubes.size()==0||x-tubes.back()+tubeOffsetX>spawnDistance){ | 
|---|
| [11529] | 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 |         } | 
|---|
| [11537] | 88 |         while((this->asteroids.front())->getPosition().x<x-300){ | 
|---|
 | 89 |             MovableEntity* deleteMe = asteroids.front(); | 
|---|
 | 90 |             asteroids.pop(); | 
|---|
 | 91 |             deleteMe->destroy(); | 
|---|
 | 92 |         } | 
|---|
| [11529] | 93 |     } | 
|---|
 | 94 |  | 
|---|
| [11503] | 95 |     void FlappyOrx::levelUp() | 
|---|
 | 96 |     { | 
|---|
| [11554] | 97 |         point++; | 
|---|
 | 98 |         spawnDistance = 300-3*point; | 
|---|
 | 99 |         getPlayer()->setSpeed(100+.5*point); | 
|---|
| [11533] | 100 |         toggleShowLevel(); | 
|---|
| [11529] | 101 |         //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this))); | 
|---|
| [11503] | 102 |     } | 
|---|
 | 103 |  | 
|---|
 | 104 |     FlappyOrxShip* FlappyOrx::getPlayer() | 
|---|
 | 105 |     { | 
|---|
 | 106 |         if (player == nullptr) | 
|---|
 | 107 |         { | 
|---|
| [11514] | 108 |             for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) { | 
|---|
| [11503] | 109 |                 player = ship; | 
|---|
| [11514] | 110 |             } | 
|---|
| [11503] | 111 |         } | 
|---|
 | 112 |         return player; | 
|---|
 | 113 |     } | 
|---|
 | 114 |  | 
|---|
| [11529] | 115 |     void FlappyOrx::spawnTube() | 
|---|
 | 116 |     { | 
|---|
| [11554] | 117 |         int space = 120; | 
|---|
| [11529] | 118 |         int height = (float(rand())/RAND_MAX-0.5)*(280-space); | 
|---|
 | 119 |             | 
|---|
 | 120 |         if (getPlayer() == nullptr) | 
|---|
 | 121 |             return; | 
|---|
| [11503] | 122 |  | 
|---|
| [11529] | 123 |         Vector3 pos = player->getPosition(); | 
|---|
| [11505] | 124 |  | 
|---|
| [11529] | 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(); | 
|---|
| [11554] | 135 |         newAsteroid.x=x; | 
|---|
 | 136 |         newAsteroid.y=y; | 
|---|
 | 137 |         newAsteroid.r=r; | 
|---|
 | 138 |         addIfPossible(newAsteroid); | 
|---|
| [11529] | 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 |  | 
|---|
| [11537] | 160 |     void deleteAsteroid(MovableEntity* asteroid){ | 
|---|
 | 161 |         //center_->getContext().getObjectList().removeElement(asteroid); | 
|---|
 | 162 |     } | 
|---|
 | 163 |  | 
|---|
| [11529] | 164 |     void FlappyOrx::createAsteroid(Circle &c){ | 
|---|
 | 165 |         MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext()); | 
|---|
| [11537] | 166 |  | 
|---|
 | 167 |  | 
|---|
| [11529] | 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 |  | 
|---|
| [11537] | 181 |         asteroids.push(newAsteroid); | 
|---|
 | 182 |  | 
|---|
 | 183 |  | 
|---|
| [11529] | 184 |     } | 
|---|
 | 185 |  | 
|---|
| [11503] | 186 |     void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center) | 
|---|
 | 187 |     { | 
|---|
 | 188 |         this->center_ = center; | 
|---|
 | 189 |     } | 
|---|
 | 190 |  | 
|---|
 | 191 |     void FlappyOrx::costLife() | 
|---|
 | 192 |     { | 
|---|
| [11537] | 193 |          | 
|---|
| [11503] | 194 |     }; | 
|---|
 | 195 |  | 
|---|
| [11563] | 196 |     bool FlappyOrx::isDead(){ | 
|---|
| [11565] | 197 |         return bIsDead; | 
|---|
| [11563] | 198 |     } | 
|---|
 | 199 |  | 
|---|
 | 200 |     std::string FlappyOrx::getDeathMessage(){ | 
|---|
| [11565] | 201 |         return sDeathMessage; | 
|---|
| [11563] | 202 |     } | 
|---|
 | 203 |  | 
|---|
| [11503] | 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 |  | 
|---|
| [11481] | 214 |     void FlappyOrx::start() | 
|---|
 | 215 |     { | 
|---|
| [11503] | 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. | 
|---|
| [11481] | 226 |         Deathmatch::start(); | 
|---|
 | 227 |     } | 
|---|
| [11503] | 228 |     void FlappyOrx::addPoints(int numPoints) | 
|---|
 | 229 |     { | 
|---|
 | 230 |         if (!bEndGame) | 
|---|
 | 231 |         { | 
|---|
 | 232 |             point += numPoints * multiplier; | 
|---|
 | 233 |             b_combo = true; | 
|---|
 | 234 |         } | 
|---|
 | 235 |     } | 
|---|
| [11481] | 236 |  | 
|---|
| [11537] | 237 |     void FlappyOrx::death(){ | 
|---|
| [11565] | 238 |         bIsDead = true; | 
|---|
 | 239 |         sDeathMessage = "GameOver"; | 
|---|
| [11537] | 240 |         if (Highscore::exists()){ | 
|---|
 | 241 |                     int score = this->getPoints(); | 
|---|
| [11554] | 242 |                     if(score > Highscore::getInstance().getHighestScoreOfGame("Flappy Orx"))  | 
|---|
 | 243 |                         Highscore::getInstance().storeHighscore("Flappy Orx",score); | 
|---|
| [11537] | 244 |         } | 
|---|
| [11554] | 245 |         point = -1; | 
|---|
 | 246 |         level=-1; | 
|---|
 | 247 |         levelUp(); | 
|---|
| [11537] | 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 |  | 
|---|
| [11481] | 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. | 
|---|
| [11503] | 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 |           } | 
|---|
| [11481] | 272 |         GSLevel::startMainMenu(); | 
|---|
 | 273 |     } | 
|---|
 | 274 | } | 
|---|