[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" |
---|
[11727] | 56 | #include "Asteroids2DCenterPoint.h" |
---|
| 57 | #include "Asteroids2DHUDinfo.h" |
---|
[11593] | 58 | #include "core/CoreIncludes.h" |
---|
[11608] | 59 | #include "Highscore.h" |
---|
[11727] | 60 | #include "gamestates/GSLevel.h" |
---|
[11593] | 61 | |
---|
| 62 | namespace orxonox |
---|
| 63 | { |
---|
| 64 | RegisterUnloadableClass(Asteroids2D); |
---|
| 65 | |
---|
| 66 | Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context) |
---|
| 67 | { |
---|
| 68 | RegisterObject(Asteroids2D); |
---|
| 69 | |
---|
[11608] | 70 | bEndGame = false; |
---|
[11668] | 71 | lives = 3; |
---|
[11608] | 72 | level = 1; |
---|
| 73 | point = 0; |
---|
| 74 | bShowLevel = false; |
---|
| 75 | multiplier = 1; |
---|
| 76 | b_combo = false; |
---|
[11616] | 77 | firstTick_ = true; |
---|
[11608] | 78 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 79 | this->center_ = nullptr; |
---|
| 80 | this->setHUDTemplate("Asteroids2DHUD"); |
---|
[11660] | 81 | levelupTimer.setTimer(30.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this))); //level up every 30s |
---|
[11593] | 82 | } |
---|
| 83 | |
---|
[11727] | 84 | void Asteroids2D::setCenterpoint(Asteroids2DCenterPoint* center) |
---|
| 85 | { |
---|
| 86 | this->center_ = center; |
---|
| 87 | } |
---|
[11613] | 88 | |
---|
[11608] | 89 | void Asteroids2D::levelUp() |
---|
| 90 | { |
---|
| 91 | level++; |
---|
| 92 | if (getPlayer() != nullptr) |
---|
| 93 | { |
---|
[11637] | 94 | |
---|
[11668] | 95 | //Do something that indicates a level up |
---|
[11608] | 96 | for (int i = 0; i < 7; i++) |
---|
| 97 | { |
---|
| 98 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
| 99 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
| 100 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
| 101 | chunk5->setScale(10); |
---|
| 102 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
| 103 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
| 104 | chunk5->Explode(); |
---|
| 105 | |
---|
| 106 | } |
---|
| 107 | } |
---|
[11637] | 108 | addPoints(multiplier * 20); |
---|
[11608] | 109 | multiplier *= 2; |
---|
| 110 | toggleShowLevel(); |
---|
| 111 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this))); |
---|
[11637] | 112 | |
---|
| 113 | |
---|
[11668] | 114 | //After level up -> spawn stones. Modify for different difficulty level |
---|
[11617] | 115 | for(int i = 0; i < level*2; i++){ |
---|
| 116 | spawnStone(); |
---|
| 117 | } |
---|
| 118 | |
---|
[11608] | 119 | } |
---|
| 120 | |
---|
[11593] | 121 | void Asteroids2D::tick(float dt) |
---|
| 122 | { |
---|
[11660] | 123 | //Do this only for the first tick, generate 5 stones in the beginning |
---|
[11616] | 124 | if(this->firstTick_) |
---|
| 125 | { |
---|
[11637] | 126 | getPlayer(); |
---|
[11616] | 127 | for(int i = 0; i < 5; ++i) |
---|
| 128 | { |
---|
| 129 | spawnStone(); |
---|
| 130 | } |
---|
[11668] | 131 | //after first tick, firstTick_ will remain false |
---|
[11616] | 132 | this->firstTick_ = false; |
---|
| 133 | } |
---|
[11608] | 134 | |
---|
[11593] | 135 | SUPER(Asteroids2D, tick, dt); |
---|
| 136 | } |
---|
| 137 | |
---|
[11616] | 138 | void Asteroids2D::spawnStone() |
---|
| 139 | { |
---|
[11660] | 140 | |
---|
[11668] | 141 | //stones are created with a size -> second constructor in Asteroids2DStone class |
---|
[11616] | 142 | Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext()); |
---|
| 143 | newStone->setAsteroids2DPlayer(player); |
---|
| 144 | |
---|
[11668] | 145 | //look at templates in data/levels/templates/asteroidsAsteroids2D.oxt |
---|
[11617] | 146 | switch(newStone->getSize()){ |
---|
| 147 | case 1: |
---|
| 148 | newStone->addTemplate("stone1"); |
---|
| 149 | break; |
---|
| 150 | case 2: |
---|
| 151 | newStone->addTemplate("stone2"); |
---|
| 152 | break; |
---|
| 153 | case 3: |
---|
| 154 | newStone->addTemplate("stone3"); |
---|
| 155 | break; |
---|
| 156 | default: |
---|
| 157 | orxout(internal_error) << "Asteroids2DStone has invalid size and cannot be created" << endl; |
---|
| 158 | break; |
---|
| 159 | |
---|
| 160 | } |
---|
[11616] | 161 | } |
---|
| 162 | |
---|
[11593] | 163 | Asteroids2DShip* Asteroids2D::getPlayer() |
---|
| 164 | { |
---|
| 165 | if (player == nullptr) |
---|
| 166 | { |
---|
| 167 | for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>()) |
---|
| 168 | { |
---|
| 169 | player = ship; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | return player; |
---|
| 173 | } |
---|
| 174 | |
---|
[11608] | 175 | void Asteroids2D::costLife() |
---|
| 176 | { |
---|
[11617] | 177 | --lives; |
---|
[11619] | 178 | if(lives <= 0){ |
---|
[11617] | 179 | endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this))); |
---|
| 180 | } |
---|
[11608] | 181 | }; |
---|
[11617] | 182 | |
---|
[11660] | 183 | //The first function that will be called |
---|
[11593] | 184 | void Asteroids2D::start() |
---|
| 185 | { |
---|
[11668] | 186 | //orxout() << "start" << endl; |
---|
[11608] | 187 | |
---|
[11593] | 188 | // Set variable to temporarily force the player to spawn. |
---|
| 189 | this->bForceSpawn_ = false; |
---|
| 190 | |
---|
| 191 | if (this->center_ == nullptr) // abandon mission! |
---|
| 192 | { |
---|
| 193 | orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl; |
---|
| 194 | GSLevel::startMainMenu(); |
---|
| 195 | return; |
---|
| 196 | } |
---|
| 197 | // Call start for the parent class. |
---|
| 198 | Deathmatch::start(); |
---|
| 199 | } |
---|
| 200 | |
---|
[11608] | 201 | void Asteroids2D::playerPreSpawn(PlayerInfo* player) |
---|
| 202 | { |
---|
| 203 | if(lives <= 0) |
---|
| 204 | { |
---|
| 205 | this->end(); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | |
---|
[11668] | 209 | //This function will be called from the ship or the stone class (if the stone was hit) |
---|
[11608] | 210 | void Asteroids2D::addPoints(int numPoints) |
---|
| 211 | { |
---|
| 212 | if (!bEndGame) |
---|
| 213 | { |
---|
| 214 | point += numPoints * multiplier; |
---|
| 215 | b_combo = true; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
[11593] | 219 | void Asteroids2D::end() |
---|
| 220 | { |
---|
| 221 | // DON'T CALL THIS! |
---|
| 222 | // Deathmatch::end(); |
---|
| 223 | // It will misteriously crash the game! |
---|
| 224 | // Instead startMainMenu, this won't crash. |
---|
[11726] | 225 | if (Highscore::exists()) |
---|
| 226 | { |
---|
| 227 | int score = this->getPoints(); |
---|
| 228 | Highscore::getInstance().storeScore("Asteroids2D", score, this->getPlayer()->getPlayer()); |
---|
| 229 | } |
---|
[11593] | 230 | GSLevel::startMainMenu(); |
---|
| 231 | } |
---|
| 232 | } |
---|