[11593] | 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 MiniGameTest.cc |
---|
| 31 | @brief Implementation of the MiniGameTest class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "MiniGameTest.h" |
---|
| 35 | #include "MiniGameTestShip.h" // Necessary for getPlayer function. Do NOT include this in Header! |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "Highscore.h" |
---|
| 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | RegisterUnloadableClass(MiniGameTest); |
---|
| 42 | |
---|
| 43 | MiniGameTest::MiniGameTest(Context* context) : Deathmatch(context) |
---|
| 44 | { |
---|
| 45 | RegisterObject(MiniGameTest); |
---|
| 46 | |
---|
| 47 | bEndGame = false; |
---|
| 48 | lives = 1; |
---|
| 49 | level = 1; |
---|
| 50 | point = 0; |
---|
| 51 | bShowLevel = false; |
---|
| 52 | multiplier = 1; |
---|
| 53 | b_combo = false; |
---|
| 54 | counter = 5000; |
---|
| 55 | pattern = 1; |
---|
| 56 | lastPosition = 0; |
---|
| 57 | // spawn enemy every 3.5 seconds |
---|
| 58 | //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&MiniGameTest::spawnEnemy, this))); |
---|
| 59 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 60 | this->center_ = nullptr; |
---|
| 61 | this->setHUDTemplate("MiniGameTestHUD"); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void MiniGameTest::levelUp() |
---|
| 65 | { |
---|
| 66 | level++; |
---|
| 67 | if (getPlayer() != nullptr) |
---|
| 68 | { |
---|
| 69 | for (int i = 0; i < 7; i++) |
---|
| 70 | { |
---|
| 71 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
| 72 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
| 73 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
| 74 | chunk5->setScale(10); |
---|
| 75 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
| 76 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
| 77 | chunk5->Explode(); |
---|
| 78 | |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | addPoints(multiplier * 42); |
---|
| 82 | multiplier *= 2; |
---|
| 83 | toggleShowLevel(); |
---|
| 84 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&MiniGameTest::toggleShowLevel, this))); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void MiniGameTest::tick(float dt) |
---|
| 88 | { |
---|
[11608] | 89 | |
---|
[11593] | 90 | SUPER(MiniGameTest, tick, dt); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | MiniGameTestShip* MiniGameTest::getPlayer() |
---|
| 94 | { |
---|
| 95 | if (player == nullptr) |
---|
| 96 | { |
---|
| 97 | for (MiniGameTestShip* ship : ObjectList<MiniGameTestShip>()) |
---|
| 98 | { |
---|
| 99 | player = ship; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | return player; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void MiniGameTest::costLife() |
---|
| 106 | { |
---|
| 107 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&MiniGameTest::end, this))); |
---|
| 108 | lives = 0; |
---|
| 109 | }; |
---|
| 110 | |
---|
| 111 | void MiniGameTest::start() |
---|
| 112 | { |
---|
| 113 | orxout() << "start" << endl; |
---|
| 114 | |
---|
| 115 | // Set variable to temporarily force the player to spawn. |
---|
| 116 | this->bForceSpawn_ = false; |
---|
| 117 | |
---|
| 118 | if (this->center_ == nullptr) // abandon mission! |
---|
| 119 | { |
---|
| 120 | orxout(internal_error) << "MiniGameTest: No Centerpoint specified." << endl; |
---|
| 121 | GSLevel::startMainMenu(); |
---|
| 122 | return; |
---|
| 123 | } |
---|
| 124 | // Call start for the parent class. |
---|
| 125 | Deathmatch::start(); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void MiniGameTest::playerPreSpawn(PlayerInfo* player) |
---|
| 129 | { |
---|
| 130 | if(lives <= 0) |
---|
| 131 | { |
---|
| 132 | this->end(); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | void MiniGameTest::addPoints(int numPoints) |
---|
| 137 | { |
---|
| 138 | if (!bEndGame) |
---|
| 139 | { |
---|
| 140 | point += numPoints * multiplier; |
---|
| 141 | b_combo = true; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | void MiniGameTest::end() |
---|
| 146 | { |
---|
| 147 | // DON'T CALL THIS! |
---|
| 148 | // Deathmatch::end(); |
---|
| 149 | // It will misteriously crash the game! |
---|
| 150 | // Instead startMainMenu, this won't crash. |
---|
| 151 | if (Highscore::exists()){ |
---|
| 152 | int score = this->getPoints(); |
---|
| 153 | if(score > Highscore::getInstance().getHighestScoreOfGame("Dodge Race")) |
---|
| 154 | Highscore::getInstance().storeHighscore("Dodge Race",score); |
---|
| 155 | |
---|
| 156 | } |
---|
| 157 | GSLevel::startMainMenu(); |
---|
| 158 | } |
---|
| 159 | } |
---|