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