[10050] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file JumpFigure.cc |
---|
| 31 | @brief Implementation of the JumpFigure class. |
---|
| 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 | /** |
---|
| 44 | @brief |
---|
| 45 | Constructor. Registers and initializes the object. |
---|
| 46 | */ |
---|
| 47 | JumpFigure::JumpFigure(Context* context) : ControllableEntity(context) |
---|
| 48 | { |
---|
| 49 | RegisterObject(JumpFigure); |
---|
| 50 | |
---|
[10074] | 51 | leftHand_ = NULL; |
---|
| 52 | rightHand_ = NULL; |
---|
[10050] | 53 | |
---|
[10074] | 54 | fieldHeight_ = 0; |
---|
| 55 | fieldWidth_ = 0; |
---|
| 56 | |
---|
| 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 | |
---|
[10050] | 65 | moveUpPressed = false; |
---|
| 66 | moveDownPressed = false; |
---|
| 67 | moveLeftPressed = false; |
---|
| 68 | moveDownPressed = false; |
---|
| 69 | firePressed = false; |
---|
| 70 | fireSignal = false; |
---|
| 71 | timeSinceLastFire = 0.0; |
---|
| 72 | |
---|
| 73 | gravityAcceleration = 8.0; |
---|
| 74 | mouseFactor_ = 75.0; |
---|
| 75 | maxFireRate = 0.3; |
---|
[10074] | 76 | |
---|
| 77 | handAngle_ = 0.0; |
---|
| 78 | animateHands_ = false; |
---|
| 79 | turnUp_ = false; |
---|
| 80 | |
---|
| 81 | rocketActive_ = false; |
---|
| 82 | propellerActive_ = false; |
---|
| 83 | bootsActive_ = false; |
---|
| 84 | shieldActive_ = false; |
---|
| 85 | rocketSpeed_ = 0.0; |
---|
| 86 | propellerSpeed_ = 0.0; |
---|
| 87 | |
---|
| 88 | dead_ = false; |
---|
[10050] | 89 | } |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | @brief |
---|
| 93 | Method to create a JumpCenterpoint through XML. |
---|
| 94 | */ |
---|
| 95 | void JumpFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 96 | { |
---|
| 97 | SUPER(JumpFigure, XMLPort, xmlelement, mode); |
---|
| 98 | XMLPortParam(JumpFigure, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode); |
---|
[10074] | 99 | XMLPortParam(JumpFigure, "modelLefthand", setModelLeftHand, getModelLeftHand, xmlelement, mode); |
---|
| 100 | XMLPortParam(JumpFigure, "modelRighthand", setModelRightHand, getModelRightHand, xmlelement, mode); |
---|
| 101 | XMLPortParam(JumpFigure, "rocketPos", setRocketPos, getRocketPos, xmlelement, mode); |
---|
| 102 | XMLPortParam(JumpFigure, "propellerPos", setPropellerPos, getPropellerPos, xmlelement, mode); |
---|
| 103 | XMLPortParam(JumpFigure, "bootsPos", setBootsPos, getBootsPos, xmlelement, mode); |
---|
| 104 | XMLPortParam(JumpFigure, "jumpSpeed", setJumpSpeed, getJumpSpeed, xmlelement, mode); |
---|
| 105 | XMLPortParam(JumpFigure, "rocketSpeed", setRocketSpeed, getRocketSpeed, xmlelement, mode); |
---|
| 106 | XMLPortParam(JumpFigure, "propellerSpeed", setPropellerSpeed, getPropellerSpeed, xmlelement, mode); |
---|
| 107 | XMLPortParam(JumpFigure, "handMinAngle", setHandMinAngle, getHandMinAngle, xmlelement, mode); |
---|
| 108 | XMLPortParam(JumpFigure, "handMaxAngle", setHandMaxAngle, getHandMaxAngle, xmlelement, mode); |
---|
| 109 | XMLPortParam(JumpFigure, "handSpeed", setHandSpeed, getHandSpeed, xmlelement, mode); |
---|
[10050] | 110 | } |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | @brief |
---|
| 114 | Is called each tick. |
---|
| 115 | Moves the bat. |
---|
| 116 | @param dt |
---|
| 117 | The time since last tick. |
---|
| 118 | */ |
---|
| 119 | void JumpFigure::tick(float dt) |
---|
| 120 | { |
---|
| 121 | SUPER(JumpFigure, tick, dt); |
---|
| 122 | |
---|
| 123 | // If the bat is controlled (but not over the network). |
---|
[10074] | 124 | if (hasLocalController()) |
---|
[10050] | 125 | { |
---|
| 126 | timeSinceLastFire += dt; |
---|
| 127 | |
---|
[10074] | 128 | // Move up/down |
---|
| 129 | Vector3 velocity = getVelocity(); |
---|
| 130 | if (rocketActive_ == true) |
---|
| 131 | { |
---|
| 132 | velocity.z = rocketSpeed_; |
---|
| 133 | } |
---|
| 134 | else if (propellerActive_ == true) |
---|
| 135 | { |
---|
| 136 | velocity.z = propellerSpeed_; |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { |
---|
| 140 | velocity.z -= gravityAcceleration; |
---|
| 141 | } |
---|
[10050] | 142 | |
---|
[10074] | 143 | // Animate Hands |
---|
| 144 | if (animateHands_ == true) |
---|
| 145 | { |
---|
| 146 | if (turnUp_ == true) |
---|
| 147 | { |
---|
| 148 | handAngle_ += handSpeed_ * dt; |
---|
| 149 | } |
---|
| 150 | else |
---|
| 151 | { |
---|
| 152 | handAngle_ -= handSpeed_ * dt; |
---|
| 153 | } |
---|
| 154 | if (handAngle_ > handMaxAngle_) |
---|
| 155 | { |
---|
| 156 | turnUp_ = false; |
---|
| 157 | } |
---|
| 158 | if (handAngle_ <= handMinAngle_) |
---|
| 159 | { |
---|
| 160 | animateHands_ = false; |
---|
| 161 | } |
---|
[10050] | 162 | |
---|
[10074] | 163 | if (leftHand_ != NULL) |
---|
| 164 | { |
---|
| 165 | leftHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(-handAngle_)); |
---|
| 166 | } |
---|
| 167 | if (rightHand_ != NULL) |
---|
| 168 | { |
---|
| 169 | rightHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(handAngle_)); |
---|
| 170 | } |
---|
| 171 | } |
---|
[10050] | 172 | |
---|
[10074] | 173 | // Move left/right |
---|
| 174 | if (dead_ == false) |
---|
[10050] | 175 | { |
---|
[10074] | 176 | velocity.x = -mouseFactor_*horizontalSpeed; |
---|
[10050] | 177 | } |
---|
[10074] | 178 | else |
---|
[10050] | 179 | { |
---|
[10074] | 180 | velocity.x = 0.0; |
---|
| 181 | } |
---|
[10050] | 182 | |
---|
[10074] | 183 | // Cheats |
---|
[10050] | 184 | if (moveUpPressed == true) |
---|
| 185 | { |
---|
| 186 | velocity.z = 200.0f; |
---|
| 187 | moveUpPressed = false; |
---|
[10074] | 188 | dead_ = false; |
---|
[10050] | 189 | } |
---|
| 190 | if (moveDownPressed == true) |
---|
| 191 | { |
---|
| 192 | moveDownPressed = false; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | setVelocity(velocity); |
---|
| 196 | |
---|
[10074] | 197 | |
---|
[10050] | 198 | if (firePressed && timeSinceLastFire >= maxFireRate) |
---|
| 199 | { |
---|
| 200 | firePressed = false; |
---|
| 201 | timeSinceLastFire = 0.0; |
---|
| 202 | fireSignal = true; |
---|
| 203 | //orxout() << "fired signal set" << endl; |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
[10074] | 207 | // Move through the left and right screen boundaries |
---|
| 208 | Vector3 position = getPosition(); |
---|
[10050] | 209 | if (position.x < -fieldWidth_*1.1) |
---|
| 210 | { |
---|
| 211 | position.x = fieldWidth_*1.1; |
---|
| 212 | } |
---|
| 213 | else if (position.x > fieldWidth_*1.1) |
---|
| 214 | { |
---|
| 215 | position.x = -fieldWidth_*1.1; |
---|
| 216 | } |
---|
[10074] | 217 | setPosition(position); |
---|
[10050] | 218 | |
---|
[10074] | 219 | // Reset key variables |
---|
[10050] | 220 | moveUpPressed = false; |
---|
| 221 | moveDownPressed = false; |
---|
| 222 | moveLeftPressed = false; |
---|
| 223 | moveDownPressed = false; |
---|
| 224 | firePressed = false; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | void JumpFigure::JumpFromPlatform(JumpPlatform* platform) |
---|
| 228 | { |
---|
[10074] | 229 | if (dead_ == false) |
---|
| 230 | { |
---|
| 231 | Vector3 velocity = getVelocity(); |
---|
| 232 | velocity.z = (bootsActive_ ? 1.2*jumpSpeed_ : jumpSpeed_); |
---|
| 233 | setVelocity(velocity); |
---|
| 234 | |
---|
| 235 | animateHands_ = true; |
---|
| 236 | handAngle_ = 0.0; |
---|
| 237 | turnUp_ = true; |
---|
| 238 | } |
---|
[10050] | 239 | } |
---|
| 240 | |
---|
[10074] | 241 | void JumpFigure::JumpFromSpring(JumpSpring* spring) |
---|
| 242 | { |
---|
| 243 | if (dead_ == false) |
---|
| 244 | { |
---|
| 245 | Vector3 velocity = getVelocity(); |
---|
| 246 | velocity.z = 1.2*jumpSpeed_; |
---|
| 247 | setVelocity(velocity); |
---|
| 248 | } |
---|
| 249 | } |
---|
[10050] | 250 | |
---|
[10074] | 251 | void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy) |
---|
| 252 | { |
---|
| 253 | if (rocketActive_ == false && propellerActive_ == false && shieldActive_ == false) |
---|
| 254 | { |
---|
| 255 | dead_ = true; |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | bool JumpFigure::StartRocket(JumpRocket* rocket) |
---|
| 260 | { |
---|
| 261 | if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) |
---|
| 262 | { |
---|
| 263 | attach(rocket); |
---|
| 264 | rocket->setPosition(0.0, rocketPos_, 0.0); |
---|
| 265 | rocket->setVelocity(0.0, 0.0, 0.0); |
---|
| 266 | rocketActive_ = true; |
---|
| 267 | |
---|
| 268 | return true; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | return false; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | void JumpFigure::StopRocket(JumpRocket* rocket) |
---|
| 275 | { |
---|
| 276 | rocket->setPosition(0.0, 0.0, -1000.0); |
---|
| 277 | rocket->setVelocity(0.0, 0.0, 0.0); |
---|
| 278 | detach(rocket); |
---|
| 279 | rocket->destroy(); |
---|
| 280 | rocketActive_ = false; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | bool JumpFigure::StartPropeller(JumpPropeller* propeller) |
---|
| 284 | { |
---|
| 285 | if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) |
---|
| 286 | { |
---|
| 287 | attach(propeller); |
---|
| 288 | propeller->setPosition(0.0, 0.0, propellerPos_); |
---|
| 289 | propeller->setVelocity(0.0, 0.0, 0.0); |
---|
| 290 | propellerActive_ = true; |
---|
| 291 | |
---|
| 292 | return true; |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | return false; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | void JumpFigure::StopPropeller(JumpPropeller* propeller) |
---|
| 299 | { |
---|
| 300 | propeller->setPosition(0.0, 0.0, -1000.0); |
---|
| 301 | propeller->setVelocity(0.0, 0.0, 0.0); |
---|
| 302 | detach(propeller); |
---|
| 303 | propeller->destroy(); |
---|
| 304 | propellerActive_ = false; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | bool JumpFigure::StartBoots(JumpBoots* boots) |
---|
| 308 | { |
---|
| 309 | if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) |
---|
| 310 | { |
---|
| 311 | attach(boots); |
---|
| 312 | boots->setPosition(0.0, 0.0, bootsPos_); |
---|
| 313 | boots->setVelocity(0.0, 0.0, 0.0); |
---|
| 314 | bootsActive_ = true; |
---|
| 315 | |
---|
| 316 | return true; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | return false; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | void JumpFigure::StopBoots(JumpBoots* boots) |
---|
| 323 | { |
---|
| 324 | boots->setPosition(0.0, 0.0, -1000.0); |
---|
| 325 | boots->setVelocity(0.0, 0.0, 0.0); |
---|
| 326 | detach(boots); |
---|
| 327 | boots->destroy(); |
---|
| 328 | bootsActive_ = false; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | bool JumpFigure::StartShield(JumpShield* shield) |
---|
| 332 | { |
---|
| 333 | if (shieldActive_ == false) |
---|
| 334 | { |
---|
| 335 | attach(shield); |
---|
| 336 | shield->setPosition(0.0, 0.0, propellerPos_); |
---|
| 337 | shield->setVelocity(0.0, 0.0, 0.0); |
---|
| 338 | shieldActive_ = true; |
---|
| 339 | |
---|
| 340 | return true; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | return false; |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | void JumpFigure::StopShield(JumpShield* shield) |
---|
| 347 | { |
---|
| 348 | shield->setPosition(0.0, 0.0, -1000.0); |
---|
| 349 | shield->setVelocity(0.0, 0.0, 0.0); |
---|
| 350 | detach(shield); |
---|
| 351 | shield->destroy(); |
---|
| 352 | shieldActive_ = false; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | void JumpFigure::InitializeAnimation(Context* context) |
---|
| 356 | { |
---|
| 357 | leftHand_ = new Model(context); |
---|
| 358 | rightHand_ = new Model(context); |
---|
| 359 | |
---|
| 360 | leftHand_->addTemplate(modelLeftHand_); |
---|
| 361 | rightHand_->addTemplate(modelRightHand_); |
---|
| 362 | |
---|
| 363 | attach(leftHand_); |
---|
| 364 | attach(rightHand_); |
---|
| 365 | } |
---|
| 366 | |
---|
[10050] | 367 | /** |
---|
[10074] | 368 | @briefhandPosition_ |
---|
[10050] | 369 | Overloaded the function to steer the bat up and down. |
---|
| 370 | @param value |
---|
| 371 | A vector whose first component is the inverse direction in which we want to steer the bat. |
---|
| 372 | */ |
---|
| 373 | void JumpFigure::moveFrontBack(const Vector2& value) |
---|
| 374 | { |
---|
| 375 | if (value.x > 0) |
---|
| 376 | { |
---|
| 377 | //orxout() << "up pressed" << endl; |
---|
| 378 | moveUpPressed = true; |
---|
| 379 | moveDownPressed = false; |
---|
| 380 | } |
---|
| 381 | else |
---|
| 382 | { |
---|
| 383 | //orxout() << "down pressed" << endl; |
---|
| 384 | moveUpPressed = false; |
---|
| 385 | moveDownPressed = true; |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | /** |
---|
| 390 | @brief |
---|
| 391 | Overloaded the function to steer the bat up and down. |
---|
| 392 | @param value |
---|
| 393 | A vector whose first component is the direction in which we wnat to steer the bat. |
---|
| 394 | */ |
---|
| 395 | void JumpFigure::moveRightLeft(const Vector2& value) |
---|
| 396 | { |
---|
| 397 | if (value.x > 0) |
---|
| 398 | { |
---|
| 399 | moveLeftPressed = false; |
---|
| 400 | moveRightPressed = true; |
---|
| 401 | } |
---|
| 402 | else |
---|
| 403 | { |
---|
| 404 | moveLeftPressed = true; |
---|
| 405 | moveRightPressed = false; |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | void JumpFigure::rotateYaw(const Vector2& value) |
---|
| 410 | { |
---|
| 411 | horizontalSpeed = value.x; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | void JumpFigure::rotatePitch(const Vector2& value) |
---|
| 415 | { |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | void JumpFigure::rotateRoll(const Vector2& value) |
---|
| 421 | { |
---|
| 422 | |
---|
| 423 | |
---|
| 424 | } |
---|
| 425 | |
---|
[10074] | 426 | void JumpFigure::fire(unsigned int firemode) |
---|
| 427 | { |
---|
| 428 | //SUPER(JumpFigure, fire, firemode); |
---|
| 429 | } |
---|
| 430 | |
---|
[10050] | 431 | void JumpFigure::fired(unsigned int firemode) |
---|
| 432 | { |
---|
[10074] | 433 | //SUPER(JumpFigure, fired, firemode); |
---|
[10050] | 434 | firePressed = true; |
---|
| 435 | } |
---|
| 436 | } |
---|