[9702] | 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 | |
---|
| 34 | #include "Invader.h" |
---|
| 35 | |
---|
| 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 | |
---|
[9709] | 44 | // ! HACK |
---|
| 45 | #include "infos/PlayerInfo.h" |
---|
| 46 | |
---|
| 47 | #include "InvaderCenterPoint.h" |
---|
[9777] | 48 | #include "InvaderShip.h" |
---|
[9793] | 49 | #include "InvaderEnemy.h" |
---|
[9874] | 50 | #include "InvaderEnemyShooter.h" |
---|
[9709] | 51 | |
---|
[9777] | 52 | #include "core/command/ConsoleCommand.h" |
---|
[9874] | 53 | #include "worldentities/BigExplosion.h" |
---|
[9777] | 54 | |
---|
[9702] | 55 | namespace orxonox |
---|
| 56 | { |
---|
| 57 | RegisterUnloadableClass(Invader); |
---|
| 58 | |
---|
| 59 | Invader::Invader(Context* context) : Deathmatch(context) |
---|
| 60 | { |
---|
| 61 | RegisterObject(Invader); |
---|
[9777] | 62 | this->center_ = 0; |
---|
[9868] | 63 | init(); |
---|
[9828] | 64 | this->setHUDTemplate("InvaderHUD"); |
---|
[9868] | 65 | } |
---|
[9777] | 66 | |
---|
[9868] | 67 | void Invader::init() |
---|
| 68 | { |
---|
| 69 | bEndGame = false; |
---|
[9829] | 70 | lives = 3; |
---|
| 71 | level = 1; |
---|
| 72 | point = 0; |
---|
[9874] | 73 | bShowLevel = false; |
---|
[9829] | 74 | multiplier = 1; |
---|
| 75 | b_combo = false; |
---|
[9874] | 76 | // spawn enemy every 3.5 seconds |
---|
| 77 | enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&Invader::spawnEnemy, this))); |
---|
| 78 | comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&Invader::comboControll, this))); |
---|
[9702] | 79 | } |
---|
| 80 | |
---|
[9874] | 81 | void Invader::levelUp() |
---|
[9777] | 82 | { |
---|
[9874] | 83 | level++; |
---|
| 84 | if (getPlayer() != NULL) |
---|
| 85 | { |
---|
| 86 | for (int i = 0; i < 7; i++) |
---|
| 87 | { |
---|
| 88 | WeakPtr<BigExplosion> chunk = new BigExplosion(this->center_->getContext()); |
---|
| 89 | chunk->setPosition(Vector3(600, 0, 100 * i - 300)); |
---|
| 90 | chunk->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
| 91 | chunk->setScale(20); |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | addPoints(multiplier * 42); |
---|
| 95 | multiplier *= 2; |
---|
| 96 | toggleShowLevel(); |
---|
| 97 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Invader::toggleShowLevel, this))); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | WeakPtr<InvaderShip> Invader::getPlayer() |
---|
| 101 | { |
---|
[9777] | 102 | if (player == NULL) |
---|
| 103 | { |
---|
| 104 | for (ObjectList<InvaderShip>::iterator it = ObjectList<InvaderShip>::begin(); it != ObjectList<InvaderShip>::end(); ++it) |
---|
| 105 | player = *it; |
---|
| 106 | } |
---|
[9874] | 107 | return player; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void Invader::spawnEnemy() |
---|
| 111 | { |
---|
| 112 | if (getPlayer() == NULL) |
---|
[9777] | 113 | return; |
---|
[9854] | 114 | srand(player->getPosition().x + player->getPosition().y); |
---|
[9879] | 115 | for (int i = 0; i < (3*log10(level) + 1); i++) |
---|
[9837] | 116 | { |
---|
[9874] | 117 | WeakPtr<InvaderEnemy> newPawn; |
---|
| 118 | if (rand() % 42/(1 + level*level) == 0) |
---|
| 119 | { |
---|
| 120 | newPawn = new InvaderEnemyShooter(this->center_->getContext()); |
---|
| 121 | newPawn->addTemplate("enemyinvadershooter"); |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
| 125 | newPawn = new InvaderEnemy(this->center_->getContext()); |
---|
| 126 | newPawn->addTemplate("enemyinvader"); |
---|
| 127 | } |
---|
[9854] | 128 | newPawn->setPlayer(player); |
---|
| 129 | newPawn->level = level; |
---|
[9868] | 130 | // spawn enemy at random points in front of player. |
---|
[9854] | 131 | newPawn->setPosition(player->getPosition() + Vector3(500 + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200)); |
---|
[9837] | 132 | } |
---|
[9777] | 133 | } |
---|
| 134 | |
---|
[9858] | 135 | void Invader::costLife() |
---|
| 136 | { |
---|
| 137 | lives--; |
---|
[9868] | 138 | multiplier = 1; |
---|
| 139 | // end the game in 30 seconds. |
---|
| 140 | if (lives <= 0) |
---|
| 141 | enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&Invader::end, this))); |
---|
[9858] | 142 | }; |
---|
| 143 | |
---|
[9829] | 144 | void Invader::comboControll() |
---|
| 145 | { |
---|
| 146 | if (b_combo) |
---|
| 147 | multiplier++; |
---|
[9868] | 148 | // if no combo was performed before, reset multiplier |
---|
[9829] | 149 | else |
---|
| 150 | multiplier = 1; |
---|
| 151 | b_combo = false; |
---|
| 152 | } |
---|
| 153 | |
---|
[9702] | 154 | void Invader::start() |
---|
| 155 | { |
---|
[9868] | 156 | init(); |
---|
[9702] | 157 | // Set variable to temporarily force the player to spawn. |
---|
| 158 | this->bForceSpawn_ = true; |
---|
| 159 | |
---|
[9709] | 160 | if (this->center_ == NULL) // abandon mission! |
---|
| 161 | { |
---|
| 162 | orxout(internal_error) << "Invader: No Centerpoint specified." << endl; |
---|
| 163 | GSLevel::startMainMenu(); |
---|
| 164 | return; |
---|
| 165 | } |
---|
[9702] | 166 | // Call start for the parent class. |
---|
| 167 | Deathmatch::start(); |
---|
| 168 | } |
---|
[9874] | 169 | void Invader::addPoints(int numPoints) |
---|
| 170 | { |
---|
| 171 | if (!bEndGame) |
---|
| 172 | { |
---|
| 173 | point += numPoints * multiplier; |
---|
| 174 | b_combo = true; |
---|
| 175 | } |
---|
| 176 | } |
---|
[9702] | 177 | |
---|
| 178 | void Invader::end() |
---|
| 179 | { |
---|
[9868] | 180 | // DON'T CALL THIS! |
---|
| 181 | // Deathmatch::end(); |
---|
| 182 | // It will misteriously crash the game! |
---|
| 183 | // Instead startMainMenu, this won't crash. |
---|
| 184 | GSLevel::startMainMenu(); |
---|
[9702] | 185 | } |
---|
| 186 | } |
---|