[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" |
---|
| 49 | |
---|
| 50 | #include "core/command/ConsoleCommand.h" |
---|
| 51 | #include "worldentities/ExplosionPart.h" |
---|
| 52 | |
---|
[11481] | 53 | namespace orxonox |
---|
| 54 | { |
---|
| 55 | RegisterUnloadableClass(FlappyOrx); |
---|
| 56 | |
---|
| 57 | FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context) |
---|
| 58 | { |
---|
| 59 | RegisterObject(FlappyOrx); |
---|
[11503] | 60 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 61 | this->center_ = nullptr; |
---|
| 62 | bEndGame = false; |
---|
| 63 | lives = 3; |
---|
| 64 | level = 1; |
---|
| 65 | point = 0; |
---|
| 66 | bShowLevel = false; |
---|
| 67 | multiplier = 1; |
---|
| 68 | b_combo = false; |
---|
| 69 | |
---|
| 70 | this->setHUDTemplate("FlappyOrxHUD"); |
---|
[11481] | 71 | } |
---|
| 72 | |
---|
[11503] | 73 | void FlappyOrx::levelUp() |
---|
| 74 | { |
---|
| 75 | level++; |
---|
| 76 | if (getPlayer() != nullptr) |
---|
| 77 | { |
---|
| 78 | for (int i = 0; i < 7; i++) |
---|
| 79 | { |
---|
| 80 | |
---|
| 81 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
| 82 | chunk5->setPosition(this->center_->getPosition()); |
---|
| 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->setMinSpeed(0); |
---|
| 88 | chunk5->setMaxSpeed(0); |
---|
| 89 | chunk5->Explode(); |
---|
| 90 | |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | addPoints(multiplier * 42); |
---|
| 94 | multiplier *= 2; |
---|
| 95 | toggleShowLevel(); |
---|
| 96 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this))); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | FlappyOrxShip* FlappyOrx::getPlayer() |
---|
| 100 | { |
---|
| 101 | if (player == nullptr) |
---|
| 102 | { |
---|
| 103 | for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) |
---|
| 104 | player = ship; |
---|
| 105 | } |
---|
| 106 | return player; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[11505] | 110 | |
---|
[11503] | 111 | void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center) |
---|
| 112 | { |
---|
| 113 | this->center_ = center; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void FlappyOrx::costLife() |
---|
| 117 | { |
---|
| 118 | lives--; |
---|
| 119 | multiplier = 1; |
---|
| 120 | // end the game in 30 seconds. |
---|
| 121 | if (lives <= 0) |
---|
| 122 | enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&FlappyOrx::end, this))); |
---|
| 123 | }; |
---|
| 124 | |
---|
| 125 | void FlappyOrx::comboControll() |
---|
| 126 | { |
---|
| 127 | if (b_combo) |
---|
| 128 | multiplier++; |
---|
| 129 | // if no combo was performed before, reset multiplier |
---|
| 130 | else |
---|
| 131 | multiplier = 1; |
---|
| 132 | b_combo = false; |
---|
| 133 | } |
---|
| 134 | |
---|
[11481] | 135 | void FlappyOrx::start() |
---|
| 136 | { |
---|
[11503] | 137 | // Set variable to temporarily force the player to spawn. |
---|
| 138 | this->bForceSpawn_ = true; |
---|
| 139 | |
---|
| 140 | if (this->center_ == nullptr) // abandon mission! |
---|
| 141 | { |
---|
| 142 | orxout(internal_error) << "FlappyOrx: No Centerpoint specified." << endl; |
---|
| 143 | GSLevel::startMainMenu(); |
---|
| 144 | return; |
---|
| 145 | } |
---|
| 146 | // Call start for the parent class. |
---|
[11481] | 147 | Deathmatch::start(); |
---|
| 148 | } |
---|
[11503] | 149 | void FlappyOrx::addPoints(int numPoints) |
---|
| 150 | { |
---|
| 151 | if (!bEndGame) |
---|
| 152 | { |
---|
| 153 | point += numPoints * multiplier; |
---|
| 154 | b_combo = true; |
---|
| 155 | } |
---|
| 156 | } |
---|
[11481] | 157 | |
---|
| 158 | void FlappyOrx::end() |
---|
| 159 | { |
---|
| 160 | // DON'T CALL THIS! |
---|
| 161 | // Deathmatch::end(); |
---|
| 162 | // It will misteriously crash the game! |
---|
| 163 | // Instead startMainMenu, this won't crash. |
---|
[11503] | 164 | if (Highscore::exists()){ |
---|
| 165 | int score = this->getPoints(); |
---|
| 166 | if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade")) |
---|
| 167 | Highscore::getInstance().storeHighscore("Orxonox Arcade",score); |
---|
| 168 | |
---|
| 169 | } |
---|
[11481] | 170 | GSLevel::startMainMenu(); |
---|
| 171 | } |
---|
| 172 | } |
---|