[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" |
---|
[9970] | 25 | #include "weapons/light_blaster.h" |
---|
| 26 | #include "weapons/medium_blaster.h" |
---|
| 27 | #include "weapons/heavy_blaster.h" |
---|
[10004] | 28 | #include "weapons/swarm_missile.h" |
---|
[9970] | 29 | #include "weapons/boomerang_gun.h" |
---|
[6868] | 30 | #include "weapons/turret.h" |
---|
| 31 | #include "weapons/cannon.h" |
---|
| 32 | |
---|
[9869] | 33 | #include "particles/dot_emitter.h" |
---|
| 34 | #include "particles/sprite_particles.h" |
---|
[6868] | 35 | |
---|
[7193] | 36 | #include "util/loading/factory.h" |
---|
[6868] | 37 | #include "key_mapper.h" |
---|
| 38 | |
---|
| 39 | #include "network_game_manager.h" |
---|
[8708] | 40 | #include "shared_network_data.h" |
---|
[6868] | 41 | |
---|
| 42 | #include "power_ups/weapon_power_up.h" |
---|
| 43 | #include "power_ups/param_power_up.h" |
---|
| 44 | |
---|
| 45 | #include "graphics_engine.h" |
---|
| 46 | |
---|
| 47 | #include "plane.h" |
---|
| 48 | |
---|
| 49 | #include "state.h" |
---|
| 50 | #include "player.h" |
---|
| 51 | |
---|
[7193] | 52 | #include "util/loading/load_param.h" |
---|
[10020] | 53 | #include "time.h" |
---|
[6868] | 54 | |
---|
[7056] | 55 | |
---|
[6868] | 56 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
| 57 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
| 58 | |
---|
| 59 | |
---|
[9869] | 60 | #include "class_id_DEPRECATED.h" |
---|
| 61 | ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP); |
---|
| 62 | CREATE_FACTORY(SpaceShip); |
---|
[9406] | 63 | |
---|
[9061] | 64 | #include "script_class.h" |
---|
[9869] | 65 | CREATE_SCRIPTABLE_CLASS(SpaceShip, |
---|
| 66 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
| 67 | ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire)) |
---|
| 68 | ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2)) |
---|
| 69 | ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName)) |
---|
| 70 | ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide)) |
---|
| 71 | ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide)) |
---|
| 72 | //Coordinates |
---|
| 73 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
| 74 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
| 75 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
| 76 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
[10017] | 77 | //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed)) |
---|
[9061] | 78 | ); |
---|
[6868] | 79 | |
---|
| 80 | /** |
---|
| 81 | * destructs the spaceship, deletes alocated memory |
---|
| 82 | */ |
---|
| 83 | SpaceShip::~SpaceShip () |
---|
| 84 | { |
---|
[6986] | 85 | this->setPlayer(NULL); |
---|
[6868] | 86 | } |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | * loads a Spaceships information from a specified file. |
---|
| 90 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
| 91 | */ |
---|
[7221] | 92 | SpaceShip::SpaceShip(const std::string& fileName) |
---|
[10019] | 93 | : secWeaponMan(this) //, |
---|
| 94 | //supportedPlaymodes(Playable::Vertical) , |
---|
| 95 | //playmode(Playable::Vertical) |
---|
[6868] | 96 | { |
---|
| 97 | this->init(); |
---|
| 98 | TiXmlDocument doc(fileName); |
---|
| 99 | |
---|
| 100 | if(!doc.LoadFile()) |
---|
| 101 | { |
---|
[7221] | 102 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); |
---|
[6868] | 103 | return; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | this->loadParams(doc.RootElement()); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * creates a new Spaceship from Xml Data |
---|
| 111 | * @param root the xml element containing spaceship data |
---|
| 112 | |
---|
| 113 | @todo add more parameters to load |
---|
| 114 | */ |
---|
| 115 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
[10019] | 116 | : secWeaponMan(this) //, |
---|
| 117 | //supportedPlaymodes(Playable::Vertical) , |
---|
| 118 | //playmode(Playable::Vertical) |
---|
[6868] | 119 | { |
---|
| 120 | this->init(); |
---|
| 121 | if (root != NULL) |
---|
| 122 | this->loadParams(root); |
---|
| 123 | |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * initializes a Spaceship |
---|
| 129 | */ |
---|
| 130 | void SpaceShip::init() |
---|
| 131 | { |
---|
[9998] | 132 | |
---|
[10019] | 133 | this->setSupportedPlaymodes(Playable::Vertical); |
---|
| 134 | |
---|
[9869] | 135 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 136 | this->registerObject(this, SpaceShip::_objectList); |
---|
[6868] | 137 | |
---|
| 138 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
| 139 | |
---|
[9998] | 140 | secWeaponMan.showCrosshair(); |
---|
| 141 | |
---|
[6868] | 142 | //weapons: |
---|
[9998] | 143 | |
---|
[9996] | 144 | Weapon* wpRight1 = new LightBlaster (); |
---|
| 145 | wpRight1->setName("Light Blaster Right"); |
---|
| 146 | Weapon* wpLeft1 = new LightBlaster (); |
---|
| 147 | wpLeft1->setName("Medium Blaster Left"); |
---|
[6868] | 148 | |
---|
[9996] | 149 | Weapon* wpRight2 = new MediumBlaster (); |
---|
[9998] | 150 | wpRight2->setName("Medium Blaster Right"); |
---|
[9996] | 151 | Weapon* wpLeft2 = new MediumBlaster (); |
---|
| 152 | wpLeft2->setName("Medium Blaster Left"); |
---|
| 153 | |
---|
| 154 | Weapon* wpRight3 = new HeavyBlaster (); |
---|
| 155 | wpRight3->setName("Heavy Blaster Right"); |
---|
| 156 | Weapon* wpLeft3 = new HeavyBlaster (); |
---|
| 157 | wpLeft3->setName("Heavy Blaster Left"); |
---|
| 158 | |
---|
[10004] | 159 | Weapon* cannon = new SwarmMissile(); |
---|
| 160 | cannon->setName("Swarm Missile"); |
---|
| 161 | |
---|
[6868] | 162 | |
---|
[9961] | 163 | |
---|
[10016] | 164 | this->weaponMan.addWeapon( wpLeft1, 0, 0); |
---|
| 165 | this->weaponMan.addWeapon( wpRight1, 0, 1); |
---|
| 166 | this->weaponMan.addWeapon( wpLeft2, 0, 2); |
---|
| 167 | this->weaponMan.addWeapon( wpRight2, 0, 3); |
---|
[9996] | 168 | this->weaponMan.addWeapon( wpLeft3, 0, 4); |
---|
| 169 | this->weaponMan.addWeapon( wpRight3, 0, 5); |
---|
[9998] | 170 | |
---|
[9965] | 171 | this->secWeaponMan.addWeapon( cannon, 0, 0); |
---|
[9961] | 172 | |
---|
[9965] | 173 | this->weaponMan.changeWeaponConfig(0); |
---|
[9961] | 174 | |
---|
[9996] | 175 | wpRight1->requestAction(WA_ACTIVATE); |
---|
| 176 | wpLeft1->requestAction(WA_ACTIVATE); |
---|
| 177 | wpRight2->requestAction(WA_ACTIVATE); |
---|
| 178 | wpLeft2->requestAction(WA_ACTIVATE); |
---|
| 179 | wpRight3->requestAction(WA_ACTIVATE); |
---|
| 180 | wpLeft3->requestAction(WA_ACTIVATE); |
---|
[9998] | 181 | |
---|
[9961] | 182 | cannon->requestAction(WA_ACTIVATE); |
---|
[9965] | 183 | |
---|
[9970] | 184 | curWeaponPrimary = 0; |
---|
| 185 | curWeaponSecondary = 0; |
---|
[9965] | 186 | |
---|
| 187 | Playable::weaponConfigChanged(); |
---|
| 188 | |
---|
[9970] | 189 | reactorOutput = 10; |
---|
[9965] | 190 | |
---|
[9970] | 191 | weaponEnergyRegen = 10; // 10 einheiten pro Sekunde |
---|
| 192 | engineSpeedBase = 5; |
---|
| 193 | shieldRegen = 2; |
---|
| 194 | |
---|
| 195 | shieldEnergyShare = 0.3; |
---|
| 196 | weaponEnergyShare = 0.3; |
---|
| 197 | engineEnergyShare = 0.4; |
---|
| 198 | |
---|
| 199 | shieldCur = 20; |
---|
| 200 | shieldMax = 100; |
---|
[10020] | 201 | shieldTH = .2* shieldMax; // shield power must be 20% before shield kicks in again |
---|
[9970] | 202 | |
---|
[10020] | 203 | electronicCur = 10; |
---|
| 204 | electronicMax = 50; |
---|
| 205 | electronicRegen = 3; |
---|
| 206 | electronicTH = .7 * electronicMax; // 30% of eDamage can be handled by the ship |
---|
| 207 | |
---|
[9961] | 208 | /* |
---|
[6868] | 209 | this->addWeapon(wpLeft, 1, 0); |
---|
| 210 | this->addWeapon(wpRight,1 ,1); |
---|
[7087] | 211 | //this->addWeapon(cannon, 0, 6); |
---|
[6868] | 212 | |
---|
[7337] | 213 | this->getWeaponManager().changeWeaponConfig(1); |
---|
[9961] | 214 | */ |
---|
[6868] | 215 | |
---|
[9970] | 216 | this->loadModel("models/ships/mantawing.obj"); |
---|
[10017] | 217 | //this->setVisibiliy(false); |
---|
[6868] | 218 | |
---|
[10017] | 219 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
| 220 | |
---|
| 221 | /* |
---|
[6868] | 222 | xMouse = yMouse = 0; |
---|
| 223 | yInvert = 1; |
---|
| 224 | mouseSensitivity = 0.001; |
---|
[7122] | 225 | airViscosity = 0.9; |
---|
[6868] | 226 | controlVelocityX = 25; |
---|
| 227 | controlVelocityY = 150; |
---|
| 228 | shipInertia = 1.5; |
---|
[10017] | 229 | */ |
---|
[9869] | 230 | // cycle = 0.0; |
---|
[6868] | 231 | |
---|
[9970] | 232 | this->setHealthMax(shieldMax); |
---|
| 233 | this->setHealth(shieldCur); |
---|
[6868] | 234 | |
---|
[10017] | 235 | this->travelNode = new PNode(); |
---|
| 236 | |
---|
| 237 | // camera - issue |
---|
| 238 | //this->cameraNode = State::getCameraNode(); |
---|
| 239 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 240 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
| 241 | |
---|
| 242 | /* |
---|
[6868] | 243 | this->velocity = this->getAbsDirX()*travelSpeed; |
---|
| 244 | this->mouseDir = this->getAbsDir(); |
---|
| 245 | this->pitchDir = this->getAbsDir(); |
---|
[10017] | 246 | */ |
---|
[6868] | 247 | |
---|
[9965] | 248 | |
---|
[9869] | 249 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 250 | // button->show(); |
---|
| 251 | // button->setLabel("orxonox"); |
---|
| 252 | // button->setBindNode(this); |
---|
| 253 | // GLGuiBar* bar = new GLGuiBar(); |
---|
| 254 | // bar->show(); |
---|
| 255 | // bar->setValue(7.0); |
---|
| 256 | // bar->setMaximum(10); |
---|
| 257 | // bar->setSize2D( 20, 100); |
---|
| 258 | // bar->setAbsCoor2D( 10, 200); |
---|
[6868] | 259 | |
---|
| 260 | //add events to the eventlist |
---|
[6997] | 261 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 262 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
[6868] | 263 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 264 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 265 | //registerEvent(SDLK_q); |
---|
| 266 | //registerEvent(SDLK_e); |
---|
| 267 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
[9958] | 268 | registerEvent(KeyMapper::PEV_FIRE2); // Added for secondary weapon support |
---|
[6868] | 269 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 270 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 271 | //registerEvent(SDLK_PAGEUP); |
---|
| 272 | //registerEvent(SDLK_PAGEDOWN); |
---|
| 273 | registerEvent(EV_MOUSE_MOTION); |
---|
| 274 | |
---|
[9965] | 275 | this->weaponMan.setSlotCount(6); |
---|
[6868] | 276 | |
---|
[9965] | 277 | this->weaponMan.setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 278 | this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 279 | |
---|
[9965] | 280 | this->weaponMan.setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 281 | this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 282 | |
---|
[9965] | 283 | this->weaponMan.setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 284 | this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 285 | |
---|
[9965] | 286 | this->weaponMan.setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 287 | this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 288 | |
---|
[9965] | 289 | this->weaponMan.setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 290 | this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
[6868] | 291 | |
---|
[9965] | 292 | this->weaponMan.setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 293 | this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[9961] | 294 | |
---|
| 295 | this->secWeaponMan.setSlotCount(6); |
---|
| 296 | |
---|
[10004] | 297 | this->secWeaponMan.setSlotPosition(0, Vector(1.5, -1, 0)); |
---|
[9961] | 298 | this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 299 | |
---|
| 300 | this->secWeaponMan.setSlotPosition(1, Vector(2.6, .1, 3.0)); |
---|
| 301 | this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 302 | |
---|
| 303 | this->secWeaponMan.setSlotPosition(2, Vector(1.5, .5, -.5)); |
---|
| 304 | this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 305 | |
---|
| 306 | this->secWeaponMan.setSlotPosition(3, Vector(1.5, .5, .5)); |
---|
| 307 | this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 308 | |
---|
| 309 | this->secWeaponMan.setSlotPosition(4, Vector(1.5, -.5, .5)); |
---|
| 310 | this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 311 | |
---|
| 312 | this->secWeaponMan.setSlotPosition(5, Vector(1.5, -.5, -.5)); |
---|
| 313 | this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[9965] | 314 | |
---|
[9869] | 315 | // |
---|
| 316 | // this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 317 | // this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 318 | // |
---|
| 319 | // this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 320 | // this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
[6868] | 321 | |
---|
[9965] | 322 | this->weaponMan.getFixedTarget()->setParent(this); |
---|
| 323 | this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
[10004] | 324 | |
---|
[9998] | 325 | |
---|
[9961] | 326 | this->secWeaponMan.getFixedTarget()->setParent(this); |
---|
| 327 | this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
[10004] | 328 | this->secWeaponMan.setRotationSpeed(0); |
---|
[6868] | 329 | |
---|
[9965] | 330 | dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false); |
---|
[9961] | 331 | |
---|
[6868] | 332 | this->burstEmitter = new DotEmitter(200, 0.0, .01); |
---|
| 333 | this->burstEmitter->setParent(this); |
---|
| 334 | this->burstEmitter->setRelCoor(-1, .5, 0); |
---|
| 335 | this->burstEmitter->setName("SpaceShip_Burst_emitter"); |
---|
| 336 | |
---|
| 337 | this->burstSystem = new SpriteParticles(1000); |
---|
| 338 | this->burstSystem->addEmitter(this->burstEmitter); |
---|
| 339 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
| 340 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 341 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
| 342 | this->burstSystem->setRadius(0.0, 1.0); |
---|
| 343 | this->burstSystem->setRadius(0.05, 1.0); |
---|
| 344 | this->burstSystem->setRadius(.5, .8); |
---|
| 345 | this->burstSystem->setRadius(1.0, 0); |
---|
| 346 | this->burstSystem->setColor(0.0, .7,.7,1,.7); |
---|
| 347 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
| 348 | this->burstSystem->setColor(0.5, .5,.5,.8,.8); |
---|
| 349 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
[9008] | 350 | |
---|
[10017] | 351 | /* |
---|
[7954] | 352 | registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); |
---|
| 353 | registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) ); |
---|
| 354 | registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) ); |
---|
| 355 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 356 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 357 | registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); |
---|
| 358 | registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); |
---|
| 359 | registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) ); |
---|
| 360 | registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) ); |
---|
[10017] | 361 | */ |
---|
| 362 | |
---|
| 363 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
| 364 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
| 365 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 366 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 367 | registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); |
---|
| 368 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
| 369 | |
---|
| 370 | registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); |
---|
| 371 | |
---|
| 372 | //this->airFriction = 0.5f; |
---|
[10019] | 373 | this->travelDistancePlus = Vector2D(38.0, 43.0); |
---|
| 374 | this->travelDistanceMinus = Vector2D(-38.0, -43.0); |
---|
| 375 | this->travelSpeed = 80; |
---|
[10017] | 376 | this->cameraSpeed = 40; |
---|
[10019] | 377 | this->cameraLook = 0.0f; |
---|
| 378 | this->acceleration = 120.0f; |
---|
| 379 | //this->airFriction = 0.0f; |
---|
[10017] | 380 | |
---|
[10020] | 381 | srand(time(0)); //initaialize RNG |
---|
| 382 | |
---|
[10017] | 383 | this->travelNode->debugDraw(); |
---|
[6868] | 384 | } |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | /** |
---|
| 388 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 389 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 390 | */ |
---|
| 391 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 392 | { |
---|
| 393 | Playable::loadParams(root); |
---|
| 394 | } |
---|
| 395 | |
---|
[10017] | 396 | void SpaceShip::setPlayDirection(const Quaternion& rot, float speed) |
---|
[7056] | 397 | { |
---|
[10017] | 398 | this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
[7056] | 399 | } |
---|
[6868] | 400 | |
---|
[10017] | 401 | void SpaceShip::setTravelSpeed(float travelSpeed) |
---|
| 402 | { |
---|
| 403 | this->travelSpeed = travelSpeed; |
---|
| 404 | } |
---|
[7056] | 405 | |
---|
[10017] | 406 | /* |
---|
| 407 | void SpaceShip::setTravelHeight(float travelHeight) |
---|
| 408 | { |
---|
| 409 | if (this->toTravelHeight == NULL) |
---|
| 410 | this->toTravelHeight = new float; |
---|
| 411 | *this->toTravelHeight = travelHeight; |
---|
| 412 | } |
---|
| 413 | */ |
---|
| 414 | |
---|
[10019] | 415 | /* |
---|
[10017] | 416 | void SpaceShip::setTravelDistance(const Vector2D& distance) |
---|
| 417 | { |
---|
| 418 | this->travelDistance = distance; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | void SpaceShip::setTravelDistance(float x, float y) |
---|
| 422 | { |
---|
| 423 | this->setTravelDistance(Vector2D(x, y)); |
---|
| 424 | } |
---|
[10019] | 425 | */ |
---|
[10017] | 426 | |
---|
| 427 | |
---|
| 428 | |
---|
[7085] | 429 | void SpaceShip::reset() |
---|
| 430 | { |
---|
[10017] | 431 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
[7056] | 432 | |
---|
[10017] | 433 | //xMouse = yMouse = 0; |
---|
[7085] | 434 | |
---|
| 435 | this->setHealth(80); |
---|
| 436 | this->velocity = Vector(0.0, 0.0, 0.0); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | |
---|
[6868] | 440 | void SpaceShip::enter() |
---|
| 441 | { |
---|
[10004] | 442 | this->secWeaponMan.showCrosshair(); |
---|
| 443 | //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true); |
---|
[10019] | 444 | if (!this->setPlaymode(Playable::Vertical)) |
---|
| 445 | std::cout << "playmode not supported"; |
---|
| 446 | //this->attachCamera(); |
---|
[6868] | 447 | } |
---|
| 448 | |
---|
| 449 | void SpaceShip::leave() |
---|
| 450 | { |
---|
[10004] | 451 | this->secWeaponMan.hideCrosshair(); |
---|
| 452 | //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false); |
---|
[10019] | 453 | //this->detachCamera(); |
---|
[6868] | 454 | } |
---|
| 455 | |
---|
| 456 | |
---|
| 457 | /** |
---|
| 458 | * effect that occurs after the SpaceShip is spawned |
---|
| 459 | */ |
---|
| 460 | void SpaceShip::postSpawn () |
---|
| 461 | { |
---|
| 462 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | /** |
---|
| 466 | * the action occuring if the spaceship left the game |
---|
| 467 | */ |
---|
| 468 | void SpaceShip::leftWorld () |
---|
| 469 | {} |
---|
| 470 | |
---|
| 471 | WorldEntity* ref = NULL; |
---|
| 472 | /** |
---|
| 473 | * this function is called, when two entities collide |
---|
| 474 | * @param entity: the world entity with whom it collides |
---|
| 475 | * |
---|
| 476 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 477 | */ |
---|
| 478 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 479 | { |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | /** |
---|
| 483 | * draws the spaceship after transforming it. |
---|
| 484 | */ |
---|
| 485 | void SpaceShip::draw () const |
---|
| 486 | { |
---|
| 487 | WorldEntity::draw(); |
---|
| 488 | |
---|
| 489 | //this->debug(0); |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | /** |
---|
| 493 | * the function called for each passing timeSnap |
---|
| 494 | * @param time The timespan passed since last update |
---|
| 495 | */ |
---|
| 496 | void SpaceShip::tick (float time) |
---|
| 497 | { |
---|
[9961] | 498 | // Playable::tick(time);$ |
---|
[6868] | 499 | |
---|
[9961] | 500 | // Own Tick Setup, as a different fire routine is used on the weapon manager |
---|
[9965] | 501 | this->weaponMan.tick(time); |
---|
[9961] | 502 | this->secWeaponMan.tick(time); |
---|
| 503 | |
---|
[10020] | 504 | if( this->systemFailure() ) |
---|
| 505 | bFire = bSecFire = false; |
---|
| 506 | |
---|
[9965] | 507 | if( this->bFire) |
---|
[9961] | 508 | { |
---|
[9965] | 509 | this->weaponMan.fire(); |
---|
[9961] | 510 | } |
---|
| 511 | if( this->bSecFire) |
---|
| 512 | { |
---|
| 513 | this->secWeaponMan.fire(); |
---|
[9965] | 514 | this->bSecFire = !this->bSecFire; // FIXME This currently is needed to prevent "echo fires" of a second rocket after its cooldown has passed |
---|
[9961] | 515 | } |
---|
| 516 | |
---|
[9970] | 517 | |
---|
| 518 | // Shield Regeneration and other regular calculations on the ship |
---|
| 519 | this->regen(time); |
---|
| 520 | |
---|
| 521 | // Weapon Regeneration and other regular calculations on the ship |
---|
[9965] | 522 | this->weaponRegen(time); |
---|
| 523 | |
---|
[9970] | 524 | // current engine speed output |
---|
| 525 | this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare; |
---|
| 526 | |
---|
| 527 | |
---|
[10017] | 528 | /* |
---|
[8708] | 529 | if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) |
---|
[9869] | 530 | { |
---|
[6868] | 531 | if (xMouse > controlVelocityX) xMouse = controlVelocityX; |
---|
| 532 | else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; |
---|
| 533 | if (yMouse > controlVelocityY) yMouse = controlVelocityY; |
---|
| 534 | else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; |
---|
| 535 | |
---|
| 536 | pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); |
---|
| 537 | |
---|
| 538 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); |
---|
| 539 | xMouse = yMouse = 0; |
---|
[9869] | 540 | } |
---|
[10017] | 541 | */ |
---|
[6868] | 542 | |
---|
[9235] | 543 | // spaceship controlled movement fire(bool bF){ this->bFire = bF;} |
---|
[7954] | 544 | //if (this->getOwner() == this->getHostID()) |
---|
[6868] | 545 | |
---|
[10017] | 546 | //is->calculateVelocity(time); |
---|
[6959] | 547 | |
---|
[6868] | 548 | |
---|
[10017] | 549 | //vector move = velocity*time; |
---|
| 550 | |
---|
| 551 | /* |
---|
[6868] | 552 | //orient the velocity in the direction of the spaceship. |
---|
| 553 | travelSpeed = velocity.len(); |
---|
| 554 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
| 555 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
[10017] | 556 | */ |
---|
| 557 | this->movement(time); |
---|
| 558 | |
---|
| 559 | // TRYING TO FIX PNode. |
---|
| 560 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
---|
| 561 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
---|
| 562 | |
---|
[6868] | 563 | this->burstEmitter->setEmissionRate(travelSpeed); |
---|
| 564 | this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1); |
---|
| 565 | |
---|
| 566 | //orient the spaceship in direction of the mouse |
---|
[10017] | 567 | /* |
---|
[9869] | 568 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); |
---|
| 569 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
[6868] | 570 | this->setAbsDir( rotQuat); |
---|
[9869] | 571 | //this->setAbsDirSoft(mouseDir,5); |
---|
[10017] | 572 | */ |
---|
[6868] | 573 | |
---|
| 574 | // this is the air friction (necessary for a smooth control) |
---|
[10017] | 575 | /* |
---|
[6868] | 576 | if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; |
---|
| 577 | else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; |
---|
[10017] | 578 | */ |
---|
[6868] | 579 | |
---|
| 580 | //other physics (gravity) |
---|
| 581 | //if(travelSpeed < 120) |
---|
| 582 | //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; |
---|
| 583 | |
---|
| 584 | //hoover effect |
---|
| 585 | //cycle += time; |
---|
| 586 | //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
| 587 | |
---|
| 588 | //readjust |
---|
| 589 | //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 590 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 591 | |
---|
| 592 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
| 593 | |
---|
[10017] | 594 | /* |
---|
[6868] | 595 | this->shiftCoor(move); |
---|
[10017] | 596 | */ |
---|
[6868] | 597 | |
---|
[9869] | 598 | // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); |
---|
[6868] | 599 | |
---|
| 600 | } |
---|
| 601 | |
---|
[10017] | 602 | /* |
---|
[6868] | 603 | void SpaceShip::calculateVelocity (float time) |
---|
| 604 | { |
---|
| 605 | Vector accel(0.0, 0.0, 0.0); |
---|
[10017] | 606 | /* calculate the direction in which the craft is heading */ |
---|
[6868] | 607 | /* |
---|
| 608 | if( this->bUp ) |
---|
[9869] | 609 | { |
---|
| 610 | accel += (this->getAbsDirX())*acceleration; |
---|
[6868] | 611 | |
---|
[9869] | 612 | } |
---|
[6868] | 613 | |
---|
| 614 | if( this->bDown ) |
---|
[9869] | 615 | { |
---|
| 616 | accel -= (this->getAbsDirX())*0.5*acceleration; |
---|
[6868] | 617 | |
---|
[9869] | 618 | } |
---|
[6868] | 619 | |
---|
[10017] | 620 | if( this->bLeft) |
---|
[6868] | 621 | { |
---|
| 622 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 623 | } |
---|
[10017] | 624 | if( this->bRight) |
---|
[6868] | 625 | { |
---|
| 626 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | |
---|
[10017] | 630 | if( this->bRollL) |
---|
[6868] | 631 | { |
---|
| 632 | mouseDir *= Quaternion(-time*2, Vector(1,0,0)); |
---|
| 633 | } |
---|
[10017] | 634 | if( this->bRollR) |
---|
[6868] | 635 | { |
---|
| 636 | mouseDir *= Quaternion(time*2, Vector(1,0,0)); |
---|
| 637 | |
---|
| 638 | } |
---|
| 639 | if (this->bAscend ) |
---|
| 640 | { |
---|
| 641 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 642 | } |
---|
| 643 | if (this->bDescend ) |
---|
| 644 | { |
---|
| 645 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 646 | } |
---|
| 647 | |
---|
[6959] | 648 | velocity += accel*time*10; |
---|
[9961] | 649 | |
---|
[6868] | 650 | } |
---|
[10017] | 651 | */ |
---|
[6868] | 652 | |
---|
| 653 | /** |
---|
| 654 | * @todo switch statement ?? |
---|
| 655 | */ |
---|
| 656 | void SpaceShip::process(const Event &event) |
---|
| 657 | { |
---|
[9961] | 658 | //Playable::process(event); |
---|
[6868] | 659 | |
---|
| 660 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[10017] | 661 | this->bLeft = event.bPressed; |
---|
[6868] | 662 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[10017] | 663 | this->bRight = event.bPressed; |
---|
[6997] | 664 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[10017] | 665 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 666 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[10017] | 667 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[9961] | 668 | else if( event.type == KeyMapper::PEV_FIRE2) |
---|
| 669 | this->bSecFire = event.bPressed; |
---|
[9958] | 670 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
[9965] | 671 | this->bFire = event.bPressed; |
---|
[10017] | 672 | |
---|
| 673 | |
---|
| 674 | /* |
---|
[6868] | 675 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 676 | { |
---|
[9961] | 677 | |
---|
[6868] | 678 | this->xMouse += event.xRel; |
---|
| 679 | this->yMouse += event.yRel; |
---|
| 680 | } |
---|
[10017] | 681 | */ |
---|
[6868] | 682 | } |
---|
| 683 | |
---|
[9235] | 684 | void SpaceShip::destroy( WorldEntity* killer ) |
---|
[9008] | 685 | { |
---|
| 686 | PRINTF(0)("spaceship destroy\n"); |
---|
| 687 | } |
---|
[6868] | 688 | |
---|
[9008] | 689 | void SpaceShip::respawn( ) |
---|
| 690 | { |
---|
| 691 | toList( OM_PLAYERS ); |
---|
| 692 | } |
---|
[6868] | 693 | |
---|
| 694 | |
---|
[9957] | 695 | void SpaceShip::damage(float pDamage, float eDamage){ |
---|
[9950] | 696 | if( this->shieldActive) { |
---|
| 697 | if( this->shieldCur > pDamage) { |
---|
| 698 | this->shieldCur = this->shieldCur - pDamage; |
---|
| 699 | } |
---|
| 700 | else { // shield <= pDamage |
---|
[9987] | 701 | this->shieldCur -=pDamage; |
---|
| 702 | this->shieldActive = false; //shield collapses |
---|
[9950] | 703 | pDamage = pDamage - this->shieldCur; |
---|
| 704 | if( !this->shieldActive) { |
---|
[9957] | 705 | this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate |
---|
[9953] | 706 | this->electronicCur -= eDamage; |
---|
[9950] | 707 | } |
---|
| 708 | } |
---|
| 709 | } |
---|
| 710 | else { |
---|
| 711 | this->armorCur = this->armorCur - pDamage; |
---|
| 712 | this->electronicCur = this->electronicCur - eDamage; |
---|
| 713 | } |
---|
| 714 | if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ } |
---|
| 715 | } |
---|
| 716 | |
---|
[9987] | 717 | |
---|
[9957] | 718 | void SpaceShip::regen(float time){ |
---|
| 719 | float tmp; |
---|
[9963] | 720 | if (this->armorCur != this->armorMax || this->armorRegen != 0){ |
---|
| 721 | tmp = this->armorCur + this->armorRegen * time; |
---|
| 722 | if ( tmp > electronicMax) |
---|
| 723 | this->armorCur = this->armorMax; |
---|
| 724 | else |
---|
| 725 | this->armorCur = tmp; |
---|
| 726 | } |
---|
| 727 | if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){ |
---|
[9970] | 728 | tmp = this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time; |
---|
[9957] | 729 | if( tmp > shieldMax) |
---|
[9953] | 730 | this->shieldCur = this->shieldMax; |
---|
| 731 | else |
---|
[9957] | 732 | this->shieldCur = tmp; |
---|
| 733 | this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH); |
---|
[9953] | 734 | } |
---|
[9970] | 735 | |
---|
| 736 | this->setHealth( this->shieldCur); // FIXME currently just to test share system |
---|
| 737 | |
---|
[9963] | 738 | if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){ |
---|
[9957] | 739 | tmp = this->electronicCur + this->electronicRegen * time; |
---|
| 740 | if ( tmp > electronicMax) |
---|
[9953] | 741 | this->electronicCur = this->electronicMax; |
---|
| 742 | else |
---|
[9957] | 743 | this->electronicCur = tmp; |
---|
[9953] | 744 | } |
---|
[9950] | 745 | } |
---|
[9965] | 746 | |
---|
[9987] | 747 | |
---|
[9965] | 748 | /** |
---|
| 749 | * Weapon regeneration |
---|
| 750 | * does not use any reactor capacity, as it wouldn't work in a consistent way. |
---|
| 751 | */ |
---|
| 752 | void SpaceShip::weaponRegen(float time) |
---|
| 753 | { |
---|
| 754 | float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time; |
---|
| 755 | Weapon* weapon; |
---|
[9987] | 756 | for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) |
---|
[9965] | 757 | { |
---|
| 758 | weapon = this->weaponMan.getWeapon(i); |
---|
| 759 | if( weapon != NULL && weapon->isActive()) |
---|
| 760 | { |
---|
| 761 | weapon->increaseEnergy( energy); |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | } |
---|
| 765 | // weaponMan.increaseAmmunition( weapon, energy); |
---|
| 766 | } |
---|
[9975] | 767 | |
---|
[9987] | 768 | |
---|
[10020] | 769 | bool SpaceShip::systemFailure() |
---|
| 770 | { |
---|
| 771 | return (this->electronicCur < /*this->rand() */ this->electronicTH); //TODO cleanup |
---|
| 772 | } |
---|
| 773 | |
---|
| 774 | |
---|
[9975] | 775 | void SpaceShip::enterPlaymode(Playable::Playmode playmode) |
---|
| 776 | { |
---|
[10017] | 777 | switch(playmode) |
---|
| 778 | { |
---|
| 779 | case Playable::Full3D: |
---|
| 780 | /* |
---|
| 781 | if (State::getCameraNode != NULL) |
---|
| 782 | { |
---|
| 783 | Vector absCoor = this->getAbsCoor(); |
---|
| 784 | this->setParent(PNode::getNullParent()); |
---|
| 785 | this->setAbsCoor(absCoor); |
---|
| 786 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
| 787 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
| 788 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
| 789 | State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); |
---|
| 790 | |
---|
| 791 | } |
---|
| 792 | */ |
---|
| 793 | //break; |
---|
| 794 | |
---|
| 795 | |
---|
| 796 | case Playable::Vertical: |
---|
| 797 | if (State::getCameraNode != NULL) |
---|
| 798 | { |
---|
| 799 | this->debugNode(1); |
---|
| 800 | this->travelNode->debugNode(1); |
---|
| 801 | |
---|
| 802 | this->travelNode->setAbsCoor(this->getAbsCoor()); |
---|
| 803 | this->travelNode->updateNode(0.01f); |
---|
| 804 | |
---|
| 805 | this->setParent(this->travelNode); |
---|
| 806 | this->setRelCoor(0,0,0); |
---|
| 807 | |
---|
| 808 | State::getCameraNode()->setParentSoft(this->travelNode); |
---|
[10019] | 809 | State::getCameraNode()->setRelCoorSoft(-0.01, 40,0); |
---|
[10017] | 810 | State::getCameraTargetNode()->setParentSoft(this->travelNode); |
---|
[10019] | 811 | State::getCameraTargetNode()->setRelCoorSoft(0,0,0); |
---|
[10017] | 812 | |
---|
| 813 | this->debugNode(1); |
---|
| 814 | this->travelNode->debugNode(1); |
---|
| 815 | } |
---|
| 816 | break; |
---|
| 817 | |
---|
| 818 | default: |
---|
| 819 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
| 820 | } |
---|
[10019] | 821 | std::cout << Playable::playmodeToString(this->getPlaymode()); |
---|
[9975] | 822 | } |
---|
| 823 | |
---|
[10017] | 824 | /** |
---|
| 825 | * @brief calculate the velocity |
---|
| 826 | * @param time the timeslice since the last frame |
---|
| 827 | */ |
---|
[9987] | 828 | |
---|
[9975] | 829 | void SpaceShip::movement (float dt) |
---|
| 830 | { |
---|
[10019] | 831 | //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so |
---|
| 832 | //the ship doesn't slide too much. |
---|
| 833 | float airCoeff = 2.5; |
---|
| 834 | |
---|
| 835 | float pi = 3.14; |
---|
| 836 | |
---|
| 837 | // these routines will change the travel movement into zero in a short amout of time, if the player |
---|
| 838 | // doesn't press any buttons. |
---|
| 839 | if (this->velocity.x >= 0) |
---|
| 840 | { |
---|
| 841 | if (this->velocity.x > airCoeff*this->acceleration * dt) |
---|
| 842 | this->velocity.x -= airCoeff* this->acceleration * dt; |
---|
[10017] | 843 | else |
---|
[10019] | 844 | this->velocity.x = 0; |
---|
| 845 | } |
---|
| 846 | else |
---|
| 847 | { |
---|
| 848 | if (this->velocity.x < -airCoeff*this->acceleration * dt) |
---|
| 849 | this->velocity.x += airCoeff* this->acceleration * dt; |
---|
| 850 | else |
---|
| 851 | this->velocity.x = 0; |
---|
| 852 | } |
---|
| 853 | if (this->velocity.z >= 0) |
---|
| 854 | { |
---|
| 855 | if (this->velocity.z > airCoeff*this->acceleration * dt) |
---|
| 856 | this->velocity.z -= airCoeff* this->acceleration * dt; |
---|
| 857 | else |
---|
| 858 | this->velocity.z = 0; |
---|
| 859 | } |
---|
| 860 | else |
---|
| 861 | { |
---|
| 862 | if (this->velocity.z < -airCoeff*this->acceleration * dt) |
---|
| 863 | this->velocity.z += airCoeff* this->acceleration * dt; |
---|
| 864 | else |
---|
| 865 | this->velocity.z = 0; |
---|
| 866 | } |
---|
[10017] | 867 | |
---|
[10019] | 868 | // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons |
---|
| 869 | // and its continuing to slide a bit. |
---|
| 870 | Vector oldCoor = this->getRelCoor(); |
---|
| 871 | if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z); |
---|
| 872 | if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z); |
---|
| 873 | if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y); |
---|
| 874 | if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y); |
---|
| 875 | |
---|
[10020] | 876 | if( this->systemFailure() ) |
---|
| 877 | bForward = bBackward = bLeft = bRight = false; |
---|
| 878 | |
---|
| 879 | |
---|
[10017] | 880 | if( this->bForward ) |
---|
| 881 | { |
---|
[10019] | 882 | if(this->getRelCoor().x < this->travelDistancePlus.x) |
---|
[10017] | 883 | { |
---|
| 884 | if (this->velocity.x < this->travelSpeed) |
---|
| 885 | { |
---|
[10019] | 886 | this->velocity.x += (airCoeff + 1.0)*this->acceleration*dt; |
---|
[10017] | 887 | } |
---|
| 888 | else |
---|
| 889 | { |
---|
| 890 | this->velocity.x = this->travelSpeed; |
---|
| 891 | } |
---|
| 892 | } |
---|
| 893 | else |
---|
| 894 | { |
---|
| 895 | this->velocity.x = 0.0f; |
---|
| 896 | } |
---|
| 897 | } |
---|
| 898 | |
---|
| 899 | if( this->bBackward ) |
---|
| 900 | { |
---|
[10019] | 901 | if(this->getRelCoor().x > this->travelDistanceMinus.x) |
---|
[10017] | 902 | { |
---|
| 903 | if (this->velocity.x > -this->travelSpeed) |
---|
| 904 | { |
---|
[10019] | 905 | this->velocity.x -= (airCoeff + 1.0)*this->acceleration*dt; |
---|
[10017] | 906 | } |
---|
| 907 | else |
---|
| 908 | { |
---|
| 909 | this->velocity.x = -this->travelSpeed; |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | else |
---|
| 913 | { |
---|
| 914 | this->velocity.x = 0.0f; |
---|
| 915 | } |
---|
| 916 | } |
---|
[10019] | 917 | |
---|
[10017] | 918 | if( this->bLeft) |
---|
| 919 | { |
---|
[10019] | 920 | if(this->getRelCoor().z > this->travelDistanceMinus.y) |
---|
| 921 | { |
---|
| 922 | if (this->velocity.z > -this->travelSpeed) |
---|
| 923 | { |
---|
| 924 | this->velocity.z -= (airCoeff + 1.0)*this->acceleration*dt; |
---|
| 925 | } |
---|
| 926 | else |
---|
| 927 | { |
---|
| 928 | this->velocity.z = -this->travelSpeed; |
---|
| 929 | } |
---|
| 930 | } |
---|
| 931 | else |
---|
| 932 | { |
---|
| 933 | this->velocity.z = 0.0f; |
---|
| 934 | } |
---|
[10017] | 935 | } |
---|
| 936 | |
---|
| 937 | if( this->bRight) |
---|
| 938 | { |
---|
[10019] | 939 | if(this->getRelCoor().z < this->travelDistancePlus.y) |
---|
| 940 | { |
---|
| 941 | if (this->velocity.z < this->travelSpeed) |
---|
| 942 | { |
---|
| 943 | this->velocity.z += (airCoeff + 1.0)*this->acceleration*dt; |
---|
| 944 | } |
---|
| 945 | else |
---|
| 946 | { |
---|
| 947 | this->velocity.z = this->travelSpeed; |
---|
| 948 | } |
---|
| 949 | } |
---|
| 950 | else |
---|
| 951 | { |
---|
| 952 | this->velocity.z = 0.0f; |
---|
| 953 | } |
---|
[10017] | 954 | } |
---|
[10019] | 955 | |
---|
| 956 | this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0)); |
---|
| 957 | this->shiftCoor (this->velocity * dt); |
---|
| 958 | |
---|
| 959 | float angle = this->velocity.z / travelSpeed * pi / 3; |
---|
| 960 | if (angle > pi/3) angle = pi/3; |
---|
| 961 | if (angle < -pi/3) angle = -pi/3; |
---|
| 962 | this->setRelDirSoft(Quaternion(angle, Vector(1,0,0)), 5.0f); |
---|
[10017] | 963 | |
---|
[10019] | 964 | /* |
---|
[10017] | 965 | switch(this->getPlaymode()) |
---|
| 966 | { |
---|
| 967 | case Playable::Vertical: |
---|
| 968 | break; |
---|
| 969 | default: |
---|
| 970 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
| 971 | } |
---|
[10019] | 972 | */ |
---|
[9975] | 973 | } |
---|
[10017] | 974 | |
---|