Changeset 10698 in orxonox.OLD for trunk/src/world_entities/creatures
- Timestamp:
- Jun 14, 2007, 5:33:43 PM (18 years ago)
- Location:
- trunk/src/world_entities/creatures
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/creatures/fps_player.cc
r10618 r10698 19 19 #include "interactive_model.h" 20 20 #include "state.h" 21 #include "tools/camera.h" 22 #include "player.h" 21 23 22 24 #include "src/lib/util/loading/factory.h" … … 51 53 ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) 52 54 ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) 55 ->addMethod("displayHUDText", Executor1<FPSPlayer, lua_State*, const std::string&>(&FPSPlayer::displayHUDText)) 53 56 ); 54 57 … … 95 98 this->bPosBut = false; 96 99 this->bFire = false; 100 this->bFire2 = false; 101 this->changeZoom = true; 102 this->inZoomMode = false; 103 this->changingZoom = false; 97 104 98 105 this->xMouse = 0.0f; … … 116 123 registerEvent(KeyMapper::PEV_RIGHT); 117 124 registerEvent(KeyMapper::PEV_FIRE1); 125 registerEvent(KeyMapper::PEV_FIRE2); 118 126 registerEvent(KeyMapper::PEV_JUMP); 127 registerEvent(KeyMapper::PEV_CROUCH); 119 128 registerEvent(EV_MOUSE_MOTION); 120 129 … … 149 158 150 159 this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); 151 this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); 160 this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ALL); 161 this->getWeaponManager().getFixedTarget()->setRelCoor(10,0,0); 152 162 153 163 … … 179 189 } 180 190 181 191 /** 192 * was probabably designed for setting direction of FPSPlayer 193 * but hey, this connot work like this, can it? 194 */ 182 195 void FPSPlayer::setPlayDirection(const Quaternion& quat, float speed) 183 196 { … … 186 199 } 187 200 188 201 /** 202 * Resets FPSPlayer stats and freezes its moving directions 203 * 204 */ 189 205 void FPSPlayer::reset() 190 206 { … … 195 211 this->xMouse = 0.0f; 196 212 this->yMouse = 0.0f; 213 this->inZoomMode = false; 197 214 198 215 this->setHealth(80); 199 216 } 200 217 201 218 /** 219 * Defines what happens to camera and other important elements when changing 220 * into FPS-view 221 */ 202 222 void FPSPlayer::enter() 203 223 { … … 206 226 State::getCameraNode()->setParentSoft(&this->cameraNode); 207 227 State::getCameraTargetNode()->setParentSoft(&this->cameraNode); 208 209 this->getWeaponManager().getFixedTarget()->setParent(State::getCameraTargetNode()); 210 this->getWeaponManager().getFixedTarget()->setRelCoor(0,0,0); 228 229 State::getCamera()->setViewMode(Camera::ViewFPS); 230 231 this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); 232 //this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ALL); 233 //this->getWeaponManager().getFixedTarget()->setRelCoor(100,0,0); 211 234 212 235 if ( !State::isOnline() ) … … 216 239 } 217 240 241 /** 242 * Defines what happens if active player leaves FPSPlayer 243 * (basicly hides crosshair and frees camera) 244 */ 218 245 void FPSPlayer::leave() 219 246 { … … 230 257 void FPSPlayer::tick (float time) 231 258 { 232 259 // Second init-step 233 260 if ( !this->initWeapon ) 234 261 { … … 239 266 this->getWeaponManager().getParentNode()->setParentMode(PNODE_ROTATE_AND_MOVE); 240 267 this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); 241 this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ROTATE_AND_MOVE); 268 //this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ROTATE_AND_MOVE); 269 State::getCamera()->setViewMode(Camera::ViewFPS); 242 270 243 271 … … 251 279 } 252 280 253 254 AABB* box = this->getModelAABB(); 255 if( box != NULL) 256 { 281 } 282 // end of second init-step 283 284 // This box represents the dimension of the used model 285 AABB* box = this->getModelAABB(); 286 287 if( box != NULL) 288 { 257 289 float f = 1.0; 290 if( this->bCrouch ) 291 f = 0.3*f; 292 258 293 this->cameraNode.setRelCoor(0, box->halfLength[1] * f, 0); 259 // this->cameraNode.setRelCoor(10, box->halfLength[1] * f, 0); 260 261 float v = 0.1f; 262 this->getWeaponManager().setSlotPosition(0, Vector(-8.0, box->halfLength[1] * v, 1.1)); 263 this->getWeaponManager().setSlotPosition(1, Vector(5.0, box->halfLength[1] * v, 0.0)); 264 } 265 } 266 294 // this->cameraNode.setRelCoor(10, box->halfLength[1] * f, 0); 295 float v = 0.1f; 296 this->getWeaponManager().setSlotPosition(0, Vector(-8.0, box->halfLength[1] * v, 1.1)); 297 this->getWeaponManager().setSlotPosition(1, Vector(5.0, box->halfLength[1] * v, 0.0)); 298 } 299 300 /* 301 if( this->bFire2 ) 302 { 303 304 // to change Zoom on click 305 if( this->changeZoom ) 306 { 307 this->changeZoom = false; 308 if( this->inZoomMode ) 309 { 310 State::getCamera()->setViewMode(Camera::ViewFPS); 311 this->inZoomMode = false; 312 } 313 else 314 { 315 State::getCamera()->setViewMode(Camera::ViewFPSZoom); 316 this->inZoomMode = true; 317 } 318 319 } 320 321 } 322 else 323 { 324 this->changeZoom = true; 325 }*/ 326 if( this->bFire2 ) 327 { 328 if( this->changeZoom ) 329 { 330 if( !this->inZoomMode || this->changingZoom ) 331 { 332 this->inZoomMode = true; 333 this->changingZoom = true; 334 float fovy = State::getCamera()->getFovy(); 335 if( fovy > 30 ) 336 State::getCamera()->setFovy( fovy - 10*time ); 337 } 338 else 339 { 340 State::getCamera()->setViewMode(Camera::ViewFPS); 341 this->inZoomMode = false; 342 this->changeZoom = false; 343 } 344 } 345 } 346 else 347 { 348 this->changeZoom = true; 349 this->changingZoom = false; 350 } 267 351 268 352 this->getWeaponManager().tick(time); … … 301 385 xMouse *= time ; 302 386 yMouse *= time ; 303 304 heading -= xMouse/5.; 305 attitude-= yMouse/5.; 387 388 float amount; 389 390 if( this->inZoomMode ) 391 amount = 2.; 392 else 393 amount = 5.; 394 395 heading -= xMouse/amount; 396 attitude-= yMouse/amount; 306 397 307 398 … … 346 437 }*/ 347 438 348 velocity *= 100; 439 int speed; 440 if( this->bCrouch ) 441 speed = 50; 442 else 443 speed = 100; 444 velocity *= speed; 349 445 350 446 if( this->getModel( 0) != NULL && this->getModel(0)->isA(InteractiveModel::staticClassID())) 351 447 { 352 if( this->bJump) 353 { 354 if( this->jumpAcceleration < 1.0f) 448 if( this->bJump) 355 449 { 356 this->jumpAcceleration = 300.0f; 357 358 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != JUMP) 359 ((InteractiveModel*)this->getModel(0))->setAnimation(JUMP); 360 } 361 } 362 else if(velocity.len() != 0.0f) 363 { 364 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != RUN) 365 ((InteractiveModel*)this->getModel(0))->setAnimation(RUN); 366 } 367 else 368 { 369 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != STAND) 370 ((InteractiveModel*)this->getModel(0))->setAnimation(STAND); 371 } 450 if( this->jumpAcceleration < 1.0f) 451 { 452 this->jumpAcceleration = 300.0f; 453 454 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != JUMP) 455 ((InteractiveModel*)this->getModel(0))->setAnimation(JUMP); 456 } 457 } 458 else if(velocity.len() != 0.0f) 459 { 460 if( this->bCrouch ) 461 { 462 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != CROUCH_WALK) 463 ((InteractiveModel*)this->getModel(0))->setAnimation(CROUCH_WALK); 464 } 465 else 466 { 467 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != RUN) 468 ((InteractiveModel*)this->getModel(0))->setAnimation(RUN); 469 } 470 471 } 472 else 473 { 474 if( this->bCrouch ) 475 { 476 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != CROUCH_STAND) 477 ((InteractiveModel*)this->getModel(0))->setAnimation(CROUCH_STAND); 478 } 479 else 480 { 481 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != STAND) 482 ((InteractiveModel*)this->getModel(0))->setAnimation(STAND); 483 } 484 } 485 486 if( this->bFire ) 487 { 488 if( this->bCrouch ) 489 { 490 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != CROUCH_ATTACK) 491 ((InteractiveModel*)this->getModel(0))->setAnimation(CROUCH_ATTACK); 492 } 493 else 494 { 495 if( ((InteractiveModel*)this->getModel(0))->getAnimation() != ATTACK) 496 ((InteractiveModel*)this->getModel(0))->setAnimation(ATTACK); 497 } 498 } 372 499 } 373 500 … … 390 517 this->fallVelocity = 0.0f; 391 518 } 392 if((velocity *time).len() < 10.0f) this->shiftCoor( velocity*time ); 393 else{ 519 if((velocity * time).len() < 10.0f) this->shiftCoor( velocity*time ); 520 else 521 { 394 522 velocity.normalize(); 395 523 velocity *= 10.0f; 396 524 this->shiftCoor( velocity ); 397 } 398 399 525 } 400 526 401 527 … … 409 535 if( this->aimingSystem != NULL) 410 536 this->aimingSystem->flushList(); 537 411 538 } 412 539 … … 426 553 427 554 /** 428 * process555 * checks events 429 556 */ 430 557 void FPSPlayer::process(const Event &event) … … 440 567 else if( event.type == KeyMapper::PEV_BACKWARD) 441 568 this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); 569 else if( event.type == KeyMapper::PEV_JUMP) 570 this->bJump = event.bPressed; 571 else if( event.type == KeyMapper::PEV_FIRE1) 572 this->bFire = event.bPressed; 573 else if( event.type == KeyMapper::PEV_FIRE2) 574 this->bFire2 = event.bPressed; 575 else if( event.type == KeyMapper::PEV_CROUCH) 576 this->bCrouch = event.bPressed; 442 577 else if( event.type == EV_MOUSE_MOTION) 443 578 { … … 445 580 this->yMouse += event.yRel; 446 581 } 447 else if( event.type == KeyMapper::PEV_JUMP) 448 { 449 this->bJump = event.bPressed; 450 } 451 else if( event.type == KeyMapper::PEV_FIRE1) 452 { 453 this->bFire = event.bPressed; 454 } 455 } 456 457 582 } 583 584 /** 585 * respawns FPSplayer 586 */ 458 587 void FPSPlayer::respawn( ) 459 588 { … … 466 595 } 467 596 468 597 /** 598 * Kills the FPSplayer defining its killer 599 */ 469 600 void FPSPlayer::destroy( WorldEntity* killer ) 470 601 { … … 474 605 } 475 606 607 void FPSPlayer::displayHUDText( const std::string& message ) 608 { 609 State::getPlayer()->hud().notifyUser(message); 610 } -
trunk/src/world_entities/creatures/fps_player.h
r10566 r10698 36 36 virtual void tick(float time); 37 37 virtual void draw() const; 38 39 void displayHUDText( const std::string& message ); 38 40 39 41 … … 43 45 void init(); 44 46 45 bool bLeft; 46 bool bRight; 47 bool bForward; 48 bool bBackward; 49 bool bJump; //!< jumping 50 bool bPosBut; //!< position button 51 bool bFire; //!< fire button 47 bool bLeft; //!< strafe left 48 bool bRight; //!< strafe right 49 bool bForward; //!< walk forward 50 bool bBackward; //!< walk backward 51 bool bJump; //!< jumping 52 bool bPosBut; //!< position button 53 bool bFire; //!< fire button 54 bool bFire2; //!< alternate fire button 55 bool bCrouch; //!< crouch button 52 56 53 float xMouse; 54 float yMouse; 57 float xMouse; //!< mouse moved in x-Direction 58 float yMouse; //!< mouse moved in y-Direction 55 59 56 60 57 float heading; 58 float attitude; 61 float heading; //!< the direction where the player heads to 62 float attitude; //!< defines the camera angle to the x-z-plane 59 63 60 PNode cameraNode; 64 PNode cameraNode; //!< the "eyes" of the player (or call it head if you want) 61 65 62 float fallVelocity; 63 float jumpAcceleration; 66 float fallVelocity; //!< velocity for falling down 67 float jumpAcceleration; //!< the jump acceleration 64 68 65 69 bool initWeapon; 70 bool changeZoom; //!< zoom sight of player 71 bool inZoomMode; //!< zoomsight 72 bool changingZoom; 66 73 67 AimingSystem* aimingSystem; 74 AimingSystem* aimingSystem; //!< aiming system of the player 68 75 69 float damageTicker; //!< ticker for dealing damage 76 float damageTicker; //!< ticker for dealing damage 77 70 78 }; 71 79
Note: See TracChangeset
for help on using the changeset viewer.