[11623] | 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 | * Noah Zarro |
---|
| 24 | * Theo von Arx |
---|
| 25 | * Co-authors: |
---|
| 26 | * |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | @file SOBGumbaBoss.cc |
---|
| 32 | @brief All items in this minigame inherit from this class. Items can move around like platforms and enemies. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #include "SOB.h" |
---|
| 36 | #include "SOBGumba.h" |
---|
| 37 | #include "SOBGumbaBoss.h" |
---|
| 38 | #include "SOBFireball.h" |
---|
| 39 | #include "SOBFigure.h" |
---|
| 40 | |
---|
| 41 | #include "core/CoreIncludes.h" |
---|
| 42 | #include "core/XMLPort.h" |
---|
| 43 | #include "util/Output.h" |
---|
| 44 | #include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
| 50 | RegisterClass(SOBGumbaBoss); |
---|
| 51 | |
---|
| 52 | SOBGumbaBoss::SOBGumbaBoss(Context* context) : SOBGumba(context) |
---|
| 53 | { |
---|
| 54 | RegisterObject(SOBGumbaBoss); |
---|
| 55 | |
---|
[11628] | 56 | gumbaMaxTime_ = 5; |
---|
[11623] | 57 | gumbaTime_ = 0; |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
---|
| 65 | |
---|
| 66 | //Every object with mass -1 does not change the direction of the GumbaBoss. For example the ground floor! The other objects switch the direction of the GumbaBoss. |
---|
| 67 | if (changeAllowed_ && otherObject->getMass() != -1) { |
---|
| 68 | goesRight_ = !goesRight_; |
---|
| 69 | changeAllowed_ = false; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | return true; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | void SOBGumbaBoss::tick(float dt) |
---|
| 79 | { |
---|
| 80 | SUPER(SOBGumbaBoss, tick, dt); |
---|
| 81 | |
---|
| 82 | if (!changeAllowed_) { |
---|
| 83 | changedOn_+= dt; |
---|
| 84 | // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions! |
---|
| 85 | if (changedOn_> 0.200) { |
---|
| 86 | changeAllowed_ = true; |
---|
| 87 | changedOn_ = 0.0; |
---|
| 88 | |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | gumbaTime_ += dt; |
---|
| 93 | |
---|
| 94 | if(gumbaTime_ > gumbaMaxTime_){ |
---|
| 95 | spawnFireball(); |
---|
| 96 | gumbaTime_ = 0; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | int dir = 1; |
---|
| 100 | if (!goesRight_) |
---|
| 101 | dir = -1; |
---|
| 102 | |
---|
| 103 | Vector3 velocity = getVelocity(); |
---|
| 104 | velocity.z -= gravityAcceleration_*dt; |
---|
| 105 | velocity.x = dir*speed_; |
---|
| 106 | setVelocity(velocity); |
---|
| 107 | |
---|
| 108 | lastPos_ = getPosition(); |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | void SOBGumbaBoss::spawnFireball() { |
---|
| 112 | SOBCenterpoint* center_ = ((SOB*)getGametype())->center_; |
---|
| 113 | |
---|
| 114 | SOBFireball* ball = new SOBFireball(center_->getContext()); |
---|
| 115 | Vector3 spawnpos = this->getWorldPosition(); |
---|
| 116 | spawnpos.z += 0; |
---|
| 117 | |
---|
| 118 | if (ball != nullptr && center_ != nullptr) |
---|
| 119 | { |
---|
| 120 | ball->addTemplate("fireball"); |
---|
| 121 | bool direction = ((this->getWorldOrientation().getRoll().valueRadians())>-1.6&&(this->getWorldOrientation().getRoll().valueRadians()<1.6)); |
---|
| 122 | ball->setDirection(direction); |
---|
| 123 | if(direction) |
---|
| 124 | { |
---|
| 125 | spawnpos.x+=10; |
---|
| 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
| 129 | spawnpos.x-=10; |
---|
| 130 | } |
---|
| 131 | ball->setPosition(spawnpos); |
---|
| 132 | |
---|
| 133 | } |
---|
[11626] | 134 | |
---|
| 135 | Vector3 velocity = ball->getVelocity(); |
---|
| 136 | velocity.z -= 100; |
---|
| 137 | ball->setVelocity(velocity); |
---|
[11623] | 138 | } |
---|
| 139 | } |
---|