[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; |
---|
| 72 | rocketActive_ = false; |
---|
| 73 | propellerActive_ = false; |
---|
| 74 | bootsActive_ = false; |
---|
| 75 | shieldActive_ = false; |
---|
| 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(); |
---|
| 108 | if (rocketActive_ == true) |
---|
| 109 | { |
---|
| 110 | velocity.z = rocketSpeed_; |
---|
| 111 | } |
---|
| 112 | else if (propellerActive_ == true) |
---|
| 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(); |
---|
[10218] | 209 | velocity.z = (bootsActive_ ? 1.2f*jumpSpeed_ : jumpSpeed_); |
---|
[10215] | 210 | setVelocity(velocity); |
---|
[10078] | 211 | |
---|
[10215] | 212 | animateHands_ = true; |
---|
| 213 | handAngle_ = 0.0; |
---|
| 214 | turnUp_ = true; |
---|
| 215 | } |
---|
[10078] | 216 | } |
---|
| 217 | |
---|
| 218 | void JumpFigure::JumpFromSpring(JumpSpring* spring) |
---|
| 219 | { |
---|
[10215] | 220 | if (dead_ == false) |
---|
| 221 | { |
---|
| 222 | Vector3 velocity = getVelocity(); |
---|
[10218] | 223 | velocity.z = 1.2f*jumpSpeed_; |
---|
[10215] | 224 | setVelocity(velocity); |
---|
| 225 | } |
---|
[10078] | 226 | } |
---|
| 227 | |
---|
| 228 | void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy) |
---|
[10215] | 229 | { |
---|
| 230 | if (rocketActive_ == false && propellerActive_ == false && shieldActive_ == false) |
---|
| 231 | { |
---|
| 232 | dead_ = true; |
---|
| 233 | } |
---|
| 234 | } |
---|
[10078] | 235 | |
---|
| 236 | bool JumpFigure::StartRocket(JumpRocket* rocket) |
---|
| 237 | { |
---|
[10215] | 238 | if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) |
---|
| 239 | { |
---|
| 240 | attach(rocket); |
---|
| 241 | rocket->setPosition(0.0, rocketPos_, 0.0); |
---|
| 242 | rocket->setVelocity(0.0, 0.0, 0.0); |
---|
| 243 | rocketActive_ = true; |
---|
[10078] | 244 | |
---|
[10215] | 245 | return true; |
---|
| 246 | } |
---|
[10078] | 247 | |
---|
[10215] | 248 | return false; |
---|
[10078] | 249 | } |
---|
| 250 | |
---|
| 251 | void JumpFigure::StopRocket(JumpRocket* rocket) |
---|
| 252 | { |
---|
[10215] | 253 | rocket->setPosition(0.0, 0.0, -1000.0); |
---|
| 254 | rocket->setVelocity(0.0, 0.0, 0.0); |
---|
| 255 | detach(rocket); |
---|
| 256 | rocket->destroy(); |
---|
| 257 | rocketActive_ = false; |
---|
[10078] | 258 | } |
---|
| 259 | |
---|
| 260 | bool JumpFigure::StartPropeller(JumpPropeller* propeller) |
---|
| 261 | { |
---|
[10215] | 262 | if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) |
---|
| 263 | { |
---|
| 264 | attach(propeller); |
---|
| 265 | propeller->setPosition(0.0, 0.0, propellerPos_); |
---|
| 266 | propeller->setVelocity(0.0, 0.0, 0.0); |
---|
| 267 | propellerActive_ = true; |
---|
[10078] | 268 | |
---|
[10215] | 269 | return true; |
---|
| 270 | } |
---|
[10078] | 271 | |
---|
[10215] | 272 | return false; |
---|
[10078] | 273 | } |
---|
| 274 | |
---|
| 275 | void JumpFigure::StopPropeller(JumpPropeller* propeller) |
---|
| 276 | { |
---|
[10215] | 277 | propeller->setPosition(0.0, 0.0, -1000.0); |
---|
| 278 | propeller->setVelocity(0.0, 0.0, 0.0); |
---|
| 279 | detach(propeller); |
---|
| 280 | propeller->destroy(); |
---|
| 281 | propellerActive_ = false; |
---|
[10078] | 282 | } |
---|
| 283 | |
---|
| 284 | bool JumpFigure::StartBoots(JumpBoots* boots) |
---|
| 285 | { |
---|
[10215] | 286 | if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) |
---|
| 287 | { |
---|
| 288 | attach(boots); |
---|
| 289 | boots->setPosition(0.0, 0.0, bootsPos_); |
---|
| 290 | boots->setVelocity(0.0, 0.0, 0.0); |
---|
| 291 | bootsActive_ = true; |
---|
[10078] | 292 | |
---|
[10215] | 293 | return true; |
---|
| 294 | } |
---|
[10078] | 295 | |
---|
[10215] | 296 | return false; |
---|
[10078] | 297 | } |
---|
| 298 | |
---|
| 299 | void JumpFigure::StopBoots(JumpBoots* boots) |
---|
| 300 | { |
---|
[10215] | 301 | boots->setPosition(0.0, 0.0, -1000.0); |
---|
| 302 | boots->setVelocity(0.0, 0.0, 0.0); |
---|
| 303 | detach(boots); |
---|
| 304 | boots->destroy(); |
---|
| 305 | bootsActive_ = false; |
---|
[10078] | 306 | } |
---|
| 307 | |
---|
| 308 | bool JumpFigure::StartShield(JumpShield* shield) |
---|
| 309 | { |
---|
[10215] | 310 | if (shieldActive_ == false) |
---|
| 311 | { |
---|
| 312 | attach(shield); |
---|
| 313 | shield->setPosition(0.0, 0.0, propellerPos_); |
---|
| 314 | shield->setVelocity(0.0, 0.0, 0.0); |
---|
| 315 | shieldActive_ = true; |
---|
[10078] | 316 | |
---|
[10215] | 317 | return true; |
---|
| 318 | } |
---|
[10078] | 319 | |
---|
[10215] | 320 | return false; |
---|
[10078] | 321 | } |
---|
| 322 | |
---|
| 323 | void JumpFigure::StopShield(JumpShield* shield) |
---|
| 324 | { |
---|
[10215] | 325 | shield->setPosition(0.0, 0.0, -1000.0); |
---|
| 326 | shield->setVelocity(0.0, 0.0, 0.0); |
---|
| 327 | detach(shield); |
---|
| 328 | shield->destroy(); |
---|
| 329 | shieldActive_ = false; |
---|
[10078] | 330 | } |
---|
| 331 | |
---|
| 332 | void JumpFigure::InitializeAnimation(Context* context) |
---|
| 333 | { |
---|
[10215] | 334 | leftHand_ = new Model(context); |
---|
| 335 | rightHand_ = new Model(context); |
---|
[10078] | 336 | |
---|
[10215] | 337 | leftHand_->addTemplate(modelLeftHand_); |
---|
| 338 | rightHand_->addTemplate(modelRightHand_); |
---|
[10078] | 339 | |
---|
[10215] | 340 | attach(leftHand_); |
---|
| 341 | attach(rightHand_); |
---|
[10078] | 342 | } |
---|
| 343 | |
---|
| 344 | void JumpFigure::moveFrontBack(const Vector2& value) |
---|
| 345 | { |
---|
[10215] | 346 | if (value.x > 0) |
---|
| 347 | { |
---|
| 348 | moveUpPressed_ = true; |
---|
| 349 | moveDownPressed_ = false; |
---|
| 350 | } |
---|
| 351 | else |
---|
| 352 | { |
---|
| 353 | moveUpPressed_ = false; |
---|
| 354 | moveDownPressed_ = true; |
---|
| 355 | } |
---|
[10078] | 356 | } |
---|
| 357 | |
---|
| 358 | void JumpFigure::moveRightLeft(const Vector2& value) |
---|
| 359 | { |
---|
[10215] | 360 | if (value.x > 0) |
---|
| 361 | { |
---|
| 362 | moveLeftPressed_ = false; |
---|
| 363 | moveRightPressed_ = true; |
---|
| 364 | } |
---|
| 365 | else |
---|
| 366 | { |
---|
| 367 | moveLeftPressed_ = true; |
---|
| 368 | moveRightPressed_ = false; |
---|
| 369 | } |
---|
[10078] | 370 | } |
---|
| 371 | |
---|
| 372 | void JumpFigure::rotateYaw(const Vector2& value) |
---|
| 373 | { |
---|
[10215] | 374 | horizontalSpeed_ = value.x; |
---|
[10078] | 375 | } |
---|
| 376 | |
---|
| 377 | void JumpFigure::rotatePitch(const Vector2& value) |
---|
| 378 | { |
---|
| 379 | |
---|
| 380 | |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | void JumpFigure::rotateRoll(const Vector2& value) |
---|
| 384 | { |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | void JumpFigure::fire(unsigned int firemode) |
---|
| 390 | { |
---|
| 391 | |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | void JumpFigure::fired(unsigned int firemode) |
---|
| 395 | { |
---|
[10215] | 396 | firePressed_ = true; |
---|
[10078] | 397 | } |
---|
| 398 | } |
---|