[6443] | 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 Grauer |
---|
| 13 | co-programmer: ... |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 18 | |
---|
[9045] | 19 | #include "spacecraft_2d.h" |
---|
[6443] | 20 | |
---|
| 21 | #include "weapons/weapon_manager.h" |
---|
| 22 | #include "weapons/test_gun.h" |
---|
| 23 | #include "weapons/turret.h" |
---|
| 24 | #include "weapons/cannon.h" |
---|
| 25 | |
---|
[7193] | 26 | #include "util/loading/factory.h" |
---|
[9110] | 27 | #include "util/loading/load_param.h" |
---|
[6443] | 28 | #include "key_mapper.h" |
---|
| 29 | #include "state.h" |
---|
| 30 | |
---|
| 31 | #include "graphics_engine.h" |
---|
[7001] | 32 | #include "dot_emitter.h" |
---|
| 33 | #include "sprite_particles.h" |
---|
[6443] | 34 | |
---|
[8362] | 35 | #include "debug.h" |
---|
| 36 | |
---|
[9124] | 37 | #include "script_class.h" |
---|
| 38 | |
---|
| 39 | |
---|
[9045] | 40 | CREATE_FACTORY(Spacecraft2D, CL_SPACECRAFT_2D); |
---|
[6443] | 41 | |
---|
[9124] | 42 | |
---|
| 43 | CREATE_SCRIPTABLE_CLASS(Spacecraft2D, CL_SPACECRAFT_2D, |
---|
| 44 | addMethod("hasPlayer", ExecutorLua0ret<Playable,bool>(&Playable::hasPlayer)) |
---|
| 45 | //Coordinates |
---|
| 46 | ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) |
---|
| 47 | ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) |
---|
| 48 | ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) |
---|
| 49 | ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ)) |
---|
| 50 | ->addMethod("setAirFriction", ExecutorLua1<Spacecraft2D, float>(&Spacecraft2D::setAirFriction)) |
---|
| 51 | ); |
---|
| 52 | |
---|
[9110] | 53 | /** |
---|
| 54 | * destructs the spacecraft_2d, deletes alocated memory |
---|
| 55 | */ |
---|
| 56 | Spacecraft2D::~Spacecraft2D () |
---|
| 57 | { |
---|
| 58 | this->setPlayer(NULL); |
---|
| 59 | delete this->toTravelHeight; |
---|
| 60 | } |
---|
[6443] | 61 | |
---|
| 62 | /** |
---|
[9045] | 63 | * @brief loads a Spacecraft2D information from a specified file. |
---|
| 64 | * @param fileName the name of the File to load the spacecraft_2d from (absolute path) |
---|
[6443] | 65 | */ |
---|
[9045] | 66 | Spacecraft2D::Spacecraft2D(const std::string& fileName) |
---|
[6443] | 67 | { |
---|
| 68 | this->init(); |
---|
| 69 | TiXmlDocument doc(fileName); |
---|
| 70 | |
---|
| 71 | if(!doc.LoadFile()) |
---|
| 72 | { |
---|
[9045] | 73 | PRINTF(2)("Loading file %s failed for Spacecraft2D.\n", fileName.c_str()); |
---|
[6443] | 74 | return; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | this->loadParams(doc.RootElement()); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
[7339] | 81 | * @brief creates a new Spaceship from Xml Data |
---|
[6443] | 82 | * @param root the xml element containing spaceship data |
---|
| 83 | |
---|
| 84 | @todo add more parameters to load |
---|
| 85 | */ |
---|
[9045] | 86 | Spacecraft2D::Spacecraft2D(const TiXmlElement* root) |
---|
[6443] | 87 | { |
---|
| 88 | this->init(); |
---|
| 89 | if (root != NULL) |
---|
| 90 | this->loadParams(root); |
---|
| 91 | |
---|
| 92 | //weapons: |
---|
[9159] | 93 | Weapon* wpRight = dynamic_cast<Weapon*>(Factory::fabricate(CL_LASER_CANNON)); |
---|
[6443] | 94 | wpRight->setName("testGun Right"); |
---|
[9159] | 95 | Weapon* wpLeft = dynamic_cast<Weapon*>(Factory::fabricate(CL_LASER_CANNON)); |
---|
[6443] | 96 | wpLeft->setName("testGun Left"); |
---|
[7126] | 97 | //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_HYPERBLASTER)); |
---|
[6443] | 98 | |
---|
[7126] | 99 | // cannon->setName("BFG"); |
---|
[6443] | 100 | |
---|
| 101 | this->addWeapon(wpLeft, 1, 0); |
---|
| 102 | this->addWeapon(wpRight,1 ,1); |
---|
[7126] | 103 | //this->addWeapon(cannon, 0, 2); |
---|
[6443] | 104 | |
---|
[7337] | 105 | this->getWeaponManager().changeWeaponConfig(1); |
---|
| 106 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6443] | 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | /** |
---|
[9045] | 111 | * @brief initializes a Spacecraft2D |
---|
[6443] | 112 | */ |
---|
[9045] | 113 | void Spacecraft2D::init() |
---|
[6443] | 114 | { |
---|
[6805] | 115 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
[9045] | 116 | this->setClassID(CL_SPACECRAFT_2D, "Spacecraft2D"); |
---|
[6443] | 117 | |
---|
[9110] | 118 | this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal ); |
---|
[7339] | 119 | |
---|
[9046] | 120 | bForward = bBackward = bLeft = bRight = false; |
---|
[6807] | 121 | mouseSensitivity = 0.005; |
---|
[6443] | 122 | |
---|
[6807] | 123 | this->cameraLook = 0.0f; |
---|
| 124 | this->rotation = 0.0f; |
---|
[9159] | 125 | this->acceleration = 20.0f; |
---|
[9124] | 126 | this->airFriction = 0.0f; |
---|
[6799] | 127 | |
---|
[9110] | 128 | |
---|
[7072] | 129 | this->setHealthMax(100); |
---|
| 130 | this->setHealth(100); |
---|
| 131 | |
---|
| 132 | |
---|
[9110] | 133 | /// 2D-MODE |
---|
| 134 | this->toTravelHeight = NULL; |
---|
| 135 | this->travelSpeed = 0.0f; |
---|
| 136 | this->travelNode = new PNode(); |
---|
| 137 | |
---|
[9159] | 138 | this->loadModel("models/ships/mantawing.obj", 5.0f); |
---|
[9110] | 139 | |
---|
[6806] | 140 | // camera - issue |
---|
[9110] | 141 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 142 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
[6880] | 143 | //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); |
---|
[7003] | 144 | //this->cameraNode.setParent(this); |
---|
[6799] | 145 | |
---|
[7001] | 146 | // PARTICLES |
---|
[9046] | 147 | this->burstEmitter = new DotEmitter(200, 5.0, .01); |
---|
| 148 | this->burstEmitter->setParent(this); |
---|
| 149 | this->burstEmitter->setRelCoor(0, -0.7, 0); |
---|
[9110] | 150 | this->burstEmitter->setRelDir(Quaternion(-M_PI, Vector(0,0,1))); |
---|
[9046] | 151 | this->burstEmitter->setName("Spacecraft2D_Burst_emitter_Left"); |
---|
[6803] | 152 | |
---|
[7001] | 153 | this->burstSystem = new SpriteParticles(1000); |
---|
[9046] | 154 | this->burstSystem->addEmitter(this->burstEmitter); |
---|
[7001] | 155 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
| 156 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 157 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
| 158 | this->burstSystem->setRadius(0.0, 1.5); |
---|
| 159 | this->burstSystem->setRadius(0.05, 1.8); |
---|
| 160 | this->burstSystem->setRadius(.5, .8); |
---|
| 161 | this->burstSystem->setRadius(1.0, 0); |
---|
| 162 | this->burstSystem->setColor(0.0, .7,.7,1,.5); |
---|
| 163 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
| 164 | this->burstSystem->setColor(0.5, .5,.5,.8,.3); |
---|
| 165 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
| 166 | |
---|
| 167 | |
---|
[7868] | 168 | //add events to the eventlist of the Playable |
---|
| 169 | this->registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 170 | this->registerEvent(KeyMapper::PEV_BACKWARD); |
---|
| 171 | this->registerEvent(KeyMapper::PEV_LEFT); |
---|
| 172 | this->registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 173 | this->registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 174 | this->registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 175 | this->registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 176 | this->registerEvent(EV_MOUSE_MOTION); |
---|
[6443] | 177 | |
---|
[7337] | 178 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6443] | 179 | |
---|
[6803] | 180 | // WEAPON_MANAGER configuration |
---|
[7337] | 181 | this->getWeaponManager().setSlotCount(5); |
---|
[6803] | 182 | |
---|
[9159] | 183 | this->getWeaponManager().setSlotPosition(0, Vector(1.843, -0.335, 2.029) * 5.0); |
---|
[7337] | 184 | this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6443] | 185 | |
---|
[9159] | 186 | this->getWeaponManager().setSlotPosition(1, Vector(1.843, -0.335, -2.029) * 5.0); |
---|
[7337] | 187 | this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6443] | 188 | |
---|
[7337] | 189 | this->getWeaponManager().setSlotPosition(2, Vector(-1.63, .809, -.003)); |
---|
| 190 | this->getWeaponManager().setSlotCapability(2, WTYPE_HEAVY); |
---|
[6443] | 191 | |
---|
[6803] | 192 | /// TODO: THESE ARE TOO MUCH |
---|
[7337] | 193 | this->getWeaponManager().setSlotPosition(3, Vector(-1.63, .678, -.652)); |
---|
| 194 | this->getWeaponManager().setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0))); |
---|
[6443] | 195 | |
---|
[7337] | 196 | this->getWeaponManager().setSlotPosition(4, Vector(-1.63, .678, .652)); |
---|
| 197 | this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); |
---|
[6443] | 198 | |
---|
[9110] | 199 | this->cameraNode.setRelCoor(1,5,0); |
---|
| 200 | this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); |
---|
| 201 | this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); |
---|
[9045] | 202 | |
---|
[8623] | 203 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
| 204 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
| 205 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 206 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 207 | //registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) ); |
---|
| 208 | registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); |
---|
| 209 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
[9159] | 210 | |
---|
| 211 | |
---|
| 212 | |
---|
[6443] | 213 | } |
---|
| 214 | |
---|
| 215 | /** |
---|
[9045] | 216 | * @brief loads the Settings of a Spacecraft2D from an XML-element. |
---|
[6443] | 217 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 218 | */ |
---|
[9045] | 219 | void Spacecraft2D::loadParams(const TiXmlElement* root) |
---|
[6443] | 220 | { |
---|
[7348] | 221 | Playable::loadParams(root); |
---|
[9110] | 222 | |
---|
| 223 | LoadParam(root, "travel-speed", this, Spacecraft2D, setTravelSpeed); |
---|
| 224 | LoadParam(root, "travel-height", this, Spacecraft2D, setTravelHeight); |
---|
| 225 | LoadParam(root, "travel-distance", this, Spacecraft2D, setTravelDistance); |
---|
[6443] | 226 | } |
---|
| 227 | |
---|
[9045] | 228 | void Spacecraft2D::setPlayDirection(const Quaternion& rot, float speed) |
---|
[7348] | 229 | { |
---|
| 230 | this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
| 231 | } |
---|
[6443] | 232 | |
---|
[9110] | 233 | void Spacecraft2D::setTravelSpeed(float travelSpeed) |
---|
[9052] | 234 | { |
---|
[9110] | 235 | this->travelSpeed = travelSpeed; |
---|
[9052] | 236 | } |
---|
| 237 | |
---|
[9110] | 238 | |
---|
| 239 | void Spacecraft2D::setTravelHeight(float travelHeight) |
---|
[9052] | 240 | { |
---|
[9110] | 241 | if (this->toTravelHeight == NULL) |
---|
| 242 | this->toTravelHeight = new float; |
---|
| 243 | *this->toTravelHeight = travelHeight; |
---|
[9052] | 244 | } |
---|
| 245 | |
---|
| 246 | |
---|
[9110] | 247 | void Spacecraft2D::setTravelDistance(const Vector2D& distance) |
---|
| 248 | { |
---|
| 249 | this->travelDistance = distance; |
---|
| 250 | } |
---|
[9052] | 251 | |
---|
[9110] | 252 | void Spacecraft2D::setTravelDistance(float x, float y) |
---|
| 253 | { |
---|
| 254 | this->setTravelDistance(Vector2D(x, y)); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | |
---|
[9045] | 259 | void Spacecraft2D::enter() |
---|
[6443] | 260 | { |
---|
[7337] | 261 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
[9110] | 262 | this->setPlaymode(this->getPlaymode()); |
---|
[6443] | 263 | } |
---|
| 264 | |
---|
[9045] | 265 | void Spacecraft2D::leave() |
---|
[6443] | 266 | { |
---|
[7337] | 267 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6443] | 268 | this->detachCamera(); |
---|
| 269 | |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | |
---|
[9110] | 273 | void Spacecraft2D::enterPlaymode(Playable::Playmode playmode) |
---|
| 274 | { |
---|
| 275 | switch(playmode) |
---|
| 276 | { |
---|
| 277 | case Playable::Full3D: |
---|
| 278 | if (State::getCameraNode != NULL) |
---|
| 279 | { |
---|
| 280 | Vector absCoor = this->getAbsCoor(); |
---|
| 281 | this->setParent(PNode::getNullParent()); |
---|
| 282 | this->setAbsCoor(absCoor); |
---|
| 283 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
| 284 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
| 285 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
| 286 | State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); |
---|
| 287 | |
---|
| 288 | } |
---|
| 289 | break; |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | case Playable::Horizontal: |
---|
| 293 | if (State::getCameraNode != NULL) |
---|
| 294 | { |
---|
| 295 | this->debugNode(1); |
---|
| 296 | this->travelNode->debugNode(1); |
---|
| 297 | |
---|
| 298 | this->travelNode->setAbsCoor(this->getAbsCoor()); |
---|
| 299 | this->travelNode->updateNode(0.01f); |
---|
| 300 | |
---|
| 301 | this->setParent(this->travelNode); |
---|
| 302 | this->setRelCoor(0,0,0); |
---|
| 303 | |
---|
| 304 | State::getCameraNode()->setParentSoft(this->travelNode); |
---|
[9149] | 305 | State::getCameraNode()->setRelCoorSoft(-3, 100,0); |
---|
[9110] | 306 | State::getCameraTargetNode()->setParentSoft(this->travelNode); |
---|
[9131] | 307 | State::getCameraTargetNode()->setRelCoorSoft(5,0,1); |
---|
[9110] | 308 | |
---|
| 309 | |
---|
| 310 | this->debugNode(1); |
---|
| 311 | this->travelNode->debugNode(1); |
---|
| 312 | } |
---|
| 313 | break; |
---|
| 314 | |
---|
| 315 | default: |
---|
| 316 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName()); |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | |
---|
[6443] | 322 | /** |
---|
[9045] | 323 | * @brief effect that occurs after the Spacecraft2D is spawned |
---|
[6443] | 324 | */ |
---|
[9045] | 325 | void Spacecraft2D::postSpawn () |
---|
[6443] | 326 | { |
---|
| 327 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | /** |
---|
[9045] | 331 | * @brief the action occuring if the spacecraft_2d left the game |
---|
[6443] | 332 | */ |
---|
[9045] | 333 | void Spacecraft2D::leftWorld () |
---|
[6443] | 334 | {} |
---|
| 335 | |
---|
| 336 | /** |
---|
[7345] | 337 | * @brief this function is called, when two entities collide |
---|
[6443] | 338 | * @param entity: the world entity with whom it collides |
---|
| 339 | * |
---|
| 340 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 341 | */ |
---|
[9045] | 342 | void Spacecraft2D::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[7072] | 343 | { |
---|
| 344 | Playable::collidesWith(entity, location); |
---|
| 345 | } |
---|
[6443] | 346 | |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | /** |
---|
[7345] | 350 | * @brief the function called for each passing timeSnap |
---|
[6443] | 351 | * @param time The timespan passed since last update |
---|
| 352 | */ |
---|
[9045] | 353 | void Spacecraft2D::tick (float dt) |
---|
[6443] | 354 | { |
---|
[7339] | 355 | // this->debugNode(1); |
---|
[6804] | 356 | Playable::tick(dt); |
---|
| 357 | |
---|
[6443] | 358 | // spaceship controlled movement |
---|
[6805] | 359 | this->movement(dt); |
---|
[7001] | 360 | |
---|
| 361 | // TRYING TO FIX PNode. |
---|
[9110] | 362 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
---|
| 363 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
---|
[6443] | 364 | } |
---|
| 365 | |
---|
| 366 | /** |
---|
[7345] | 367 | * @brief calculate the velocity |
---|
[6443] | 368 | * @param time the timeslice since the last frame |
---|
| 369 | */ |
---|
[9045] | 370 | void Spacecraft2D::movement (float dt) |
---|
[6443] | 371 | { |
---|
| 372 | Vector accel(0.0, 0.0, 0.0); |
---|
| 373 | |
---|
[6814] | 374 | if( this->bForward ) |
---|
| 375 | { |
---|
[6879] | 376 | accel += Vector(this->acceleration, 0, 0); |
---|
[6443] | 377 | } |
---|
| 378 | |
---|
[6814] | 379 | if( this->bBackward ) |
---|
| 380 | { |
---|
[6879] | 381 | accel -= Vector(this->acceleration, 0, 0); |
---|
[6443] | 382 | } |
---|
[6814] | 383 | if( this->bLeft) |
---|
| 384 | { |
---|
[6879] | 385 | accel -= Vector(0, 0, this->acceleration); |
---|
[6443] | 386 | } |
---|
[6807] | 387 | |
---|
[6814] | 388 | if( this->bRight) |
---|
| 389 | { |
---|
[6879] | 390 | accel += Vector(0, 0, this->acceleration); |
---|
[6443] | 391 | } |
---|
| 392 | |
---|
[7339] | 393 | switch(this->getPlaymode()) |
---|
| 394 | { |
---|
| 395 | case Playable::Full3D: |
---|
| 396 | { |
---|
| 397 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
[6814] | 398 | |
---|
[7339] | 399 | // this is the air friction (necessary for a smooth control) |
---|
[9110] | 400 | Vector damping = (this->velocity * this->airFriction); |
---|
[6999] | 401 | |
---|
[9110] | 402 | |
---|
| 403 | this->velocity += (accelerationDir - damping)* dt; |
---|
[7339] | 404 | this->shiftCoor (this->velocity * dt); |
---|
[6879] | 405 | |
---|
[7339] | 406 | // limit the maximum rotation speed. |
---|
| 407 | if (this->rotation != 0.0f) |
---|
| 408 | { |
---|
| 409 | float maxRot = 10.0 * dt; |
---|
| 410 | if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; |
---|
| 411 | if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; |
---|
| 412 | this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); |
---|
[7326] | 413 | |
---|
[7339] | 414 | this->rotation = 0.0f; |
---|
| 415 | } |
---|
[7326] | 416 | |
---|
[7339] | 417 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
| 418 | } |
---|
| 419 | break; |
---|
| 420 | |
---|
| 421 | case Playable::Horizontal: |
---|
| 422 | { |
---|
[9110] | 423 | |
---|
| 424 | if (this->toTravelHeight != NULL) |
---|
| 425 | { |
---|
| 426 | this->travelNode->shiftCoor(Vector(0, (*toTravelHeight - this->travelNode->getAbsCoor().y) * dt, 0)); |
---|
| 427 | if (fabsf(this->travelNode->getAbsCoor().y - *this->toTravelHeight) < .1) |
---|
| 428 | { |
---|
| 429 | delete this->toTravelHeight; |
---|
| 430 | this->toTravelHeight = NULL; |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | this->travelNode->shiftCoor(Vector(this->travelSpeed * dt, 0, 0)); |
---|
| 434 | |
---|
[7345] | 435 | accel.y = 0.0; |
---|
[9124] | 436 | |
---|
| 437 | |
---|
[7339] | 438 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
[7345] | 439 | accelerationDir.y = 0.0; |
---|
[7339] | 440 | |
---|
[9124] | 441 | |
---|
| 442 | /* |
---|
| 443 | if (this->getRelCoor().z > this->travelDistance.y && accel.z > 0.0) |
---|
| 444 | accel.z = 0.0f; |
---|
| 445 | if (this->getRelCoor().z < -this->travelDistance.y && accel.z < 0.0) |
---|
| 446 | accel.z = 0.0f; |
---|
| 447 | |
---|
| 448 | if (this->getRelCoor().x > this->travelDistance.x && accel.x > 0.0) |
---|
| 449 | accel.x = 0.0f; |
---|
| 450 | if (this->getRelCoor().x < -this->travelDistance.x && accel.x < 0.0) |
---|
| 451 | accel.x = 0.0f;*/ |
---|
| 452 | |
---|
| 453 | |
---|
[7339] | 454 | // this is the air friction (necessary for a smooth control) |
---|
[9110] | 455 | Vector damping = (this->velocity * this->airFriction); |
---|
[7339] | 456 | |
---|
| 457 | |
---|
[9110] | 458 | this->velocity += (accelerationDir - damping)* dt; |
---|
[9124] | 459 | |
---|
[9159] | 460 | if (this->getRelCoor().z > this->travelDistance.y && velocity.z > 0.0) |
---|
[9124] | 461 | this->velocity.z = 0.0f; |
---|
[9159] | 462 | if (this->getRelCoor().z < -this->travelDistance.y && velocity.z < 0.0) |
---|
[9124] | 463 | this->velocity.z = 0.0f; |
---|
| 464 | |
---|
[9159] | 465 | if (this->getRelCoor().x > this->travelDistance.x && velocity.x > 0.0) |
---|
[9124] | 466 | this->velocity.x = 0.0f; |
---|
[9159] | 467 | if (this->getRelCoor().x < -this->travelDistance.x && velocity.x < 0.0) |
---|
[9124] | 468 | this->velocity.x = 0.0f; |
---|
| 469 | |
---|
| 470 | |
---|
[7339] | 471 | this->shiftCoor (this->velocity * dt); |
---|
[9124] | 472 | if (accel.z == 0) |
---|
[9159] | 473 | this->setRelDirSoft(Quaternion(0, Vector(0,0,0)), 5.0f); |
---|
[9124] | 474 | else |
---|
[9159] | 475 | this->setRelDirSoft(Quaternion(this->velocity.z * .004, Vector(1,0,0)), 4.5f); |
---|
[7339] | 476 | } |
---|
| 477 | break; |
---|
[7346] | 478 | |
---|
[8316] | 479 | default: |
---|
[9110] | 480 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName()); |
---|
[7339] | 481 | } |
---|
[6443] | 482 | } |
---|
| 483 | |
---|
| 484 | |
---|
[9045] | 485 | void Spacecraft2D::draw() const |
---|
[6443] | 486 | { |
---|
| 487 | WorldEntity::draw(); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | /** |
---|
| 491 | * @todo switch statement ?? |
---|
| 492 | */ |
---|
[9045] | 493 | void Spacecraft2D::process(const Event &event) |
---|
[6443] | 494 | { |
---|
[6804] | 495 | Playable::process(event); |
---|
[6443] | 496 | |
---|
[6637] | 497 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[6805] | 498 | this->bLeft = event.bPressed; |
---|
[6637] | 499 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[6805] | 500 | this->bRight = event.bPressed; |
---|
[6997] | 501 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[6805] | 502 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 503 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[6805] | 504 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6443] | 505 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 506 | { |
---|
| 507 | |
---|
[9110] | 508 | |
---|
| 509 | |
---|
[9052] | 510 | if (this->getPlaymode() == Playable::Full3D) |
---|
[9110] | 511 | { |
---|
| 512 | float xMouse, yMouse; |
---|
| 513 | xMouse = event.xRel*mouseSensitivity; |
---|
| 514 | yMouse = event.yRel*mouseSensitivity; |
---|
| 515 | |
---|
| 516 | // rotate the Player around the y-axis |
---|
[9052] | 517 | this->rotation += xMouse; |
---|
[6799] | 518 | |
---|
[9110] | 519 | this->cameraLook += yMouse; |
---|
| 520 | // rotate the Camera around the z-axis |
---|
| 521 | if (cameraLook > M_PI_4) |
---|
| 522 | cameraLook = M_PI_4; |
---|
| 523 | else if (cameraLook < -M_PI_4) |
---|
| 524 | cameraLook = -M_PI_4; |
---|
| 525 | //this->cameraNode.setRelDirSoft(this->direction,10); |
---|
| 526 | } |
---|
[6805] | 527 | } |
---|
[6443] | 528 | } |
---|