[11556] | 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 | * Theo von Arx |
---|
| 24 | * Noah Zarro |
---|
| 25 | * Co-authors: |
---|
| 26 | * |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | @file SOBFireball.cc |
---|
| 32 | @brief Fireballs are the Projectile of the Fireflower Powerup |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #include "SOBFireball.h" |
---|
| 36 | |
---|
| 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include "core/XMLPort.h" |
---|
| 39 | #include "SOBFigure.h" |
---|
| 40 | #include "SOBGumba.h" |
---|
| 41 | #include "SOB.h" |
---|
| 42 | #include "util/Output.h" |
---|
| 43 | #include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
| 49 | RegisterClass(SOBFireball); |
---|
| 50 | |
---|
| 51 | SOBFireball::SOBFireball(Context* context) : MovableEntity(context) |
---|
| 52 | { |
---|
| 53 | RegisterObject(SOBFireball); |
---|
| 54 | |
---|
| 55 | attachedToFigure_ = false; |
---|
| 56 | setAngularFactor(0.0); |
---|
| 57 | figure_ = nullptr; |
---|
| 58 | this->enableCollisionCallback(); |
---|
| 59 | gravityAcceleration_ = 3.0; |
---|
| 60 | speed_ = 0; |
---|
| 61 | hasCollided_=false; |
---|
| 62 | lastPos_ = getPosition(); |
---|
| 63 | lastPos_.x -= 20; |
---|
| 64 | changeAllowed_ = true; |
---|
| 65 | changedOn_ = 0.0; |
---|
| 66 | goesRight_ = true; |
---|
| 67 | collDisX_ = 0; |
---|
| 68 | collDisZ_ = 0; |
---|
| 69 | |
---|
| 70 | orxout() << "fireball existed" << endl; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | void SOBFireball::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 78 | { |
---|
| 79 | SUPER(SOBFireball, XMLPort, xmlelement, mode); |
---|
| 80 | XMLPortParam(SOBFireball, "speed", setSpeed, getSpeed, xmlelement, mode); |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | bool SOBFireball::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
---|
| 87 | collDisX_ = getPosition().x - contactPoint.getPositionWorldOnB().getX(); |
---|
| 88 | collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ(); |
---|
| 89 | |
---|
| 90 | SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject); |
---|
| 91 | |
---|
| 92 | if(gumba!=nullptr && !(gumba->hasCollided_)) //if other object is a Gumba, kill the Gumba and add score and destroy the fireball |
---|
| 93 | { |
---|
| 94 | gumba->destroyLater(); |
---|
| 95 | gumba->hasCollided_ = true; |
---|
| 96 | SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); |
---|
| 97 | SOBGame->addGumba(); |
---|
| 98 | this->destroyLater(); |
---|
| 99 | this->hasCollided_ = true; |
---|
| 100 | } |
---|
| 101 | //collision with either top or bottom of a block |
---|
| 102 | else if(changeAllowed_ && (abs(collDisX_)<=abs(collDisZ_))) |
---|
| 103 | { |
---|
| 104 | changeAllowed_ = false; |
---|
| 105 | Vector3 velocity = getVelocity(); |
---|
| 106 | velocity.z = -velocity.z; |
---|
| 107 | setVelocity(velocity); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | //collision with the vertical side of a block |
---|
| 111 | else if(changeAllowed_ && (abs(collDisX_)>abs(collDisZ_))) |
---|
| 112 | { |
---|
| 113 | changeAllowed_ = false; |
---|
| 114 | goesRight_=!goesRight_; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | return true; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | void SOBFireball::setFigure(SOBFigure* newFigure) |
---|
| 123 | { |
---|
| 124 | figure_ = newFigure; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | void SOBFireball::tick(float dt) |
---|
| 130 | { |
---|
| 131 | SUPER(SOBFireball, tick, dt); |
---|
| 132 | |
---|
| 133 | if (!changeAllowed_) { |
---|
| 134 | changedOn_+= dt; |
---|
| 135 | // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions! |
---|
| 136 | if (changedOn_> 0.200) { |
---|
| 137 | changeAllowed_ = true; |
---|
| 138 | changedOn_ = 0.0; |
---|
| 139 | |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | int dir = 1; |
---|
| 145 | if (!goesRight_) |
---|
| 146 | dir = -1; |
---|
| 147 | |
---|
| 148 | Vector3 velocity = getVelocity(); |
---|
| 149 | velocity.z -= gravityAcceleration_*dt; |
---|
| 150 | velocity.x = dir*speed_; |
---|
| 151 | setVelocity(velocity); |
---|
| 152 | |
---|
| 153 | lastPos_ = getPosition(); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | } |
---|