Changeset 5985 in orxonox.OLD for branches/powerups/src/world_entities/space_ships
- Timestamp:
- Dec 8, 2005, 1:10:27 AM (19 years ago)
- Location:
- branches/powerups/src/world_entities/space_ships
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/powerups/src/world_entities/space_ships/space_ship.cc
r5973 r5985 31 31 #include "factory.h" 32 32 #include "key_mapper.h" 33 #include "event_handler.h" 33 34 34 35 #include "power_ups/weapon_power_up.h" 36 37 #include "graphics_engine.h" 35 38 36 39 using namespace std; … … 88 91 Weapon* wpLeft = new TestGun(1); 89 92 wpLeft->setName("testGun Left"); 90 Weapon* cannon = dynamic_cast<Weapon*>(Factory:: getFirst()->fabricate(CL_CANNON));93 Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON)); 91 94 92 95 cannon->setName("BFG"); … … 112 115 PRINTF(4)("SPACESHIP INIT\n"); 113 116 114 115 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 117 EventHandler::getInstance()->grabEvents(true); 118 119 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; 116 120 bFire = false; 121 xMouse = yMouse = 0; 122 mouseSensitivity = 0.001; 123 124 cycle = 0.0; 125 117 126 118 127 travelSpeed = 15.0; … … 126 135 127 136 //add events to the eventlist 128 registerEvent(KeyMapper::PEV_UP); 129 registerEvent(KeyMapper::PEV_DOWN); 130 registerEvent(KeyMapper::PEV_LEFT); 131 registerEvent(KeyMapper::PEV_RIGHT); 137 registerEvent(SDLK_w); 138 registerEvent(SDLK_s); 139 registerEvent(SDLK_a); 140 registerEvent(SDLK_d); 141 registerEvent(SDLK_q); 142 registerEvent(SDLK_e); 132 143 registerEvent(KeyMapper::PEV_FIRE1); 133 144 registerEvent(KeyMapper::PEV_NEXT_WEAPON); … … 135 146 registerEvent(SDLK_PAGEUP); 136 147 registerEvent(SDLK_PAGEDOWN); 148 registerEvent(EV_MOUSE_MOTION); 137 149 138 150 this->getWeaponManager()->setSlotCount(7); … … 255 267 void SpaceShip::tick (float time) 256 268 { 269 cycle += time; 257 270 // spaceship controlled movement 258 271 this->calculateVelocity(time); … … 261 274 262 275 //orient the spaceship model in the direction of movement. 276 277 // this is the air friction (necessary for a smooth control) 278 if(velocity.len() != 0) velocity -= velocity*0.01; 279 280 this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); 281 282 //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); 263 283 264 284 this->shiftCoor (move); … … 283 303 if( this->bUp ) 284 304 { 285 this->shiftCoor(this->getAbsDirX());286 //if(travelSpeed <= 5000) travelSpeed += 10;305 //this->shiftCoor(this->getAbsDirX()); 306 accel += (this->getAbsDirX())*2; 287 307 } 288 308 289 309 if( this->bDown ) 290 310 { 291 this->shiftCoor(Vector()-this->getAbsDirX());292 //if(travelSpeed >= 10) travelSpeed -= 10;311 //this->shiftCoor((this->getAbsDirX())*-1); 312 accel -= (this->getAbsDirX())*2; 293 313 } 294 314 … … 310 330 //rotVal += .4; 311 331 } 332 333 if( this->bRollL /* > -this->getRelCoor().z*2*/) 334 { 335 this->shiftDir(Quaternion(-time, Vector(1,0,0))); 336 // accel -= rightDirection; 337 //velocityDir.normalize(); 338 //rot +=Vector(1,0,0); 339 //rotVal -= .4; 340 } 341 if( this->bRollR /* > this->getRelCoor().z*2*/) 342 { 343 this->shiftDir(Quaternion(time, Vector(1,0,0))); 344 345 // accel += rightDirection; 346 //velocityDir.normalize(); 347 //rot += Vector(1,0,0); 348 //rotVal += .4; 349 } 312 350 if (this->bAscend ) 313 351 { … … 329 367 } 330 368 331 velocity += accel *(time);369 velocity += accel; 332 370 //rot.normalize(); 333 371 //this->setRelDirSoft(Quaternion(rotVal, rot), 5); … … 350 388 void SpaceShip::process(const Event &event) 351 389 { 352 if( event.type == KeyMapper::PEV_UP) 353 this->bUp = event.bPressed; 354 else if( event.type == KeyMapper::PEV_DOWN) 355 this->bDown = event.bPressed; 356 else if( event.type == KeyMapper::PEV_RIGHT) 357 this->bRight= event.bPressed; 358 else if( event.type == KeyMapper::PEV_LEFT) 359 this->bLeft = event.bPressed; 390 391 392 if( event.type == SDLK_a) 393 this->bRollL = event.bPressed; 394 else if( event.type == SDLK_d) 395 this->bRollR = event.bPressed; 360 396 else if( event.type == KeyMapper::PEV_FIRE1) 361 397 this->bFire = event.bPressed; … … 365 401 this->getWeaponManager()->previousWeaponConfig(); 366 402 367 else if( event.type == SDLK_PAGEUP) 368 this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); 369 else if( event.type == SDLK_PAGEDOWN) 370 this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); 403 else if( event.type == SDLK_w) 404 this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); 405 else if( event.type == SDLK_s) 406 this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); 407 else if( event.type == EV_MOUSE_MOTION) 408 { 409 this->xMouse = event.xRel; 410 this->yMouse = event.yRel; 411 this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); 412 } 371 413 } 372 414 -
branches/powerups/src/world_entities/space_ships/space_ship.h
r5965 r5985 58 58 bool bDescend; //!< descend button presses. 59 59 bool bFire; //!< fire button pressed. 60 bool bRollL; //!< rolling button pressed (left) 61 bool bRollR; //!< rolling button pressed (right) 62 63 float xMouse; //!< mouse moved in x-Direction 64 float yMouse; //!< mouse moved in y-Direction 65 float mouseSensitivity; //!< the mouse sensitivity 66 float cycle; //!< hovercycle 60 67 61 68 Vector velocity; //!< the velocity of the player.
Note: See TracChangeset
for help on using the changeset viewer.