[6868] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Knecht |
---|
| 13 | co-programmer: Silvan Nellen |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 18 | |
---|
| 19 | #include "executor/executor.h" |
---|
| 20 | #include "space_ship.h" |
---|
| 21 | |
---|
[7193] | 22 | #include "util/loading/resource_manager.h" |
---|
[6868] | 23 | |
---|
| 24 | #include "weapons/test_gun.h" |
---|
| 25 | #include "weapons/turret.h" |
---|
| 26 | #include "weapons/cannon.h" |
---|
| 27 | |
---|
| 28 | #include "dot_emitter.h" |
---|
| 29 | #include "sprite_particles.h" |
---|
| 30 | |
---|
[7193] | 31 | #include "util/loading/factory.h" |
---|
[6868] | 32 | #include "key_mapper.h" |
---|
| 33 | |
---|
| 34 | #include "network_game_manager.h" |
---|
[8708] | 35 | #include "shared_network_data.h" |
---|
[6868] | 36 | |
---|
| 37 | #include "power_ups/weapon_power_up.h" |
---|
| 38 | #include "power_ups/param_power_up.h" |
---|
| 39 | |
---|
| 40 | #include "graphics_engine.h" |
---|
| 41 | |
---|
| 42 | #include "plane.h" |
---|
| 43 | |
---|
| 44 | #include "state.h" |
---|
| 45 | #include "player.h" |
---|
| 46 | |
---|
[7193] | 47 | #include "util/loading/load_param.h" |
---|
[6868] | 48 | |
---|
[7056] | 49 | |
---|
[6868] | 50 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
| 51 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | using namespace std; |
---|
| 55 | |
---|
| 56 | CREATE_FACTORY(SpaceShip, CL_SPACE_SHIP); |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * destructs the spaceship, deletes alocated memory |
---|
| 61 | */ |
---|
| 62 | SpaceShip::~SpaceShip () |
---|
| 63 | { |
---|
[6986] | 64 | this->setPlayer(NULL); |
---|
[6868] | 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * loads a Spaceships information from a specified file. |
---|
| 69 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
| 70 | */ |
---|
[7221] | 71 | SpaceShip::SpaceShip(const std::string& fileName) |
---|
[6868] | 72 | { |
---|
| 73 | this->init(); |
---|
| 74 | TiXmlDocument doc(fileName); |
---|
| 75 | |
---|
| 76 | if(!doc.LoadFile()) |
---|
| 77 | { |
---|
[7221] | 78 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); |
---|
[6868] | 79 | return; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | this->loadParams(doc.RootElement()); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * creates a new Spaceship from Xml Data |
---|
| 87 | * @param root the xml element containing spaceship data |
---|
| 88 | |
---|
| 89 | @todo add more parameters to load |
---|
| 90 | */ |
---|
| 91 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
| 92 | { |
---|
| 93 | this->init(); |
---|
| 94 | if (root != NULL) |
---|
| 95 | this->loadParams(root); |
---|
| 96 | |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * initializes a Spaceship |
---|
| 102 | */ |
---|
| 103 | void SpaceShip::init() |
---|
| 104 | { |
---|
| 105 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 106 | this->setClassID(CL_SPACE_SHIP, "SpaceShip"); |
---|
| 107 | |
---|
| 108 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
| 109 | |
---|
| 110 | //weapons: |
---|
| 111 | Weapon* wpRight = new TestGun(0); |
---|
| 112 | wpRight->setName("testGun Right"); |
---|
| 113 | Weapon* wpLeft = new TestGun(1); |
---|
| 114 | wpLeft->setName("testGun Left"); |
---|
[7087] | 115 | //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON)); |
---|
[6868] | 116 | |
---|
[7087] | 117 | //cannon->setName("BFG"); |
---|
[6868] | 118 | |
---|
| 119 | this->addWeapon(wpLeft, 1, 0); |
---|
| 120 | this->addWeapon(wpRight,1 ,1); |
---|
[7087] | 121 | //this->addWeapon(cannon, 0, 6); |
---|
[6868] | 122 | |
---|
[7337] | 123 | this->getWeaponManager().changeWeaponConfig(1); |
---|
[6868] | 124 | |
---|
| 125 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; |
---|
| 126 | |
---|
| 127 | xMouse = yMouse = 0; |
---|
| 128 | yInvert = 1; |
---|
| 129 | mouseSensitivity = 0.001; |
---|
[7122] | 130 | airViscosity = 0.9; |
---|
[6868] | 131 | controlVelocityX = 25; |
---|
| 132 | controlVelocityY = 150; |
---|
| 133 | shipInertia = 1.5; |
---|
| 134 | // cycle = 0.0; |
---|
| 135 | |
---|
| 136 | this->setHealthMax(100); |
---|
| 137 | this->setHealth(80); |
---|
| 138 | |
---|
[6947] | 139 | travelSpeed = 0.0; |
---|
[6868] | 140 | acceleration = 3; |
---|
| 141 | this->velocity = this->getAbsDirX()*travelSpeed; |
---|
| 142 | this->mouseDir = this->getAbsDir(); |
---|
| 143 | this->pitchDir = this->getAbsDir(); |
---|
| 144 | |
---|
| 145 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 146 | // button->show(); |
---|
| 147 | // button->setLabel("orxonox"); |
---|
| 148 | // button->setBindNode(this); |
---|
| 149 | // GLGuiBar* bar = new GLGuiBar(); |
---|
| 150 | // bar->show(); |
---|
| 151 | // bar->setValue(7.0); |
---|
| 152 | // bar->setMaximum(10); |
---|
| 153 | // bar->setSize2D( 20, 100); |
---|
| 154 | // bar->setAbsCoor2D( 10, 200); |
---|
| 155 | |
---|
| 156 | //add events to the eventlist |
---|
[6997] | 157 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 158 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
[6868] | 159 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 160 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 161 | //registerEvent(SDLK_q); |
---|
| 162 | //registerEvent(SDLK_e); |
---|
| 163 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 164 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 165 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 166 | //registerEvent(SDLK_PAGEUP); |
---|
| 167 | //registerEvent(SDLK_PAGEDOWN); |
---|
| 168 | registerEvent(EV_MOUSE_MOTION); |
---|
| 169 | |
---|
[7337] | 170 | this->getWeaponManager().setSlotCount(7); |
---|
[6868] | 171 | |
---|
[7337] | 172 | this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 173 | this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 174 | |
---|
[7337] | 175 | this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 176 | this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 177 | |
---|
[7337] | 178 | this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 179 | this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 180 | |
---|
[7337] | 181 | this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 182 | this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 183 | |
---|
[7337] | 184 | this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 185 | this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
[6868] | 186 | |
---|
[7337] | 187 | this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 188 | this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[6868] | 189 | // |
---|
[7337] | 190 | this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0)); |
---|
| 191 | this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 192 | // |
---|
[7337] | 193 | // this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 194 | // this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
[6868] | 195 | // |
---|
[7337] | 196 | // this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 197 | // this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
[6868] | 198 | |
---|
[7337] | 199 | this->getWeaponManager().getFixedTarget()->setParent(this); |
---|
| 200 | this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0); |
---|
[6868] | 201 | |
---|
[7337] | 202 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6868] | 203 | |
---|
| 204 | this->burstEmitter = new DotEmitter(200, 0.0, .01); |
---|
| 205 | this->burstEmitter->setParent(this); |
---|
| 206 | this->burstEmitter->setRelCoor(-1, .5, 0); |
---|
| 207 | this->burstEmitter->setName("SpaceShip_Burst_emitter"); |
---|
| 208 | |
---|
| 209 | this->burstSystem = new SpriteParticles(1000); |
---|
| 210 | this->burstSystem->addEmitter(this->burstEmitter); |
---|
| 211 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
| 212 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 213 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
| 214 | this->burstSystem->setRadius(0.0, 1.0); |
---|
| 215 | this->burstSystem->setRadius(0.05, 1.0); |
---|
| 216 | this->burstSystem->setRadius(.5, .8); |
---|
| 217 | this->burstSystem->setRadius(1.0, 0); |
---|
| 218 | this->burstSystem->setColor(0.0, .7,.7,1,.7); |
---|
| 219 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
| 220 | this->burstSystem->setColor(0.5, .5,.5,.8,.8); |
---|
| 221 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
[7954] | 222 | |
---|
| 223 | registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity" ) ); |
---|
| 224 | registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); |
---|
[6868] | 225 | |
---|
[7954] | 226 | registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) ); |
---|
| 227 | registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) ); |
---|
| 228 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 229 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 230 | registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); |
---|
| 231 | registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); |
---|
| 232 | registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) ); |
---|
| 233 | registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) ); |
---|
[6868] | 234 | } |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | /** |
---|
| 238 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 239 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 240 | */ |
---|
| 241 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 242 | { |
---|
| 243 | Playable::loadParams(root); |
---|
| 244 | } |
---|
| 245 | |
---|
[7346] | 246 | void SpaceShip::setPlayDirection(const Quaternion& quat, float speed) |
---|
[7056] | 247 | { |
---|
[7095] | 248 | this->mouseDir = quat; |
---|
[7056] | 249 | } |
---|
[6868] | 250 | |
---|
[7056] | 251 | |
---|
[7085] | 252 | void SpaceShip::reset() |
---|
| 253 | { |
---|
| 254 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; |
---|
[7056] | 255 | |
---|
[7085] | 256 | xMouse = yMouse = 0; |
---|
| 257 | |
---|
| 258 | this->setHealth(80); |
---|
| 259 | this->velocity = Vector(0.0, 0.0, 0.0); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | |
---|
[6868] | 263 | void SpaceShip::enter() |
---|
| 264 | { |
---|
[7337] | 265 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
[6868] | 266 | this->attachCamera(); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | void SpaceShip::leave() |
---|
| 270 | { |
---|
[7337] | 271 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6868] | 272 | this->detachCamera(); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | /** |
---|
| 277 | * effect that occurs after the SpaceShip is spawned |
---|
| 278 | */ |
---|
| 279 | void SpaceShip::postSpawn () |
---|
| 280 | { |
---|
| 281 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
| 285 | * the action occuring if the spaceship left the game |
---|
| 286 | */ |
---|
| 287 | void SpaceShip::leftWorld () |
---|
| 288 | {} |
---|
| 289 | |
---|
| 290 | WorldEntity* ref = NULL; |
---|
| 291 | /** |
---|
| 292 | * this function is called, when two entities collide |
---|
| 293 | * @param entity: the world entity with whom it collides |
---|
| 294 | * |
---|
| 295 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 296 | */ |
---|
| 297 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 298 | { |
---|
| 299 | Playable::collidesWith(entity, location); |
---|
[6959] | 300 | |
---|
| 301 | if( entity->isA(CL_PROJECTILE) && entity != ref) |
---|
| 302 | { |
---|
| 303 | if ( isServer() ) |
---|
| 304 | { |
---|
[7954] | 305 | //TODO handle this |
---|
[6868] | 306 | } |
---|
[6959] | 307 | } |
---|
[8228] | 308 | PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); |
---|
[6868] | 309 | } |
---|
| 310 | |
---|
| 311 | /** |
---|
| 312 | * draws the spaceship after transforming it. |
---|
| 313 | */ |
---|
| 314 | void SpaceShip::draw () const |
---|
| 315 | { |
---|
| 316 | WorldEntity::draw(); |
---|
| 317 | |
---|
| 318 | //this->debug(0); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | /** |
---|
| 322 | * the function called for each passing timeSnap |
---|
| 323 | * @param time The timespan passed since last update |
---|
| 324 | */ |
---|
| 325 | void SpaceShip::tick (float time) |
---|
| 326 | { |
---|
| 327 | Playable::tick(time); |
---|
| 328 | |
---|
[8708] | 329 | if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) |
---|
[6868] | 330 | { |
---|
| 331 | if (xMouse > controlVelocityX) xMouse = controlVelocityX; |
---|
| 332 | else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; |
---|
| 333 | if (yMouse > controlVelocityY) yMouse = controlVelocityY; |
---|
| 334 | else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; |
---|
| 335 | |
---|
| 336 | pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); |
---|
| 337 | |
---|
| 338 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); |
---|
| 339 | xMouse = yMouse = 0; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | // if( this != State::getPlayer()->getControllable()) |
---|
| 344 | // return; |
---|
| 345 | |
---|
| 346 | // spaceship controlled movement |
---|
[7954] | 347 | //if (this->getOwner() == this->getHostID()) |
---|
[6959] | 348 | this->calculateVelocity(time); |
---|
[6868] | 349 | |
---|
[6959] | 350 | |
---|
[6868] | 351 | Vector move = velocity*time; |
---|
| 352 | |
---|
| 353 | //orient the velocity in the direction of the spaceship. |
---|
| 354 | travelSpeed = velocity.len(); |
---|
| 355 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
| 356 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
| 357 | this->burstEmitter->setEmissionRate(travelSpeed); |
---|
| 358 | this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1); |
---|
| 359 | |
---|
| 360 | //orient the spaceship in direction of the mouse |
---|
| 361 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); |
---|
| 362 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
| 363 | this->setAbsDir( rotQuat); |
---|
| 364 | //this->setAbsDirSoft(mouseDir,5); |
---|
| 365 | |
---|
| 366 | // this is the air friction (necessary for a smooth control) |
---|
| 367 | if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; |
---|
| 368 | else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; |
---|
| 369 | |
---|
| 370 | //other physics (gravity) |
---|
| 371 | //if(travelSpeed < 120) |
---|
| 372 | //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; |
---|
| 373 | |
---|
| 374 | //hoover effect |
---|
| 375 | //cycle += time; |
---|
| 376 | //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
| 377 | |
---|
| 378 | //readjust |
---|
| 379 | //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 380 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 381 | |
---|
| 382 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
| 383 | |
---|
| 384 | this->shiftCoor(move); |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | /** |
---|
| 390 | * calculate the velocity |
---|
| 391 | * @param time the timeslice since the last frame |
---|
| 392 | */ |
---|
| 393 | void SpaceShip::calculateVelocity (float time) |
---|
| 394 | { |
---|
| 395 | Vector accel(0.0, 0.0, 0.0); |
---|
| 396 | /* |
---|
| 397 | Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter |
---|
| 398 | */ |
---|
| 399 | //float rotVal = 0.0; |
---|
| 400 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
| 401 | /* calculate the direction in which the craft is heading */ |
---|
| 402 | |
---|
| 403 | //Plane plane(Vector(0,1,0), Vector(0,0,0)); |
---|
| 404 | |
---|
| 405 | if( this->bUp ) |
---|
| 406 | { |
---|
| 407 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 408 | //accel += (this->getAbsDirX())*2; |
---|
| 409 | accel += (this->getAbsDirX())*acceleration; |
---|
| 410 | |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | if( this->bDown ) |
---|
| 414 | { |
---|
| 415 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 416 | //accel -= (this->getAbsDirX())*2; |
---|
| 417 | //if(velocity.len() > 50) |
---|
| 418 | accel -= (this->getAbsDirX())*0.5*acceleration; |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | if( this->bLeft/* > -this->getRelCoor().z*2*/) |
---|
| 425 | { |
---|
| 426 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 427 | // accel -= rightDirection; |
---|
| 428 | //velocityDir.normalize(); |
---|
| 429 | //rot +=Vector(1,0,0); |
---|
| 430 | //rotVal -= .4; |
---|
| 431 | } |
---|
| 432 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 433 | { |
---|
| 434 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
| 435 | |
---|
| 436 | // accel += rightDirection; |
---|
| 437 | //velocityDir.normalize(); |
---|
| 438 | //rot += Vector(1,0,0); |
---|
| 439 | //rotVal += .4; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | |
---|
| 443 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 444 | { |
---|
| 445 | mouseDir *= Quaternion(-time*2, Vector(1,0,0)); |
---|
| 446 | // accel -= rightDirection; |
---|
| 447 | //velocityDir.normalize(); |
---|
| 448 | //rot +=Vector(1,0,0); |
---|
| 449 | //rotVal -= .4; |
---|
| 450 | } |
---|
| 451 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 452 | { |
---|
| 453 | mouseDir *= Quaternion(time*2, Vector(1,0,0)); |
---|
| 454 | |
---|
| 455 | // accel += rightDirection; |
---|
| 456 | //velocityDir.normalize(); |
---|
| 457 | //rot += Vector(1,0,0); |
---|
| 458 | //rotVal += .4; |
---|
| 459 | } |
---|
| 460 | if (this->bAscend ) |
---|
| 461 | { |
---|
| 462 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 463 | |
---|
| 464 | // accel += upDirection; |
---|
| 465 | //velocityDir.normalize(); |
---|
| 466 | //rot += Vector(0,0,1); |
---|
| 467 | //rotVal += .4; |
---|
| 468 | } |
---|
| 469 | if (this->bDescend ) |
---|
| 470 | { |
---|
| 471 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 472 | |
---|
| 473 | // accel -= upDirection; |
---|
| 474 | //velocityDir.normalize(); |
---|
| 475 | //rot += Vector(0,0,1); |
---|
| 476 | //rotVal -= .4; |
---|
| 477 | } |
---|
| 478 | |
---|
[6959] | 479 | velocity += accel*time*10; |
---|
[6868] | 480 | //rot.normalize(); |
---|
| 481 | //this->setRelDirSoft(Quaternion(rotVal, rot), 5); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | /** |
---|
| 485 | * @todo switch statement ?? |
---|
| 486 | */ |
---|
| 487 | void SpaceShip::process(const Event &event) |
---|
| 488 | { |
---|
| 489 | Playable::process(event); |
---|
| 490 | |
---|
| 491 | if( event.type == KeyMapper::PEV_LEFT) |
---|
| 492 | this->bRollL = event.bPressed; |
---|
| 493 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
| 494 | this->bRollR = event.bPressed; |
---|
[6997] | 495 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[6868] | 496 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 497 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[6868] | 498 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
| 499 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 500 | { |
---|
| 501 | this->xMouse += event.xRel; |
---|
| 502 | this->yMouse += event.yRel; |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | |
---|
[8827] | 506 | void SpaceShip::destroy( ) |
---|
| 507 | { |
---|
| 508 | PRINTF(0)("spaceship destroy\n"); |
---|
| 509 | } |
---|
[6868] | 510 | |
---|
[8827] | 511 | void SpaceShip::respawn( ) |
---|
| 512 | { |
---|
| 513 | toList( OM_PLAYERS ); |
---|
| 514 | } |
---|
[6868] | 515 | |
---|
| 516 | |
---|
[8827] | 517 | |
---|
| 518 | |
---|