[10078] | 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 JumpFigure.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 "JumpFigure.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
| 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | RegisterClass(JumpFigure); |
---|
| 42 | |
---|
| 43 | JumpFigure::JumpFigure(Context* context) : ControllableEntity(context) |
---|
| 44 | { |
---|
| 45 | RegisterObject(JumpFigure); |
---|
| 46 | |
---|
[10215] | 47 | // initialize variables |
---|
[10078] | 48 | leftHand_ = NULL; |
---|
| 49 | rightHand_ = NULL; |
---|
| 50 | fieldHeight_ = 0; |
---|
| 51 | fieldWidth_ = 0; |
---|
| 52 | jumpSpeed_ = 0.0; |
---|
| 53 | handSpeed_ = 0.0; |
---|
| 54 | handMaxAngle_ = 0.0; |
---|
| 55 | handMinAngle_ = 0.0; |
---|
| 56 | rocketPos_ = 0.0; |
---|
| 57 | propellerPos_ = 0.0; |
---|
| 58 | bootsPos_ = 0.0; |
---|
| 59 | moveUpPressed_ = false; |
---|
| 60 | moveDownPressed_ = false; |
---|
| 61 | moveLeftPressed_ = false; |
---|
| 62 | moveDownPressed_ = false; |
---|
| 63 | firePressed_ = false; |
---|
| 64 | fireSignal_ = false; |
---|
| 65 | timeSinceLastFire_ = 0.0; |
---|
| 66 | gravityAcceleration_ = 8.0; |
---|
| 67 | mouseFactor_ = 75.0; |
---|
| 68 | maxFireRate_ = 0.3; |
---|
| 69 | handAngle_ = 0.0; |
---|
| 70 | animateHands_ = false; |
---|
| 71 | turnUp_ = false; |
---|
[10260] | 72 | rocketActive_ = NULL; |
---|
| 73 | propellerActive_ = NULL; |
---|
| 74 | bootsActive_ = NULL; |
---|
| 75 | shieldActive_ = NULL; |
---|
[10078] | 76 | rocketSpeed_ = 0.0; |
---|
| 77 | propellerSpeed_ = 0.0; |
---|
| 78 | dead_ = false; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void JumpFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 82 | { |
---|
| 83 | SUPER(JumpFigure, XMLPort, xmlelement, mode); |
---|
| 84 | XMLPortParam(JumpFigure, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode); |
---|
| 85 | XMLPortParam(JumpFigure, "modelLefthand", setModelLeftHand, getModelLeftHand, xmlelement, mode); |
---|
| 86 | XMLPortParam(JumpFigure, "modelRighthand", setModelRightHand, getModelRightHand, xmlelement, mode); |
---|
| 87 | XMLPortParam(JumpFigure, "rocketPos", setRocketPos, getRocketPos, xmlelement, mode); |
---|
| 88 | XMLPortParam(JumpFigure, "propellerPos", setPropellerPos, getPropellerPos, xmlelement, mode); |
---|
| 89 | XMLPortParam(JumpFigure, "bootsPos", setBootsPos, getBootsPos, xmlelement, mode); |
---|
| 90 | XMLPortParam(JumpFigure, "jumpSpeed", setJumpSpeed, getJumpSpeed, xmlelement, mode); |
---|
| 91 | XMLPortParam(JumpFigure, "rocketSpeed", setRocketSpeed, getRocketSpeed, xmlelement, mode); |
---|
| 92 | XMLPortParam(JumpFigure, "propellerSpeed", setPropellerSpeed, getPropellerSpeed, xmlelement, mode); |
---|
| 93 | XMLPortParam(JumpFigure, "handMinAngle", setHandMinAngle, getHandMinAngle, xmlelement, mode); |
---|
| 94 | XMLPortParam(JumpFigure, "handMaxAngle", setHandMaxAngle, getHandMaxAngle, xmlelement, mode); |
---|
| 95 | XMLPortParam(JumpFigure, "handSpeed", setHandSpeed, getHandSpeed, xmlelement, mode); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void JumpFigure::tick(float dt) |
---|
| 99 | { |
---|
[10215] | 100 | SUPER(JumpFigure, tick, dt); |
---|
[10078] | 101 | |
---|
| 102 | if (hasLocalController()) |
---|
| 103 | { |
---|
[10215] | 104 | timeSinceLastFire_ += dt; |
---|
[10078] | 105 | |
---|
[10215] | 106 | // Move up/down |
---|
| 107 | Vector3 velocity = getVelocity(); |
---|
[10260] | 108 | if (rocketActive_ != NULL) |
---|
[10215] | 109 | { |
---|
| 110 | velocity.z = rocketSpeed_; |
---|
| 111 | } |
---|
[10260] | 112 | else if (propellerActive_ != NULL) |
---|
[10215] | 113 | { |
---|
| 114 | velocity.z = propellerSpeed_; |
---|
| 115 | } |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | velocity.z -= gravityAcceleration_; |
---|
| 119 | } |
---|
[10078] | 120 | |
---|
[10215] | 121 | // Animate Hands |
---|
| 122 | if (animateHands_ == true) |
---|
| 123 | { |
---|
| 124 | if (turnUp_ == true) |
---|
| 125 | { |
---|
| 126 | handAngle_ += handSpeed_ * dt; |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | handAngle_ -= handSpeed_ * dt; |
---|
| 131 | } |
---|
| 132 | if (handAngle_ > handMaxAngle_) |
---|
| 133 | { |
---|
| 134 | turnUp_ = false; |
---|
| 135 | } |
---|
| 136 | if (handAngle_ <= handMinAngle_) |
---|
| 137 | { |
---|
| 138 | animateHands_ = false; |
---|
| 139 | } |
---|
[10078] | 140 | |
---|
[10215] | 141 | if (leftHand_ != NULL) |
---|
| 142 | { |
---|
| 143 | leftHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(-handAngle_)); |
---|
| 144 | } |
---|
| 145 | if (rightHand_ != NULL) |
---|
| 146 | { |
---|
| 147 | rightHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(handAngle_)); |
---|
| 148 | } |
---|
| 149 | } |
---|
[10078] | 150 | |
---|
[10215] | 151 | // Move left/right |
---|
| 152 | if (dead_ == false) |
---|
| 153 | { |
---|
| 154 | velocity.x = -mouseFactor_*horizontalSpeed_; |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | velocity.x = 0.0; |
---|
| 159 | } |
---|
[10078] | 160 | |
---|
[10215] | 161 | // Cheats |
---|
| 162 | /*if (moveUpPressed_ == true) |
---|
| 163 | { |
---|
| 164 | velocity.z = 400.0f; |
---|
| 165 | moveUpPressed_ = false; |
---|
| 166 | dead_ = false; |
---|
| 167 | } |
---|
| 168 | if (moveDownPressed_ == true) |
---|
| 169 | { |
---|
| 170 | moveDownPressed_ = false; |
---|
| 171 | }*/ |
---|
[10078] | 172 | |
---|
[10215] | 173 | setVelocity(velocity); |
---|
[10078] | 174 | |
---|
| 175 | |
---|
[10215] | 176 | if (firePressed_ && timeSinceLastFire_ >= maxFireRate_) |
---|
| 177 | { |
---|
| 178 | firePressed_ = false; |
---|
| 179 | timeSinceLastFire_ = 0.0; |
---|
| 180 | fireSignal_ = true; |
---|
| 181 | } |
---|
[10078] | 182 | } |
---|
| 183 | |
---|
| 184 | // Move through the left and right screen boundaries |
---|
| 185 | Vector3 position = getPosition(); |
---|
[10218] | 186 | if (position.x < -fieldWidth_*1.1f) |
---|
[10078] | 187 | { |
---|
[10218] | 188 | position.x = fieldWidth_*1.1f; |
---|
[10078] | 189 | } |
---|
[10218] | 190 | else if (position.x > fieldWidth_*1.1f) |
---|
[10078] | 191 | { |
---|
[10218] | 192 | position.x = -fieldWidth_*1.1f; |
---|
[10078] | 193 | } |
---|
| 194 | setPosition(position); |
---|
| 195 | |
---|
| 196 | // Reset key variables |
---|
| 197 | moveUpPressed_ = false; |
---|
| 198 | moveDownPressed_ = false; |
---|
| 199 | moveLeftPressed_ = false; |
---|
| 200 | moveDownPressed_ = false; |
---|
| 201 | firePressed_ = false; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | void JumpFigure::JumpFromPlatform(JumpPlatform* platform) |
---|
| 205 | { |
---|
[10215] | 206 | if (dead_ == false) |
---|
| 207 | { |
---|
| 208 | Vector3 velocity = getVelocity(); |
---|
[10260] | 209 | if (bootsActive_ == NULL) |
---|
| 210 | { |
---|
| 211 | velocity.z = 1.2f*jumpSpeed_; |
---|
| 212 | } |
---|
| 213 | else |
---|
| 214 | { |
---|
| 215 | velocity.z = jumpSpeed_; |
---|
| 216 | } |
---|
[10215] | 217 | setVelocity(velocity); |
---|
| 218 | animateHands_ = true; |
---|
| 219 | handAngle_ = 0.0; |
---|
| 220 | turnUp_ = true; |
---|
| 221 | } |
---|
[10078] | 222 | } |
---|
| 223 | |
---|
| 224 | void JumpFigure::JumpFromSpring(JumpSpring* spring) |
---|
| 225 | { |
---|
[10215] | 226 | if (dead_ == false) |
---|
| 227 | { |
---|
| 228 | Vector3 velocity = getVelocity(); |
---|
[10218] | 229 | velocity.z = 1.2f*jumpSpeed_; |
---|
[10215] | 230 | setVelocity(velocity); |
---|
| 231 | } |
---|
[10078] | 232 | } |
---|
| 233 | |
---|
| 234 | void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy) |
---|
[10215] | 235 | { |
---|
[10260] | 236 | if (rocketActive_ == NULL && propellerActive_ == NULL && shieldActive_ == NULL) |
---|
[10215] | 237 | { |
---|
| 238 | dead_ = true; |
---|
| 239 | } |
---|
| 240 | } |
---|
[10078] | 241 | |
---|
| 242 | bool JumpFigure::StartRocket(JumpRocket* rocket) |
---|
| 243 | { |
---|
[10260] | 244 | if (rocketActive_ == NULL && propellerActive_ == NULL && bootsActive_ == NULL) |
---|
[10215] | 245 | { |
---|
| 246 | attach(rocket); |
---|
| 247 | rocket->setPosition(0.0, rocketPos_, 0.0); |
---|
| 248 | rocket->setVelocity(0.0, 0.0, 0.0); |
---|
[10260] | 249 | rocketActive_ = rocket; |
---|
[10078] | 250 | |
---|
[10215] | 251 | return true; |
---|
| 252 | } |
---|
[10078] | 253 | |
---|
[10215] | 254 | return false; |
---|
[10078] | 255 | } |
---|
| 256 | |
---|
| 257 | void JumpFigure::StopRocket(JumpRocket* rocket) |
---|
| 258 | { |
---|
[10215] | 259 | rocket->setPosition(0.0, 0.0, -1000.0); |
---|
| 260 | rocket->setVelocity(0.0, 0.0, 0.0); |
---|
| 261 | detach(rocket); |
---|
| 262 | rocket->destroy(); |
---|
[10260] | 263 | rocketActive_ = NULL; |
---|
[10078] | 264 | } |
---|
| 265 | |
---|
| 266 | bool JumpFigure::StartPropeller(JumpPropeller* propeller) |
---|
| 267 | { |
---|
[10260] | 268 | if (rocketActive_ == NULL && propellerActive_ == NULL && bootsActive_ == NULL) |
---|
[10215] | 269 | { |
---|
| 270 | attach(propeller); |
---|
| 271 | propeller->setPosition(0.0, 0.0, propellerPos_); |
---|
| 272 | propeller->setVelocity(0.0, 0.0, 0.0); |
---|
[10260] | 273 | propellerActive_ = propeller; |
---|
[10078] | 274 | |
---|
[10215] | 275 | return true; |
---|
| 276 | } |
---|
[10078] | 277 | |
---|
[10215] | 278 | return false; |
---|
[10078] | 279 | } |
---|
| 280 | |
---|
| 281 | void JumpFigure::StopPropeller(JumpPropeller* propeller) |
---|
| 282 | { |
---|
[10215] | 283 | propeller->setPosition(0.0, 0.0, -1000.0); |
---|
| 284 | propeller->setVelocity(0.0, 0.0, 0.0); |
---|
| 285 | detach(propeller); |
---|
| 286 | propeller->destroy(); |
---|
[10260] | 287 | propellerActive_ = NULL; |
---|
[10078] | 288 | } |
---|
| 289 | |
---|
| 290 | bool JumpFigure::StartBoots(JumpBoots* boots) |
---|
| 291 | { |
---|
[10260] | 292 | if (rocketActive_ == NULL && propellerActive_ == NULL && bootsActive_ == NULL) |
---|
[10215] | 293 | { |
---|
| 294 | attach(boots); |
---|
| 295 | boots->setPosition(0.0, 0.0, bootsPos_); |
---|
| 296 | boots->setVelocity(0.0, 0.0, 0.0); |
---|
[10260] | 297 | bootsActive_ = boots; |
---|
[10078] | 298 | |
---|
[10215] | 299 | return true; |
---|
| 300 | } |
---|
[10078] | 301 | |
---|
[10215] | 302 | return false; |
---|
[10078] | 303 | } |
---|
| 304 | |
---|
| 305 | void JumpFigure::StopBoots(JumpBoots* boots) |
---|
| 306 | { |
---|
[10215] | 307 | boots->setPosition(0.0, 0.0, -1000.0); |
---|
| 308 | boots->setVelocity(0.0, 0.0, 0.0); |
---|
| 309 | detach(boots); |
---|
| 310 | boots->destroy(); |
---|
[10260] | 311 | bootsActive_ = NULL; |
---|
[10078] | 312 | } |
---|
| 313 | |
---|
| 314 | bool JumpFigure::StartShield(JumpShield* shield) |
---|
| 315 | { |
---|
[10215] | 316 | if (shieldActive_ == false) |
---|
| 317 | { |
---|
| 318 | attach(shield); |
---|
| 319 | shield->setPosition(0.0, 0.0, propellerPos_); |
---|
| 320 | shield->setVelocity(0.0, 0.0, 0.0); |
---|
[10260] | 321 | shieldActive_ = shield; |
---|
[10078] | 322 | |
---|
[10215] | 323 | return true; |
---|
| 324 | } |
---|
[10078] | 325 | |
---|
[10215] | 326 | return false; |
---|
[10078] | 327 | } |
---|
| 328 | |
---|
| 329 | void JumpFigure::StopShield(JumpShield* shield) |
---|
| 330 | { |
---|
[10215] | 331 | shield->setPosition(0.0, 0.0, -1000.0); |
---|
| 332 | shield->setVelocity(0.0, 0.0, 0.0); |
---|
| 333 | detach(shield); |
---|
| 334 | shield->destroy(); |
---|
[10260] | 335 | shieldActive_ = NULL; |
---|
[10078] | 336 | } |
---|
| 337 | |
---|
| 338 | void JumpFigure::InitializeAnimation(Context* context) |
---|
| 339 | { |
---|
[10215] | 340 | leftHand_ = new Model(context); |
---|
| 341 | rightHand_ = new Model(context); |
---|
[10078] | 342 | |
---|
[10215] | 343 | leftHand_->addTemplate(modelLeftHand_); |
---|
| 344 | rightHand_->addTemplate(modelRightHand_); |
---|
[10078] | 345 | |
---|
[10215] | 346 | attach(leftHand_); |
---|
| 347 | attach(rightHand_); |
---|
[10078] | 348 | } |
---|
| 349 | |
---|
| 350 | void JumpFigure::moveFrontBack(const Vector2& value) |
---|
| 351 | { |
---|
[10215] | 352 | if (value.x > 0) |
---|
| 353 | { |
---|
| 354 | moveUpPressed_ = true; |
---|
| 355 | moveDownPressed_ = false; |
---|
| 356 | } |
---|
| 357 | else |
---|
| 358 | { |
---|
| 359 | moveUpPressed_ = false; |
---|
| 360 | moveDownPressed_ = true; |
---|
| 361 | } |
---|
[10078] | 362 | } |
---|
| 363 | |
---|
| 364 | void JumpFigure::moveRightLeft(const Vector2& value) |
---|
| 365 | { |
---|
[10215] | 366 | if (value.x > 0) |
---|
| 367 | { |
---|
| 368 | moveLeftPressed_ = false; |
---|
| 369 | moveRightPressed_ = true; |
---|
| 370 | } |
---|
| 371 | else |
---|
| 372 | { |
---|
| 373 | moveLeftPressed_ = true; |
---|
| 374 | moveRightPressed_ = false; |
---|
| 375 | } |
---|
[10078] | 376 | } |
---|
| 377 | |
---|
| 378 | void JumpFigure::rotateYaw(const Vector2& value) |
---|
| 379 | { |
---|
[10215] | 380 | horizontalSpeed_ = value.x; |
---|
[10078] | 381 | } |
---|
| 382 | |
---|
| 383 | void JumpFigure::rotatePitch(const Vector2& value) |
---|
| 384 | { |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | void JumpFigure::rotateRoll(const Vector2& value) |
---|
| 390 | { |
---|
| 391 | |
---|
| 392 | |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | void JumpFigure::fire(unsigned int firemode) |
---|
| 396 | { |
---|
| 397 | |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | void JumpFigure::fired(unsigned int firemode) |
---|
| 401 | { |
---|
[10215] | 402 | firePressed_ = true; |
---|
[10078] | 403 | } |
---|
| 404 | } |
---|