[11516] | 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 Invader.cc |
---|
| 31 | @brief Implementation of the Invader class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[11506] | 34 | #include "Asteroids.h" |
---|
[11516] | 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" |
---|
[11506] | 40 | |
---|
[11516] | 41 | #include "gamestates/GSLevel.h" |
---|
| 42 | #include "chat/ChatManager.h" |
---|
| 43 | |
---|
| 44 | // ! HACK |
---|
| 45 | #include "infos/PlayerInfo.h" |
---|
| 46 | |
---|
| 47 | #include "AsteroidsCenterPoint.h" |
---|
| 48 | #include "AsteroidsShip.h" |
---|
| 49 | |
---|
| 50 | #include "core/command/ConsoleCommand.h" |
---|
| 51 | #include "worldentities/ExplosionPart.h" |
---|
| 52 | |
---|
[11506] | 53 | namespace orxonox |
---|
| 54 | { |
---|
[11516] | 55 | RegisterUnloadableClass(Asteroids); |
---|
[11506] | 56 | |
---|
[11516] | 57 | Asteroids::Asteroids(Context* context) : Deathmatch(context) |
---|
| 58 | { |
---|
| 59 | RegisterObject(Asteroids); |
---|
| 60 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 61 | this->center_ = nullptr; |
---|
[11555] | 62 | this->lives = 3; |
---|
[11516] | 63 | bEndGame = false; |
---|
| 64 | lives = 3; |
---|
| 65 | point = 0; |
---|
[11506] | 66 | |
---|
[11528] | 67 | // Pre-set the timer, but don't start it yet. |
---|
[11555] | 68 | //this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this))); |
---|
[11516] | 69 | } |
---|
[11506] | 70 | |
---|
[11528] | 71 | //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird |
---|
[11541] | 72 | void Asteroids::spawnStone() |
---|
| 73 | { |
---|
| 74 | if(getPlayer() == nullptr) return; |
---|
[11516] | 75 | |
---|
[11528] | 76 | AsteroidsStone* newStone; |
---|
| 77 | newStone = new AsteroidsStone(this->center_->getContext()); |
---|
| 78 | newStone->addTemplate("asteroidsstone"); |
---|
| 79 | newStone->setAsteroidsPlayer(player); |
---|
| 80 | } |
---|
| 81 | |
---|
[11555] | 82 | void Asteroids::spawnStone(int newsize) |
---|
[11528] | 83 | { |
---|
[11555] | 84 | //no player -> should end game? |
---|
| 85 | if(getPlayer() == nullptr) return; |
---|
| 86 | //invalid size |
---|
| 87 | if(newsize > 3 || newsize < 1) return; |
---|
| 88 | AsteroidsStone* newStone; |
---|
| 89 | newStone = new AsteroidsStone(this->center_->getContext()); |
---|
| 90 | newStone.size = newsize; |
---|
| 91 | if(newsize == 1) newStone->addTemplate("asteroidsstone1"); |
---|
| 92 | else if(newsize == 2) newStone->addTemplate("asteroidsstone2"); |
---|
| 93 | else newStone->addTemplate("asteroidsstone3"); |
---|
| 94 | newStone->setAsteroidsPlayer(player); |
---|
[11528] | 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
[11516] | 98 | AsteroidsShip* Asteroids::getPlayer() |
---|
[11506] | 99 | { |
---|
[11516] | 100 | if (player == nullptr) |
---|
| 101 | { |
---|
| 102 | for (Asteroids* ship : ObjectList<AsteroidsShip>()) |
---|
| 103 | player = ship; |
---|
| 104 | } |
---|
| 105 | return player; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | void Asteroids::setCenterpoint(AsteroidsCenterPoint* center) |
---|
| 110 | { |
---|
[11506] | 111 | this->center_ = center; |
---|
| 112 | } |
---|
| 113 | |
---|
[11516] | 114 | void Asteroids::costLife() |
---|
| 115 | { |
---|
| 116 | lives = 0; |
---|
[11541] | 117 | } |
---|
| 118 | |
---|
[11516] | 119 | void Asteroids::start() |
---|
| 120 | { |
---|
[11528] | 121 | if (this->center_ == nullptr) // There needs to be a AsteroidsCenterpoint, i.e. the area the game takes place. If no centerpoint was specified, an error is thrown and the level is exited. |
---|
[11516] | 122 | { |
---|
[11528] | 123 | orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl; |
---|
[11516] | 124 | GSLevel::startMainMenu(); |
---|
| 125 | return; |
---|
| 126 | } |
---|
[11528] | 127 | |
---|
| 128 | // Set variable to temporarily force the player to spawn. |
---|
| 129 | bool temp = this->bForceSpawn_; |
---|
| 130 | this->bForceSpawn_ = true; |
---|
| 131 | |
---|
[11516] | 132 | // Call start for the parent class. |
---|
| 133 | Deathmatch::start(); |
---|
[11528] | 134 | |
---|
| 135 | // Reset the variable. |
---|
| 136 | this->bForceSpawn_ = temp; |
---|
[11516] | 137 | } |
---|
| 138 | |
---|
| 139 | void Asteroids::addPoints(int numPoints) |
---|
| 140 | { |
---|
| 141 | if (!bEndGame) |
---|
| 142 | { |
---|
| 143 | point += numPoints; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void Asteroids::end() |
---|
| 148 | { |
---|
| 149 | // DON'T CALL THIS! |
---|
| 150 | // Deathmatch::end(); |
---|
| 151 | // It will misteriously crash the game! |
---|
| 152 | // Instead startMainMenu, this won't crash. |
---|
| 153 | GSLevel::startMainMenu(); |
---|
| 154 | } |
---|
[11555] | 155 | } |
---|