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