[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: |
---|
[11660] | 23 | * Viviane Yang |
---|
[11593] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[11617] | 29 | |
---|
[11660] | 30 | |
---|
[11593] | 31 | /** |
---|
| 32 | @file Asteroids2D.cc |
---|
| 33 | @brief Implementation of the Asteroids2D class. |
---|
[11660] | 34 | |
---|
| 35 | TODO: |
---|
| 36 | - Implement a counting system for the score |
---|
| 37 | - HUD can be improved (display health, points, level etc.) |
---|
[11668] | 38 | - Projectiles still fly in a mysterious direction |
---|
| 39 | - Problem: The asteroids spawn randomly on the playing field. |
---|
| 40 | During spawn or level up, there is the possibility that they pawn at the position of the ship. |
---|
| 41 | ->spawn somewhere with a safty distance/radius |
---|
| 42 | |
---|
[11593] | 43 | */ |
---|
| 44 | |
---|
| 45 | #include "Asteroids2D.h" |
---|
| 46 | #include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header! |
---|
[11616] | 47 | #include "Asteroids2DStone.h" |
---|
[11593] | 48 | #include "core/CoreIncludes.h" |
---|
[11608] | 49 | #include "Highscore.h" |
---|
[11593] | 50 | |
---|
| 51 | namespace orxonox |
---|
| 52 | { |
---|
| 53 | RegisterUnloadableClass(Asteroids2D); |
---|
| 54 | |
---|
| 55 | Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context) |
---|
| 56 | { |
---|
| 57 | RegisterObject(Asteroids2D); |
---|
| 58 | |
---|
[11608] | 59 | bEndGame = false; |
---|
[11668] | 60 | lives = 3; |
---|
[11608] | 61 | level = 1; |
---|
| 62 | point = 0; |
---|
| 63 | bShowLevel = false; |
---|
| 64 | multiplier = 1; |
---|
| 65 | b_combo = false; |
---|
[11616] | 66 | firstTick_ = true; |
---|
[11608] | 67 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 68 | this->center_ = nullptr; |
---|
| 69 | this->setHUDTemplate("Asteroids2DHUD"); |
---|
[11660] | 70 | levelupTimer.setTimer(30.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this))); //level up every 30s |
---|
[11593] | 71 | } |
---|
| 72 | |
---|
[11613] | 73 | |
---|
| 74 | |
---|
[11608] | 75 | void Asteroids2D::levelUp() |
---|
| 76 | { |
---|
| 77 | level++; |
---|
| 78 | if (getPlayer() != nullptr) |
---|
| 79 | { |
---|
[11637] | 80 | |
---|
[11668] | 81 | //Do something that indicates a level up |
---|
[11608] | 82 | for (int i = 0; i < 7; i++) |
---|
| 83 | { |
---|
| 84 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
| 85 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
| 86 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
| 87 | chunk5->setScale(10); |
---|
| 88 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
| 89 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
| 90 | chunk5->Explode(); |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | } |
---|
[11637] | 94 | addPoints(multiplier * 20); |
---|
[11608] | 95 | multiplier *= 2; |
---|
| 96 | toggleShowLevel(); |
---|
| 97 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this))); |
---|
[11637] | 98 | |
---|
| 99 | |
---|
[11668] | 100 | //After level up -> spawn stones. Modify for different difficulty level |
---|
[11617] | 101 | for(int i = 0; i < level*2; i++){ |
---|
| 102 | spawnStone(); |
---|
| 103 | } |
---|
| 104 | |
---|
[11608] | 105 | } |
---|
| 106 | |
---|
[11593] | 107 | void Asteroids2D::tick(float dt) |
---|
| 108 | { |
---|
[11660] | 109 | //Do this only for the first tick, generate 5 stones in the beginning |
---|
[11616] | 110 | if(this->firstTick_) |
---|
| 111 | { |
---|
[11637] | 112 | getPlayer(); |
---|
[11616] | 113 | for(int i = 0; i < 5; ++i) |
---|
| 114 | { |
---|
| 115 | spawnStone(); |
---|
| 116 | } |
---|
[11668] | 117 | //after first tick, firstTick_ will remain false |
---|
[11616] | 118 | this->firstTick_ = false; |
---|
| 119 | } |
---|
[11608] | 120 | |
---|
[11593] | 121 | SUPER(Asteroids2D, tick, dt); |
---|
| 122 | } |
---|
| 123 | |
---|
[11616] | 124 | void Asteroids2D::spawnStone() |
---|
| 125 | { |
---|
[11660] | 126 | |
---|
[11668] | 127 | //stones are created with a size -> second constructor in Asteroids2DStone class |
---|
[11616] | 128 | Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext()); |
---|
| 129 | newStone->setAsteroids2DPlayer(player); |
---|
| 130 | |
---|
[11668] | 131 | //look at templates in data/levels/templates/asteroidsAsteroids2D.oxt |
---|
[11617] | 132 | switch(newStone->getSize()){ |
---|
| 133 | case 1: |
---|
| 134 | newStone->addTemplate("stone1"); |
---|
| 135 | break; |
---|
| 136 | case 2: |
---|
| 137 | newStone->addTemplate("stone2"); |
---|
| 138 | break; |
---|
| 139 | case 3: |
---|
| 140 | newStone->addTemplate("stone3"); |
---|
| 141 | break; |
---|
| 142 | default: |
---|
| 143 | orxout(internal_error) << "Asteroids2DStone has invalid size and cannot be created" << endl; |
---|
| 144 | break; |
---|
| 145 | |
---|
| 146 | } |
---|
[11616] | 147 | } |
---|
| 148 | |
---|
[11593] | 149 | Asteroids2DShip* Asteroids2D::getPlayer() |
---|
| 150 | { |
---|
| 151 | if (player == nullptr) |
---|
| 152 | { |
---|
| 153 | for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>()) |
---|
| 154 | { |
---|
| 155 | player = ship; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | return player; |
---|
| 159 | } |
---|
| 160 | |
---|
[11608] | 161 | void Asteroids2D::costLife() |
---|
| 162 | { |
---|
[11617] | 163 | --lives; |
---|
[11619] | 164 | if(lives <= 0){ |
---|
[11617] | 165 | endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this))); |
---|
| 166 | } |
---|
[11608] | 167 | }; |
---|
[11617] | 168 | |
---|
[11660] | 169 | //The first function that will be called |
---|
[11593] | 170 | void Asteroids2D::start() |
---|
| 171 | { |
---|
[11668] | 172 | //orxout() << "start" << endl; |
---|
[11608] | 173 | |
---|
[11593] | 174 | // Set variable to temporarily force the player to spawn. |
---|
| 175 | this->bForceSpawn_ = false; |
---|
| 176 | |
---|
| 177 | if (this->center_ == nullptr) // abandon mission! |
---|
| 178 | { |
---|
| 179 | orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl; |
---|
| 180 | GSLevel::startMainMenu(); |
---|
| 181 | return; |
---|
| 182 | } |
---|
| 183 | // Call start for the parent class. |
---|
| 184 | Deathmatch::start(); |
---|
| 185 | } |
---|
| 186 | |
---|
[11608] | 187 | void Asteroids2D::playerPreSpawn(PlayerInfo* player) |
---|
| 188 | { |
---|
| 189 | if(lives <= 0) |
---|
| 190 | { |
---|
| 191 | this->end(); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
[11668] | 195 | //This function will be called from the ship or the stone class (if the stone was hit) |
---|
[11608] | 196 | void Asteroids2D::addPoints(int numPoints) |
---|
| 197 | { |
---|
| 198 | if (!bEndGame) |
---|
| 199 | { |
---|
| 200 | point += numPoints * multiplier; |
---|
| 201 | b_combo = true; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
[11593] | 205 | void Asteroids2D::end() |
---|
| 206 | { |
---|
| 207 | // DON'T CALL THIS! |
---|
| 208 | // Deathmatch::end(); |
---|
| 209 | // It will misteriously crash the game! |
---|
| 210 | // Instead startMainMenu, this won't crash. |
---|
[11608] | 211 | if (Highscore::exists()){ |
---|
| 212 | int score = this->getPoints(); |
---|
[11616] | 213 | if(score > Highscore::getInstance().getHighestScoreOfGame("Asteroids2D")) |
---|
| 214 | Highscore::getInstance().storeHighscore("Asteroids2D",score); |
---|
[11608] | 215 | |
---|
| 216 | } |
---|
[11593] | 217 | GSLevel::startMainMenu(); |
---|
| 218 | } |
---|
| 219 | } |
---|