[11400] | 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: |
---|
[11416] | 23 | * Julien Kindle |
---|
[11400] | 24 | * Co-authors: |
---|
[11416] | 25 | * |
---|
[11400] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file SOBQBlock.cc |
---|
| 31 | @brief If this QBlock is created, attachedToFigure_ is set to false. When the figure picks it up, the variable is set to true and the figure starts flying fast until the fuel is reduced to zero. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "SOBQBlock.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
[11405] | 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "SOB.h" |
---|
| 39 | #include "SOBMushroom.h" |
---|
[11416] | 40 | #include "SOBCoin.h" |
---|
[11400] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | RegisterClass(SOBQBlock); |
---|
| 45 | |
---|
| 46 | SOBQBlock::SOBQBlock(Context* context) : SOBItem(context) |
---|
| 47 | { |
---|
| 48 | RegisterObject(SOBQBlock); |
---|
| 49 | used_ = false; |
---|
[11416] | 50 | |
---|
[11400] | 51 | } |
---|
| 52 | |
---|
| 53 | SOBQBlock::~SOBQBlock() |
---|
| 54 | { |
---|
| 55 | |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | bool SOBQBlock::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
---|
| 60 | |
---|
[11416] | 61 | |
---|
| 62 | //If you hit the QBlock, the visibility of all attached objects get inverted! Pretty easy way to create changing blocks :) |
---|
[11400] | 63 | float v_z = otherObject->getVelocity().z; |
---|
| 64 | if (!used_ && v_z > 50.0) { |
---|
| 65 | used_ = true; |
---|
| 66 | |
---|
[11405] | 67 | for (WorldEntity* object : this->getAttachedObjects()) |
---|
| 68 | object->setVisible(!object->isVisible()); |
---|
| 69 | |
---|
| 70 | SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); |
---|
[11416] | 71 | |
---|
| 72 | //Spawn either a powerup mushroom or a coin animation (also just an object, have a look at the SOBCoin class) |
---|
| 73 | //The spawn methods are declared at the bottom of this file |
---|
[11405] | 74 | if (type_ == "Coin") { |
---|
| 75 | SOBGame->addCoin(); |
---|
[11416] | 76 | spawnCoin(); |
---|
[11400] | 77 | } |
---|
[11405] | 78 | if (type_ == "Mushroom") { |
---|
| 79 | spawnMushroom(); |
---|
| 80 | } |
---|
[11400] | 81 | |
---|
| 82 | } |
---|
| 83 | return true; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
[11405] | 87 | void SOBQBlock::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 88 | { |
---|
| 89 | SUPER(SOBQBlock, XMLPort, xmlelement, mode); |
---|
| 90 | XMLPortParam(SOBQBlock, "type", setType, getType, xmlelement, mode).defaultValues(false); |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
[11416] | 96 | //The spawnmethods from above |
---|
[11405] | 97 | void SOBQBlock::spawnMushroom() { |
---|
| 98 | SOBCenterpoint* center_ = ((SOB*)getGametype())->center_; |
---|
| 99 | |
---|
| 100 | SOBMushroom* mush = new SOBMushroom(center_->getContext()); |
---|
| 101 | Vector3 spawnpos = this->getWorldPosition(); |
---|
| 102 | spawnpos.z += 0; |
---|
| 103 | |
---|
| 104 | if (mush != nullptr && center_ != nullptr) |
---|
| 105 | { |
---|
| 106 | mush->addTemplate("mushroom"); |
---|
[11416] | 107 | mush->setPosition(spawnpos); |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | } |
---|
[11405] | 111 | |
---|
[11416] | 112 | void SOBQBlock::spawnCoin() { |
---|
| 113 | SOBCenterpoint* center_ = ((SOB*)getGametype())->center_; |
---|
[11405] | 114 | |
---|
[11416] | 115 | SOBCoin* mush = new SOBCoin(center_->getContext()); |
---|
| 116 | Vector3 spawnpos = this->getWorldPosition(); |
---|
| 117 | spawnpos.z += 0; |
---|
| 118 | |
---|
| 119 | if (mush != nullptr && center_ != nullptr) |
---|
| 120 | { |
---|
| 121 | mush->addTemplate("coin"); |
---|
[11405] | 122 | mush->setPosition(spawnpos); |
---|
[11416] | 123 | |
---|
[11405] | 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
[11400] | 128 | } |
---|