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