[5907] | 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 |
---|
[6034] | 13 | co-programmer: Silvan Nellen |
---|
[5907] | 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 18 | |
---|
| 19 | #include "executor/executor.h" |
---|
| 20 | #include "space_ship.h" |
---|
| 21 | |
---|
[6034] | 22 | #include "objModel.h" |
---|
[5907] | 23 | #include "resource_manager.h" |
---|
| 24 | |
---|
| 25 | #include "weapons/weapon_manager.h" |
---|
| 26 | #include "weapons/test_gun.h" |
---|
| 27 | #include "weapons/turret.h" |
---|
| 28 | #include "weapons/cannon.h" |
---|
| 29 | |
---|
| 30 | #include "factory.h" |
---|
| 31 | #include "key_mapper.h" |
---|
[5978] | 32 | #include "event_handler.h" |
---|
[5907] | 33 | |
---|
[6243] | 34 | #include "power_ups/weapon_power_up.h" |
---|
| 35 | #include "power_ups/param_power_up.h" |
---|
| 36 | |
---|
[5978] | 37 | #include "graphics_engine.h" |
---|
| 38 | |
---|
[6287] | 39 | |
---|
| 40 | |
---|
[6306] | 41 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
| 42 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
[6287] | 43 | |
---|
| 44 | |
---|
[5907] | 45 | using namespace std; |
---|
| 46 | |
---|
| 47 | CREATE_FACTORY(SpaceShip, CL_SPACE_SHIP); |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * creates the controlable Spaceship |
---|
| 51 | */ |
---|
| 52 | SpaceShip::SpaceShip() |
---|
| 53 | { |
---|
| 54 | this->init(); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * destructs the spaceship, deletes alocated memory |
---|
| 59 | */ |
---|
| 60 | SpaceShip::~SpaceShip () |
---|
| 61 | { |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * loads a Spaceships information from a specified file. |
---|
| 66 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
| 67 | */ |
---|
| 68 | SpaceShip::SpaceShip(const char* fileName) |
---|
| 69 | { |
---|
| 70 | this->init(); |
---|
| 71 | TiXmlDocument doc(fileName); |
---|
| 72 | |
---|
| 73 | if(!doc.LoadFile()) |
---|
| 74 | { |
---|
| 75 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName); |
---|
| 76 | return; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | this->loadParams(doc.RootElement()); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * creates a new Spaceship from Xml Data |
---|
| 84 | * @param root the xml element containing spaceship data |
---|
| 85 | |
---|
| 86 | @todo add more parameters to load |
---|
| 87 | */ |
---|
| 88 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
| 89 | { |
---|
| 90 | this->init(); |
---|
| 91 | if (root != NULL) |
---|
| 92 | this->loadParams(root); |
---|
| 93 | |
---|
| 94 | //weapons: |
---|
| 95 | Weapon* wpRight = new TestGun(0); |
---|
| 96 | wpRight->setName("testGun Right"); |
---|
| 97 | Weapon* wpLeft = new TestGun(1); |
---|
| 98 | wpLeft->setName("testGun Left"); |
---|
[5982] | 99 | Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON)); |
---|
[5907] | 100 | |
---|
| 101 | cannon->setName("BFG"); |
---|
| 102 | |
---|
| 103 | this->getWeaponManager()->addWeapon(wpLeft, 1, 0); |
---|
| 104 | this->getWeaponManager()->addWeapon(wpRight,1 ,1); |
---|
| 105 | this->getWeaponManager()->addWeapon(cannon, 0, 6); |
---|
| 106 | |
---|
| 107 | //this->getWeaponManager()->addWeapon(turret, 3, 0); |
---|
| 108 | |
---|
| 109 | this->getWeaponManager()->changeWeaponConfig(1); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * initializes a Spaceship |
---|
| 115 | */ |
---|
| 116 | void SpaceShip::init() |
---|
| 117 | { |
---|
| 118 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 119 | this->setClassID(CL_SPACE_SHIP, "SpaceShip"); |
---|
| 120 | |
---|
| 121 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
| 122 | |
---|
[6341] | 123 | // EventHandler::getInstance()->grabEvents(true); |
---|
[5907] | 124 | |
---|
[5978] | 125 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; |
---|
[5907] | 126 | bFire = false; |
---|
[5978] | 127 | xMouse = yMouse = 0; |
---|
| 128 | mouseSensitivity = 0.001; |
---|
[6034] | 129 | airViscosity = 1.0; |
---|
[5978] | 130 | cycle = 0.0; |
---|
[5907] | 131 | |
---|
[5982] | 132 | |
---|
[5907] | 133 | travelSpeed = 15.0; |
---|
| 134 | this->velocity = Vector(0.0,0.0,0.0); |
---|
[6162] | 135 | this->mouseDir = this->getAbsDir(); |
---|
[5907] | 136 | |
---|
[6306] | 137 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 138 | // button->show(); |
---|
| 139 | // button->setLabel("orxonox"); |
---|
| 140 | // button->setBindNode(this); |
---|
| 141 | // GLGuiBar* bar = new GLGuiBar(); |
---|
| 142 | // bar->show(); |
---|
| 143 | // bar->setValue(7.0); |
---|
| 144 | // bar->setMaximum(10); |
---|
| 145 | // bar->setSize2D( 20, 100); |
---|
| 146 | // bar->setAbsCoor2D( 10, 200); |
---|
[6300] | 147 | |
---|
[5907] | 148 | //add events to the eventlist |
---|
[5978] | 149 | registerEvent(SDLK_w); |
---|
| 150 | registerEvent(SDLK_s); |
---|
| 151 | registerEvent(SDLK_a); |
---|
| 152 | registerEvent(SDLK_d); |
---|
| 153 | registerEvent(SDLK_q); |
---|
| 154 | registerEvent(SDLK_e); |
---|
[5907] | 155 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 156 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 157 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 158 | registerEvent(SDLK_PAGEUP); |
---|
| 159 | registerEvent(SDLK_PAGEDOWN); |
---|
[5978] | 160 | registerEvent(EV_MOUSE_MOTION); |
---|
[5907] | 161 | |
---|
| 162 | this->getWeaponManager()->setSlotCount(7); |
---|
| 163 | |
---|
| 164 | this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 165 | this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 166 | |
---|
| 167 | this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 168 | this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 169 | |
---|
| 170 | this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 171 | this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 172 | |
---|
| 173 | this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 174 | this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 175 | |
---|
| 176 | this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 177 | this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 178 | |
---|
| 179 | this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 180 | this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
| 181 | // |
---|
| 182 | this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0)); |
---|
| 183 | this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 184 | // |
---|
| 185 | // this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 186 | // this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 187 | // |
---|
| 188 | // this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 189 | // this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
| 190 | |
---|
[6162] | 191 | this->getWeaponManager()->getFixedTarget()->setParent(this); |
---|
| 192 | this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0); |
---|
| 193 | |
---|
[6222] | 194 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
[5907] | 195 | } |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 199 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 200 | */ |
---|
| 201 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 202 | { |
---|
| 203 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | |
---|
[6222] | 207 | void SpaceShip::enter() |
---|
| 208 | { |
---|
| 209 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true); |
---|
[6241] | 210 | this->attachCamera(); |
---|
[6222] | 211 | |
---|
| 212 | |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | void SpaceShip::leave() |
---|
| 216 | { |
---|
| 217 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
[6241] | 218 | this->detachCamera(); |
---|
[6222] | 219 | |
---|
| 220 | |
---|
| 221 | } |
---|
| 222 | |
---|
[5907] | 223 | /** |
---|
| 224 | * adds a weapon to the weapon list of the spaceship |
---|
| 225 | * @param weapon to add |
---|
| 226 | */ |
---|
| 227 | void SpaceShip::addWeapon(Weapon* weapon) |
---|
| 228 | { |
---|
| 229 | this->getWeaponManager()->addWeapon(weapon); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | /** |
---|
| 234 | * removes a weapon from the spaceship |
---|
| 235 | * @param weapon to remove |
---|
| 236 | */ |
---|
| 237 | void SpaceShip::removeWeapon(Weapon* weapon) |
---|
| 238 | { |
---|
| 239 | this->getWeaponManager()->removeWeapon(weapon); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | /** |
---|
| 243 | * effect that occurs after the SpaceShip is spawned |
---|
| 244 | */ |
---|
| 245 | void SpaceShip::postSpawn () |
---|
| 246 | { |
---|
| 247 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | /** |
---|
| 251 | * the action occuring if the spaceship left the game |
---|
| 252 | */ |
---|
| 253 | void SpaceShip::leftWorld () |
---|
| 254 | {} |
---|
| 255 | |
---|
| 256 | WorldEntity* ref = NULL; |
---|
| 257 | /** |
---|
| 258 | * this function is called, when two entities collide |
---|
| 259 | * @param entity: the world entity with whom it collides |
---|
| 260 | * |
---|
| 261 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 262 | */ |
---|
| 263 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 264 | { |
---|
| 265 | if (entity->isA(CL_TURRET_POWER_UP) && entity != ref) |
---|
| 266 | { |
---|
| 267 | this->ADDWEAPON(); |
---|
| 268 | ref = entity; |
---|
| 269 | } |
---|
| 270 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | /** |
---|
| 274 | * draws the spaceship after transforming it. |
---|
| 275 | */ |
---|
| 276 | void SpaceShip::draw () const |
---|
| 277 | { |
---|
[6281] | 278 | WorldEntity::draw(); |
---|
[5907] | 279 | this->getWeaponManager()->draw(); |
---|
| 280 | |
---|
| 281 | //this->debug(0); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
| 285 | * the function called for each passing timeSnap |
---|
| 286 | * @param time The timespan passed since last update |
---|
| 287 | */ |
---|
| 288 | void SpaceShip::tick (float time) |
---|
| 289 | { |
---|
[6034] | 290 | |
---|
[5907] | 291 | // spaceship controlled movement |
---|
| 292 | this->calculateVelocity(time); |
---|
| 293 | |
---|
| 294 | Vector move = (velocity)*time; |
---|
| 295 | |
---|
[6034] | 296 | //orient the velocity in the direction of the spaceship. |
---|
| 297 | travelSpeed = velocity.len(); |
---|
| 298 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
| 299 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
[6222] | 300 | |
---|
[6162] | 301 | //orient the spaceship in direction of the mouse |
---|
[6241] | 302 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*3.0); |
---|
| 303 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
[6162] | 304 | this->setAbsDir( rotQuat); |
---|
| 305 | //this->setAbsDirSoft(mouseDir,5); |
---|
[6222] | 306 | |
---|
[5978] | 307 | // this is the air friction (necessary for a smooth control) |
---|
| 308 | if(velocity.len() != 0) velocity -= velocity*0.01; |
---|
[5982] | 309 | |
---|
[6034] | 310 | //hoover effect |
---|
| 311 | cycle += time; |
---|
[5978] | 312 | this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
[5982] | 313 | |
---|
[6034] | 314 | //readjust |
---|
| 315 | // if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 316 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 317 | |
---|
[5978] | 318 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
[5907] | 319 | |
---|
| 320 | this->shiftCoor (move); |
---|
| 321 | |
---|
| 322 | this->getWeaponManager()->tick(time); |
---|
| 323 | // weapon system manipulation |
---|
| 324 | this->weaponAction(); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | /** |
---|
| 328 | * calculate the velocity |
---|
| 329 | * @param time the timeslice since the last frame |
---|
| 330 | */ |
---|
| 331 | void SpaceShip::calculateVelocity (float time) |
---|
| 332 | { |
---|
| 333 | Vector accel(0.0, 0.0, 0.0); |
---|
[6162] | 334 | /* |
---|
| 335 | Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter |
---|
| 336 | */ |
---|
[5907] | 337 | //float rotVal = 0.0; |
---|
[5912] | 338 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
[5907] | 339 | /* calculate the direction in which the craft is heading */ |
---|
| 340 | |
---|
[6222] | 341 | Plane plane(Vector(0,1,0), Vector(0,0,0)); |
---|
| 342 | |
---|
[5907] | 343 | if( this->bUp ) |
---|
| 344 | { |
---|
[5978] | 345 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 346 | accel += (this->getAbsDirX())*2; |
---|
[6222] | 347 | |
---|
[6162] | 348 | /* Heli-Steuerung |
---|
| 349 | accel += (this->getAbsDirX()*2; |
---|
| 350 | if( |
---|
| 351 | */ |
---|
[5907] | 352 | } |
---|
| 353 | |
---|
| 354 | if( this->bDown ) |
---|
[5908] | 355 | { |
---|
[5978] | 356 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 357 | accel -= (this->getAbsDirX())*2; |
---|
[5907] | 358 | } |
---|
| 359 | |
---|
[6034] | 360 | if( this->bLeft/* > -this->getRelCoor().z*2*/) |
---|
[5907] | 361 | { |
---|
[5912] | 362 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 363 | // accel -= rightDirection; |
---|
[5908] | 364 | //velocityDir.normalize(); |
---|
[5907] | 365 | //rot +=Vector(1,0,0); |
---|
| 366 | //rotVal -= .4; |
---|
| 367 | } |
---|
| 368 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 369 | { |
---|
[5912] | 370 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
| 371 | |
---|
| 372 | // accel += rightDirection; |
---|
[5908] | 373 | //velocityDir.normalize(); |
---|
[5907] | 374 | //rot += Vector(1,0,0); |
---|
| 375 | //rotVal += .4; |
---|
| 376 | } |
---|
[5982] | 377 | |
---|
[6034] | 378 | |
---|
[5978] | 379 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 380 | { |
---|
[6162] | 381 | mouseDir *= Quaternion(-time, Vector(1,0,0)); |
---|
[5978] | 382 | // accel -= rightDirection; |
---|
| 383 | //velocityDir.normalize(); |
---|
| 384 | //rot +=Vector(1,0,0); |
---|
| 385 | //rotVal -= .4; |
---|
| 386 | } |
---|
| 387 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 388 | { |
---|
[6162] | 389 | mouseDir *= Quaternion(time, Vector(1,0,0)); |
---|
[5978] | 390 | |
---|
| 391 | // accel += rightDirection; |
---|
| 392 | //velocityDir.normalize(); |
---|
| 393 | //rot += Vector(1,0,0); |
---|
| 394 | //rotVal += .4; |
---|
| 395 | } |
---|
[5907] | 396 | if (this->bAscend ) |
---|
| 397 | { |
---|
[5912] | 398 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 399 | |
---|
| 400 | // accel += upDirection; |
---|
[5908] | 401 | //velocityDir.normalize(); |
---|
[5907] | 402 | //rot += Vector(0,0,1); |
---|
| 403 | //rotVal += .4; |
---|
| 404 | } |
---|
| 405 | if (this->bDescend ) |
---|
| 406 | { |
---|
[5912] | 407 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 408 | |
---|
| 409 | // accel -= upDirection; |
---|
[5908] | 410 | //velocityDir.normalize(); |
---|
[5907] | 411 | //rot += Vector(0,0,1); |
---|
| 412 | //rotVal -= .4; |
---|
| 413 | } |
---|
| 414 | |
---|
[5978] | 415 | velocity += accel; |
---|
[5907] | 416 | //rot.normalize(); |
---|
| 417 | //this->setRelDirSoft(Quaternion(rotVal, rot), 5); |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | /** |
---|
| 421 | * weapon manipulation by the player |
---|
| 422 | */ |
---|
| 423 | void SpaceShip::weaponAction() |
---|
| 424 | { |
---|
| 425 | if( this->bFire) |
---|
| 426 | { |
---|
| 427 | this->getWeaponManager()->fire(); |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | /** |
---|
| 432 | * @todo switch statement ?? |
---|
| 433 | */ |
---|
| 434 | void SpaceShip::process(const Event &event) |
---|
| 435 | { |
---|
[5982] | 436 | |
---|
| 437 | |
---|
[5978] | 438 | if( event.type == SDLK_a) |
---|
| 439 | this->bRollL = event.bPressed; |
---|
| 440 | else if( event.type == SDLK_d) |
---|
| 441 | this->bRollR = event.bPressed; |
---|
[5907] | 442 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
| 443 | this->bFire = event.bPressed; |
---|
| 444 | else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed) |
---|
| 445 | this->getWeaponManager()->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange; |
---|
| 446 | else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) |
---|
| 447 | this->getWeaponManager()->previousWeaponConfig(); |
---|
[5978] | 448 | else if( event.type == SDLK_w) |
---|
| 449 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
| 450 | else if( event.type == SDLK_s) |
---|
| 451 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
| 452 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 453 | { |
---|
| 454 | this->xMouse = event.xRel; |
---|
| 455 | this->yMouse = event.yRel; |
---|
[6162] | 456 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); |
---|
[6241] | 457 | // if( xMouse*xMouse + yMouse*yMouse < 0.9) |
---|
| 458 | //this->setAbsDir(mouseDir); |
---|
[5978] | 459 | } |
---|
[5907] | 460 | } |
---|
| 461 | |
---|
[6243] | 462 | /** |
---|
| 463 | * |
---|
| 464 | */ |
---|
| 465 | bool SpaceShip::pickup(PowerUp* powerUp) |
---|
| 466 | { |
---|
| 467 | if(powerUp->isA(CL_WEAPON_POWER_UP)) { |
---|
| 468 | Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon(); |
---|
| 469 | WeaponManager* manager = this->getWeaponManager(); |
---|
| 470 | int slot = manager->getNextFreeSlot(0, weapon->getCapability()); |
---|
| 471 | if(slot >= 0) { |
---|
| 472 | manager->addWeapon(weapon, 0, slot); |
---|
| 473 | return true; |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | else if(powerUp->isA(CL_PARAM_POWER_UP)) { |
---|
| 477 | ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp); |
---|
| 478 | switch(ppu->getType()) { |
---|
| 479 | case PARAM_SHIELD: |
---|
| 480 | break; |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | return false; |
---|
| 484 | } |
---|
| 485 | |
---|
[5907] | 486 | #include "weapons/aiming_turret.h" |
---|
| 487 | // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG |
---|
| 488 | void SpaceShip::ADDWEAPON() |
---|
| 489 | { |
---|
| 490 | Weapon* turret = NULL; |
---|
| 491 | |
---|
[6306] | 492 | if ((float)rand()/RAND_MAX < .9) |
---|
[5907] | 493 | { |
---|
| 494 | //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET)) |
---|
| 495 | { |
---|
| 496 | turret = new Turret(); |
---|
| 497 | this->getWeaponManager()->addWeapon(turret, 2); |
---|
| 498 | this->getWeaponManager()->changeWeaponConfig(2); |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | else |
---|
| 502 | { |
---|
| 503 | //if (this->getWeaponManager()->hasFreeSlot(3)) |
---|
| 504 | { |
---|
| 505 | turret = new AimingTurret(); |
---|
| 506 | this->getWeaponManager()->addWeapon(turret, 3); |
---|
| 507 | |
---|
| 508 | this->getWeaponManager()->changeWeaponConfig(3); |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | if(turret != NULL) |
---|
| 513 | { |
---|
| 514 | turret->setName("Turret"); |
---|
| 515 | turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1); |
---|
| 516 | } |
---|
| 517 | } |
---|