- Timestamp:
- Jan 31, 2015, 5:31:23 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS14/src/modules/jump/JumpFigure.cc
r10078 r10215 45 45 RegisterObject(JumpFigure); 46 46 47 47 // initialize variables 48 48 leftHand_ = NULL; 49 49 rightHand_ = NULL; … … 98 98 void JumpFigure::tick(float dt) 99 99 { 100 100 SUPER(JumpFigure, tick, dt); 101 101 102 102 if (hasLocalController()) 103 103 { 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 104 timeSinceLastFire_ += dt; 105 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 } 120 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 } 140 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 } 150 151 // Move left/right 152 if (dead_ == false) 153 { 154 velocity.x = -mouseFactor_*horizontalSpeed_; 155 } 156 else 157 { 158 velocity.x = 0.0; 159 } 160 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 }*/ 172 173 setVelocity(velocity); 174 175 176 if (firePressed_ && timeSinceLastFire_ >= maxFireRate_) 177 { 178 firePressed_ = false; 179 timeSinceLastFire_ = 0.0; 180 fireSignal_ = true; 181 } 182 182 } 183 183 … … 186 186 if (position.x < -fieldWidth_*1.1) 187 187 { 188 188 position.x = fieldWidth_*1.1; 189 189 } 190 190 else if (position.x > fieldWidth_*1.1) 191 191 { 192 192 position.x = -fieldWidth_*1.1; 193 193 } 194 194 setPosition(position); … … 204 204 void JumpFigure::JumpFromPlatform(JumpPlatform* platform) 205 205 { 206 207 208 209 210 211 212 213 214 215 206 if (dead_ == false) 207 { 208 Vector3 velocity = getVelocity(); 209 velocity.z = (bootsActive_ ? 1.2*jumpSpeed_ : jumpSpeed_); 210 setVelocity(velocity); 211 212 animateHands_ = true; 213 handAngle_ = 0.0; 214 turnUp_ = true; 215 } 216 216 } 217 217 218 218 void JumpFigure::JumpFromSpring(JumpSpring* spring) 219 219 { 220 221 222 223 224 225 220 if (dead_ == false) 221 { 222 Vector3 velocity = getVelocity(); 223 velocity.z = 1.2*jumpSpeed_; 224 setVelocity(velocity); 225 } 226 226 } 227 227 228 228 void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy) 229 230 231 232 233 234 229 { 230 if (rocketActive_ == false && propellerActive_ == false && shieldActive_ == false) 231 { 232 dead_ = true; 233 } 234 } 235 235 236 236 bool JumpFigure::StartRocket(JumpRocket* rocket) 237 237 { 238 239 240 241 242 243 244 245 246 247 248 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; 244 245 return true; 246 } 247 248 return false; 249 249 } 250 250 251 251 void JumpFigure::StopRocket(JumpRocket* rocket) 252 252 { 253 254 255 256 257 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; 258 258 } 259 259 260 260 bool JumpFigure::StartPropeller(JumpPropeller* propeller) 261 261 { 262 263 264 265 266 267 268 269 270 271 272 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; 268 269 return true; 270 } 271 272 return false; 273 273 } 274 274 275 275 void JumpFigure::StopPropeller(JumpPropeller* propeller) 276 276 { 277 278 279 280 281 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; 282 282 } 283 283 284 284 bool JumpFigure::StartBoots(JumpBoots* boots) 285 285 { 286 287 288 289 290 291 292 293 294 295 296 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; 292 293 return true; 294 } 295 296 return false; 297 297 } 298 298 299 299 void JumpFigure::StopBoots(JumpBoots* boots) 300 300 { 301 302 303 304 305 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; 306 306 } 307 307 308 308 bool JumpFigure::StartShield(JumpShield* shield) 309 309 { 310 311 312 313 314 315 316 317 318 319 320 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; 316 317 return true; 318 } 319 320 return false; 321 321 } 322 322 323 323 void JumpFigure::StopShield(JumpShield* shield) 324 324 { 325 326 327 328 329 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; 330 330 } 331 331 332 332 void JumpFigure::InitializeAnimation(Context* context) 333 333 { 334 335 336 337 338 339 340 341 334 leftHand_ = new Model(context); 335 rightHand_ = new Model(context); 336 337 leftHand_->addTemplate(modelLeftHand_); 338 rightHand_->addTemplate(modelRightHand_); 339 340 attach(leftHand_); 341 attach(rightHand_); 342 342 } 343 343 344 344 void JumpFigure::moveFrontBack(const Vector2& value) 345 345 { 346 347 348 349 350 351 352 353 354 355 346 if (value.x > 0) 347 { 348 moveUpPressed_ = true; 349 moveDownPressed_ = false; 350 } 351 else 352 { 353 moveUpPressed_ = false; 354 moveDownPressed_ = true; 355 } 356 356 } 357 357 358 358 void JumpFigure::moveRightLeft(const Vector2& value) 359 359 { 360 361 362 363 364 365 366 367 368 369 360 if (value.x > 0) 361 { 362 moveLeftPressed_ = false; 363 moveRightPressed_ = true; 364 } 365 else 366 { 367 moveLeftPressed_ = true; 368 moveRightPressed_ = false; 369 } 370 370 } 371 371 372 372 void JumpFigure::rotateYaw(const Vector2& value) 373 373 { 374 374 horizontalSpeed_ = value.x; 375 375 } 376 376 … … 394 394 void JumpFigure::fired(unsigned int firemode) 395 395 { 396 396 firePressed_ = true; 397 397 } 398 398 }
Note: See TracChangeset
for help on using the changeset viewer.