[11379] | 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 | * Fabien Vultier |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file SOBFigure.cc |
---|
| 31 | @brief This class represents your figure when you play the minigame. Here the movement of the figure, activating items, ... are handled. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "SOBFigure.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "graphics/Model.h" |
---|
[11383] | 39 | #include "graphics/Camera.h" |
---|
[11400] | 40 | #include "graphics/ParticleSpawner.h" |
---|
[11379] | 41 | |
---|
[11400] | 42 | |
---|
[11379] | 43 | namespace orxonox |
---|
| 44 | { |
---|
| 45 | RegisterClass(SOBFigure); |
---|
| 46 | |
---|
| 47 | SOBFigure::SOBFigure(Context* context) : ControllableEntity(context) |
---|
| 48 | { |
---|
| 49 | RegisterObject(SOBFigure); |
---|
| 50 | |
---|
| 51 | // initialize variables |
---|
[11383] | 52 | |
---|
[11379] | 53 | moveUpPressed_ = false; |
---|
| 54 | moveDownPressed_ = false; |
---|
| 55 | moveLeftPressed_ = false; |
---|
| 56 | moveDownPressed_ = false; |
---|
| 57 | firePressed_ = false; |
---|
| 58 | timeSinceLastFire_ = 0.0; |
---|
[11383] | 59 | lastSpeed_z = 0.0; |
---|
[11400] | 60 | isColliding_ = true; |
---|
| 61 | particlespawner_ = NULL; |
---|
[11383] | 62 | |
---|
[11400] | 63 | gravityAcceleration_ = 350.0; |
---|
[11392] | 64 | pitch_ = 0.0; |
---|
[11383] | 65 | |
---|
[11379] | 66 | dead_ = false; |
---|
[11381] | 67 | setAngularFactor(0.0); |
---|
[11400] | 68 | this->enableCollisionCallback(); |
---|
[11379] | 69 | } |
---|
| 70 | |
---|
[11400] | 71 | |
---|
| 72 | |
---|
| 73 | bool SOBFigure::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
---|
| 74 | |
---|
| 75 | isColliding_ = true; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | return true; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
[11379] | 83 | void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 84 | { |
---|
| 85 | SUPER(SOBFigure, XMLPort, xmlelement, mode); |
---|
[11383] | 86 | |
---|
[11379] | 87 | } |
---|
| 88 | |
---|
[11400] | 89 | |
---|
| 90 | |
---|
[11379] | 91 | void SOBFigure::tick(float dt) |
---|
| 92 | { |
---|
| 93 | SUPER(SOBFigure, tick, dt); |
---|
| 94 | |
---|
[11400] | 95 | if (particlespawner_ == NULL) { |
---|
| 96 | for (WorldEntity* object : this->getAttachedObjects()) |
---|
| 97 | { |
---|
| 98 | if (object->isA(Class(ParticleSpawner))) |
---|
| 99 | particlespawner_ = object; |
---|
| 100 | |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | if (firePressed_ == false) { |
---|
| 110 | gravityAcceleration_ = 350.0; |
---|
| 111 | |
---|
| 112 | } |
---|
| 113 | |
---|
[11379] | 114 | if (hasLocalController()) |
---|
| 115 | { |
---|
[11383] | 116 | Vector3 velocity = getVelocity(); |
---|
| 117 | Vector3 position = getPosition(); |
---|
[11379] | 118 | |
---|
[11383] | 119 | if (dead_) { |
---|
| 120 | velocity.x = 0; |
---|
| 121 | velocity.z = 0; |
---|
| 122 | setVelocity(velocity); |
---|
| 123 | return; |
---|
| 124 | } |
---|
[11381] | 125 | |
---|
[11379] | 126 | |
---|
[11383] | 127 | int maxvelocity_x = 100; |
---|
| 128 | int speedAddedPerTick = 5; |
---|
| 129 | int camMaxOffset = 25; |
---|
[11379] | 130 | |
---|
[11383] | 131 | timeSinceLastFire_ += dt; |
---|
| 132 | lastSpeed_z = velocity.z; |
---|
[11381] | 133 | |
---|
| 134 | |
---|
| 135 | |
---|
[11400] | 136 | //Handle the rocket fire from the jetpack |
---|
| 137 | if (velocity.z > 40) |
---|
| 138 | particlespawner_->setVisible(true); |
---|
| 139 | else |
---|
| 140 | particlespawner_->setVisible(false); |
---|
| 141 | |
---|
[11383] | 142 | //If player hits space and does not move in z-dir |
---|
[11400] | 143 | if (firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) { |
---|
| 144 | gravityAcceleration_ = 100.0; |
---|
| 145 | velocity.z = 110; //150 |
---|
[11392] | 146 | } |
---|
[11381] | 147 | |
---|
[11392] | 148 | // rotate(1,getOrientation()* WorldEntity::FRONT) |
---|
| 149 | |
---|
[11400] | 150 | |
---|
[11383] | 151 | //Left-right movement with acceleration |
---|
[11400] | 152 | float rot = getOrientation().getRoll().valueDegrees(); |
---|
[11383] | 153 | if (moveRightPressed_) { |
---|
[11400] | 154 | if (rot < 0.0) |
---|
| 155 | setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6)); |
---|
| 156 | |
---|
[11383] | 157 | if (std::abs(velocity.x) < maxvelocity_x) { |
---|
| 158 | velocity.x += speedAddedPerTick; |
---|
[11400] | 159 | |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
[11392] | 164 | // if (pitch_ > 0.0) { |
---|
| 165 | // pitch -= turn_fac*dt); |
---|
| 166 | // } |
---|
[11379] | 167 | } |
---|
[11383] | 168 | } else if (moveLeftPressed_) { |
---|
[11400] | 169 | if (rot >= 0.0) |
---|
| 170 | setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6)); |
---|
| 171 | |
---|
[11383] | 172 | if (std::abs(velocity.x) < maxvelocity_x) { |
---|
| 173 | velocity.x -= speedAddedPerTick; |
---|
[11379] | 174 | } |
---|
[11383] | 175 | } else { |
---|
| 176 | velocity.x /= 1.1; |
---|
[11392] | 177 | } |
---|
[11379] | 178 | |
---|
[11392] | 179 | |
---|
[11383] | 180 | velocity.z -= gravityAcceleration_*dt; |
---|
| 181 | setVelocity(velocity); |
---|
[11379] | 182 | |
---|
| 183 | |
---|
[11383] | 184 | //Camera operation |
---|
| 185 | Camera* cam = getCamera(); |
---|
| 186 | Vector3 campos = cam->getPosition(); |
---|
[11379] | 187 | |
---|
[11383] | 188 | if (campos.x + camMaxOffset < position.x) { |
---|
| 189 | campos.x = position.x - camMaxOffset; |
---|
| 190 | cam->setPosition(campos); |
---|
[11379] | 191 | } |
---|
[11383] | 192 | if (campos.x - camMaxOffset > position.x) { |
---|
| 193 | campos.x = position.x + camMaxOffset; |
---|
| 194 | cam->setPosition(campos); |
---|
| 195 | } |
---|
[11379] | 196 | |
---|
[11383] | 197 | |
---|
| 198 | |
---|
[11392] | 199 | |
---|
[11383] | 200 | } |
---|
| 201 | |
---|
[11379] | 202 | // Move through the left and right screen boundaries |
---|
[11383] | 203 | |
---|
[11379] | 204 | //setPosition(position); |
---|
| 205 | |
---|
| 206 | // Reset key variables |
---|
[11383] | 207 | moveUpPressed_ = false; |
---|
| 208 | moveDownPressed_ = false; |
---|
| 209 | moveLeftPressed_ = false; |
---|
| 210 | moveRightPressed_ = false; |
---|
| 211 | moveDownPressed_ = false; |
---|
[11400] | 212 | isColliding_ = false; |
---|
[11379] | 213 | |
---|
[11383] | 214 | } |
---|
[11379] | 215 | |
---|
| 216 | |
---|
[11383] | 217 | |
---|
| 218 | |
---|
| 219 | |
---|
[11379] | 220 | |
---|
[11383] | 221 | void SOBFigure::moveFrontBack(const Vector2& value) |
---|
| 222 | { |
---|
| 223 | if (value.x > 0) |
---|
[11379] | 224 | { |
---|
[11383] | 225 | moveUpPressed_ = true; |
---|
| 226 | moveDownPressed_ = false; |
---|
[11379] | 227 | } |
---|
[11383] | 228 | else |
---|
| 229 | { |
---|
| 230 | moveUpPressed_ = false; |
---|
| 231 | moveDownPressed_ = true; |
---|
| 232 | } |
---|
| 233 | } |
---|
[11379] | 234 | |
---|
[11383] | 235 | void SOBFigure::moveRightLeft(const Vector2& value) |
---|
| 236 | { |
---|
| 237 | if (value.x > 0) |
---|
[11379] | 238 | { |
---|
[11383] | 239 | moveLeftPressed_ = false; |
---|
| 240 | moveRightPressed_ = true; |
---|
[11379] | 241 | } |
---|
[11383] | 242 | else |
---|
| 243 | { |
---|
| 244 | moveLeftPressed_ = true; |
---|
| 245 | moveRightPressed_ = false; |
---|
| 246 | } |
---|
| 247 | } |
---|
[11379] | 248 | |
---|
| 249 | |
---|
| 250 | |
---|
[11383] | 251 | |
---|
| 252 | |
---|
| 253 | void SOBFigure::boost(bool boost) |
---|
| 254 | { |
---|
[11400] | 255 | firePressed_ = boost; |
---|
[11379] | 256 | } |
---|
[11383] | 257 | } |
---|