- Timestamp:
- May 22, 2014, 3:05:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickupsFS14/src/modules/jump/JumpFigure.cc
r10050 r10074 49 49 RegisterObject(JumpFigure); 50 50 51 this->movement_ = 0; 52 this->bMoveLocal_ = false; 53 this->length_ = 0.25; 54 this->fieldWidth_ = 180; 55 this->bSteadiedPosition_ = false; 51 leftHand_ = NULL; 52 rightHand_ = NULL; 53 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; 56 64 57 65 moveUpPressed = false; … … 66 74 mouseFactor_ = 75.0; 67 75 maxFireRate = 0.3; 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; 68 89 } 69 90 … … 76 97 SUPER(JumpFigure, XMLPort, xmlelement, mode); 77 98 XMLPortParam(JumpFigure, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode); 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); 78 110 } 79 111 … … 90 122 91 123 // If the bat is controlled (but not over the network). 92 if ( this->hasLocalController())124 if (hasLocalController()) 93 125 { 94 126 timeSinceLastFire += dt; 95 127 96 /*if (this->movement_ != 0) 97 { 98 // The absolute value of the movement is restricted to be lesser or equal than the speed of the bat. 99 this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; 100 101 // If moveRightLeft() is used the movement is dependento on wehther it is the right or the left bat, so, it is i.e. dependent on the orientation of the bat. 102 if (this->bMoveLocal_) 103 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0)); 104 else 105 this->setVelocity(0, 0, this->movement_); 106 107 this->movement_ = 0; 108 this->bSteadiedPosition_ = false; 109 } 110 // If there is no movement but the position has not been steadied, the velocity is set to zero and the position is reaffirmed. 111 else if (!this->bSteadiedPosition_) 112 { 113 // To ensure network synchronicity 114 this->setVelocity(0, 0, 0); 115 this->setPosition(this->getPosition()); 116 this->bSteadiedPosition_ = true; 117 }*/ 118 119 128 // Move up/down 120 129 Vector3 velocity = getVelocity(); 121 122 velocity.z -= gravityAcceleration; 123 124 /*if (moveLeftPressed == true) 125 { 126 velocity.x = -accelerationFactor; 127 moveLeftPressed = false; 128 } 129 if (moveRightPressed == true) 130 { 131 velocity.x = accelerationFactor; 132 moveRightPressed = false; 133 }*/ 134 135 velocity.x = -mouseFactor_*horizontalSpeed; 136 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 } 142 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 } 162 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 } 172 173 // Move left/right 174 if (dead_ == false) 175 { 176 velocity.x = -mouseFactor_*horizontalSpeed; 177 } 178 else 179 { 180 velocity.x = 0.0; 181 } 182 183 // Cheats 137 184 if (moveUpPressed == true) 138 185 { 139 186 velocity.z = 200.0f; 140 187 moveUpPressed = false; 188 dead_ = false; 141 189 } 142 190 if (moveDownPressed == true) … … 146 194 147 195 setVelocity(velocity); 196 148 197 149 198 if (firePressed && timeSinceLastFire >= maxFireRate) … … 156 205 } 157 206 158 Vector3 position = this->getPosition();159 207 // Move through the left and right screen boundaries 208 Vector3 position = getPosition(); 160 209 if (position.x < -fieldWidth_*1.1) 161 210 { … … 166 215 position.x = -fieldWidth_*1.1; 167 216 } 168 169 this->setPosition(position); 170 217 setPosition(position); 218 219 // Reset key variables 171 220 moveUpPressed = false; 172 221 moveDownPressed = false; … … 178 227 void JumpFigure::JumpFromPlatform(JumpPlatform* platform) 179 228 { 180 Vector3 velocity = getVelocity(); 181 velocity.z = 200.0f; 182 setVelocity(velocity); 183 } 184 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 } 239 } 240 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 } 250 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 } 185 366 186 367 /** 187 @brief 368 @briefhandPosition_ 188 369 Overloaded the function to steer the bat up and down. 189 370 @param value … … 216 397 if (value.x > 0) 217 398 { 218 //orxout() << "right pressed" << endl;219 399 moveLeftPressed = false; 220 400 moveRightPressed = true; … … 222 402 else 223 403 { 224 //orxout() << "left pressed" << endl;225 404 moveLeftPressed = true; 226 405 moveRightPressed = false; 227 406 } 228 /*this->bMoveLocal_ = true;229 this->movement_ = value.x;*/230 407 } 231 408 … … 233 410 { 234 411 horizontalSpeed = value.x; 235 236 412 } 237 413 … … 248 424 } 249 425 426 void JumpFigure::fire(unsigned int firemode) 427 { 428 //SUPER(JumpFigure, fire, firemode); 429 } 430 250 431 void JumpFigure::fired(unsigned int firemode) 251 432 { 252 orxout() << "fire pressed" << endl;433 //SUPER(JumpFigure, fired, firemode); 253 434 firePressed = true; 254 435 }
Note: See TracChangeset
for help on using the changeset viewer.