[608] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[608] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[670] | 23 | * Fabian 'x3n' Landau |
---|
[608] | 24 | * Co-authors: |
---|
[1293] | 25 | * Benjamin Knecht |
---|
[608] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[786] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 30 | #include "SpaceShip.h" |
---|
[784] | 31 | |
---|
[715] | 32 | #include <string> |
---|
| 33 | |
---|
[708] | 34 | #include <OgreCamera.h> |
---|
| 35 | #include <OgreRenderWindow.h> |
---|
| 36 | #include <OgreParticleSystem.h> |
---|
| 37 | #include <OgreSceneNode.h> |
---|
[608] | 38 | |
---|
[1293] | 39 | #include "CameraHandler.h" |
---|
[1323] | 40 | //#include "util/Convert.h" |
---|
[742] | 41 | #include "util/Math.h" |
---|
[1021] | 42 | #include "core/CoreIncludes.h" |
---|
[1052] | 43 | #include "core/ConfigValueIncludes.h" |
---|
[1021] | 44 | #include "core/Debug.h" |
---|
[1032] | 45 | #include "GraphicsEngine.h" |
---|
[1024] | 46 | #include "core/InputManager.h" |
---|
[1021] | 47 | #include "particle/ParticleInterface.h" |
---|
[708] | 48 | #include "Projectile.h" |
---|
[871] | 49 | #include "core/XMLPort.h" |
---|
[1052] | 50 | #include "core/ConsoleCommand.h" |
---|
[1293] | 51 | #include "network/Client.h" |
---|
[608] | 52 | |
---|
| 53 | namespace orxonox |
---|
| 54 | { |
---|
[1052] | 55 | ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); |
---|
| 56 | ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); |
---|
| 57 | ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); |
---|
| 58 | ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); |
---|
| 59 | |
---|
[608] | 60 | CreateFactory(SpaceShip); |
---|
| 61 | |
---|
[1052] | 62 | SpaceShip* SpaceShip::instance_s; |
---|
| 63 | |
---|
[1293] | 64 | SpaceShip::SpaceShip() : |
---|
| 65 | //testvector_(0,0,0), |
---|
| 66 | //bInvertYAxis_(false), |
---|
| 67 | setMouseEventCallback_(false), |
---|
| 68 | bLMousePressed_(false), |
---|
| 69 | bRMousePressed_(false), |
---|
| 70 | camNode_(0), |
---|
| 71 | cam_(0), |
---|
| 72 | camName_("CamNode"), |
---|
| 73 | tt_(0), |
---|
| 74 | redNode_(0), |
---|
| 75 | greenNode_(0), |
---|
| 76 | blinkTime_(0.0f), |
---|
| 77 | chNearNode_(0), |
---|
| 78 | chFarNode_(0), |
---|
| 79 | timeToReload_(0.0f), |
---|
| 80 | //reloadTime_(0.0f), |
---|
| 81 | maxSideAndBackSpeed_(0.0f), |
---|
| 82 | maxSpeed_(0.0f), |
---|
| 83 | maxRotation_(0.0f), |
---|
| 84 | translationAcceleration_(0.0f), |
---|
| 85 | rotationAcceleration_(0.0f), |
---|
| 86 | translationDamping_(0.0f), |
---|
| 87 | rotationDamping_(0.0f), |
---|
| 88 | maxRotationRadian_(0), |
---|
| 89 | rotationAccelerationRadian_(0), |
---|
| 90 | rotationDampingRadian_(0), |
---|
| 91 | zeroRadian_(0), |
---|
| 92 | mouseXRotation_(0), |
---|
| 93 | mouseYRotation_(0), |
---|
| 94 | mouseX_(0.0f), |
---|
| 95 | mouseY_(0.0f), |
---|
| 96 | emitterRate_(0.0f), |
---|
| 97 | server_(false) |
---|
[608] | 98 | { |
---|
| 99 | RegisterObject(SpaceShip); |
---|
[1021] | 100 | this->registerAllVariables(); |
---|
[608] | 101 | |
---|
[1052] | 102 | SpaceShip::instance_s = this; |
---|
| 103 | |
---|
[697] | 104 | this->setConfigValues(); |
---|
[608] | 105 | |
---|
| 106 | |
---|
[647] | 107 | this->setRotationAxis(1, 0, 0); |
---|
| 108 | this->setStatic(false); |
---|
[608] | 109 | |
---|
| 110 | COUT(3) << "Info: SpaceShip was loaded" << std::endl; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | SpaceShip::~SpaceShip() |
---|
| 114 | { |
---|
[647] | 115 | if (this->tt_) |
---|
| 116 | delete this->tt_; |
---|
[1293] | 117 | if(setMouseEventCallback_) |
---|
| 118 | InputManager::removeMouseHandler("SpaceShip"); |
---|
| 119 | if (this->cam_) |
---|
| 120 | delete this->cam_; |
---|
[608] | 121 | } |
---|
| 122 | |
---|
[1021] | 123 | bool SpaceShip::create(){ |
---|
| 124 | if(Model::create()) |
---|
| 125 | this->init(); |
---|
| 126 | else |
---|
| 127 | return false; |
---|
| 128 | return true; |
---|
| 129 | } |
---|
[1056] | 130 | |
---|
[1021] | 131 | void SpaceShip::registerAllVariables(){ |
---|
[1293] | 132 | registerVar( &camName_, camName_.length()+1, network::STRING, 0x1); |
---|
| 133 | registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); |
---|
| 134 | registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); |
---|
| 135 | registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); |
---|
| 136 | registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); |
---|
| 137 | registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); |
---|
| 138 | registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); |
---|
| 139 | registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); |
---|
| 140 | registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); |
---|
| 141 | registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); |
---|
[1056] | 142 | |
---|
[1021] | 143 | } |
---|
[1056] | 144 | |
---|
[871] | 145 | void SpaceShip::init() |
---|
[697] | 146 | { |
---|
[1293] | 147 | if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) )) |
---|
| 148 | { |
---|
| 149 | if (!setMouseEventCallback_) |
---|
| 150 | { |
---|
| 151 | InputManager::addMouseHandler(this, "SpaceShip"); |
---|
| 152 | setMouseEventCallback_ = true; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
[633] | 156 | // START CREATING THRUSTER |
---|
[1032] | 157 | this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); |
---|
[647] | 158 | this->tt_->getParticleSystem()->setParameter("local_space","true"); |
---|
[978] | 159 | this->tt_->newEmitter(); |
---|
[608] | 160 | /* |
---|
[647] | 161 | this->tt_->setDirection(Vector3(0,0,1)); |
---|
| 162 | this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); |
---|
| 163 | this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); |
---|
[608] | 164 | */ |
---|
[647] | 165 | this->tt_->setDirection(Vector3(-1,0,0)); |
---|
[978] | 166 | this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); |
---|
| 167 | this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); |
---|
[647] | 168 | this->tt_->setVelocity(50); |
---|
[608] | 169 | |
---|
[633] | 170 | emitterRate_ = tt_->getRate(); |
---|
[626] | 171 | |
---|
[633] | 172 | Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); |
---|
| 173 | node2->setInheritScale(false); |
---|
| 174 | tt_->addToSceneNode(node2); |
---|
| 175 | // END CREATING THRUSTER |
---|
[608] | 176 | |
---|
[633] | 177 | // START CREATING BLINKING LIGHTS |
---|
| 178 | this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); |
---|
| 179 | this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); |
---|
[608] | 180 | |
---|
[1293] | 181 | this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3)); |
---|
[633] | 182 | this->redNode_->setInheritScale(false); |
---|
[1293] | 183 | this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3)); |
---|
[633] | 184 | this->greenNode_->setInheritScale(false); |
---|
[608] | 185 | |
---|
[633] | 186 | this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); |
---|
| 187 | this->redNode_->setScale(0.3, 0.3, 0.3); |
---|
[608] | 188 | |
---|
[633] | 189 | this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); |
---|
| 190 | this->greenNode_->setScale(0.3, 0.3, 0.3); |
---|
| 191 | // END CREATING BLINKING LIGHTS |
---|
[608] | 192 | |
---|
[661] | 193 | // START of testing crosshair |
---|
| 194 | this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
| 195 | this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
[608] | 196 | |
---|
[661] | 197 | this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); |
---|
| 198 | this->chNearNode_->setInheritScale(false); |
---|
| 199 | this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); |
---|
| 200 | this->chFarNode_->setInheritScale(false); |
---|
| 201 | |
---|
| 202 | this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); |
---|
| 203 | this->chNearNode_->setScale(0.2, 0.2, 0.2); |
---|
| 204 | |
---|
| 205 | this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); |
---|
| 206 | this->chFarNode_->setScale(0.4, 0.4, 0.4); |
---|
| 207 | |
---|
[1293] | 208 | createCamera(); |
---|
[661] | 209 | // END of testing crosshair |
---|
[871] | 210 | } |
---|
[661] | 211 | |
---|
[871] | 212 | void SpaceShip::setConfigValues() |
---|
| 213 | { |
---|
| 214 | SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); |
---|
| 215 | SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds"); |
---|
| 216 | SetConfigValue(testvector_, Vector3()).description("asdfblah"); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | void SpaceShip::setCamera(const std::string& camera) |
---|
| 220 | { |
---|
[1293] | 221 | camName_=camera; |
---|
| 222 | // change camera attributes here, if you want to ;) |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | void SpaceShip::getFocus(){ |
---|
| 226 | COUT(4) << "requesting focus" << std::endl; |
---|
| 227 | if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID) |
---|
| 228 | CameraHandler::getInstance()->requestFocus(cam_); |
---|
| 229 | |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | void SpaceShip::createCamera(){ |
---|
| 233 | // COUT(4) << "begin camera creation" << std::endl; |
---|
| 234 | this->camNode_ = this->getNode()->createChildSceneNode(camName_); |
---|
| 235 | COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; |
---|
| 236 | this->camNode_->setPosition(Vector3(-50,0,10)); |
---|
| 237 | Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); |
---|
| 238 | Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); |
---|
| 239 | camNode_->setOrientation(q1*q2); |
---|
| 240 | COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; |
---|
| 241 | cam_ = new Camera(this->camNode_); |
---|
[608] | 242 | |
---|
[1293] | 243 | cam_->setTargetNode(this->getNode()); |
---|
[871] | 244 | // cam->setPosition(Vector3(0,-350,0)); |
---|
[1293] | 245 | if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ |
---|
| 246 | this->setBacksync(true); |
---|
| 247 | CameraHandler::getInstance()->requestFocus(cam_); |
---|
| 248 | } |
---|
[608] | 249 | |
---|
| 250 | } |
---|
| 251 | |
---|
[871] | 252 | void SpaceShip::setMaxSpeed(float value) |
---|
| 253 | { this->maxSpeed_ = value; } |
---|
| 254 | void SpaceShip::setMaxSideAndBackSpeed(float value) |
---|
| 255 | { this->maxSideAndBackSpeed_ = value; } |
---|
| 256 | void SpaceShip::setMaxRotation(float value) |
---|
| 257 | { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); } |
---|
| 258 | void SpaceShip::setTransAcc(float value) |
---|
| 259 | { this->translationAcceleration_ = value; } |
---|
| 260 | void SpaceShip::setRotAcc(float value) |
---|
| 261 | { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); } |
---|
| 262 | void SpaceShip::setTransDamp(float value) |
---|
| 263 | { this->translationDamping_ = value; } |
---|
| 264 | void SpaceShip::setRotDamp(float value) |
---|
| 265 | { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); } |
---|
| 266 | |
---|
| 267 | /** |
---|
| 268 | @brief XML loading and saving. |
---|
| 269 | @param xmlelement The XML-element |
---|
| 270 | @param loading Loading (true) or saving (false) |
---|
| 271 | @return The XML-element |
---|
| 272 | */ |
---|
[1052] | 273 | void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[871] | 274 | { |
---|
[1052] | 275 | Model::XMLPort(xmlelement, mode); |
---|
[871] | 276 | |
---|
[1052] | 277 | XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode); |
---|
| 278 | XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode); |
---|
| 279 | XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode); |
---|
| 280 | XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode); |
---|
| 281 | XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode); |
---|
| 282 | XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode); |
---|
| 283 | XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); |
---|
| 284 | XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); |
---|
[1293] | 285 | server_=true; // TODO: this is only a hack |
---|
| 286 | SpaceShip::create(); |
---|
| 287 | getFocus(); |
---|
[871] | 288 | } |
---|
| 289 | |
---|
[647] | 290 | int sgn(float x) |
---|
| 291 | { |
---|
| 292 | if (x >= 0) |
---|
| 293 | return 1; |
---|
| 294 | else |
---|
| 295 | return -1; |
---|
| 296 | } |
---|
| 297 | |
---|
[1340] | 298 | void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) |
---|
[608] | 299 | { |
---|
[647] | 300 | /* |
---|
[608] | 301 | this->mouseX += e.state.X.rel; |
---|
| 302 | if (this->bInvertMouse_) |
---|
| 303 | this->mouseY += e.state.Y.rel; |
---|
| 304 | else |
---|
| 305 | this->mouseY -= e.state.Y.rel; |
---|
| 306 | |
---|
| 307 | // if(mouseX>maxMouseX) maxMouseX = mouseX; |
---|
| 308 | // if(mouseX<minMouseX) minMouseX = mouseX; |
---|
| 309 | // cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; |
---|
| 310 | |
---|
| 311 | this->moved = true; |
---|
[647] | 312 | */ |
---|
[644] | 313 | if (this->bRMousePressed_) |
---|
| 314 | { |
---|
[1323] | 315 | this->camNode_->roll(Degree(-rel.x * 0.10)); |
---|
| 316 | this->camNode_->yaw(Degree(rel.y * 0.10)); |
---|
[644] | 317 | } |
---|
[647] | 318 | else |
---|
| 319 | { |
---|
[1323] | 320 | float minDimension = clippingSize.y; |
---|
| 321 | if (clippingSize.x < minDimension) |
---|
| 322 | minDimension = clippingSize.x; |
---|
[644] | 323 | |
---|
[1323] | 324 | this->mouseX_ += rel.x; |
---|
[647] | 325 | if (this->mouseX_ < -minDimension) |
---|
| 326 | this->mouseX_ = -minDimension; |
---|
| 327 | if (this->mouseX_ > minDimension) |
---|
| 328 | this->mouseX_ = minDimension; |
---|
| 329 | |
---|
[1323] | 330 | this->mouseY_ += rel.y; |
---|
[647] | 331 | if (this->mouseY_ < -minDimension) |
---|
| 332 | this->mouseY_ = -minDimension; |
---|
| 333 | if (this->mouseY_ > minDimension) |
---|
| 334 | this->mouseY_ = minDimension; |
---|
| 335 | |
---|
| 336 | float xRotation = this->mouseX_ / minDimension; |
---|
| 337 | xRotation = xRotation*xRotation * sgn(xRotation); |
---|
| 338 | xRotation *= -this->rotationAcceleration_; |
---|
| 339 | if (xRotation > this->maxRotation_) |
---|
| 340 | xRotation = this->maxRotation_; |
---|
| 341 | if (xRotation < -this->maxRotation_) |
---|
| 342 | xRotation = -this->maxRotation_; |
---|
| 343 | this->mouseXRotation_ = Radian(xRotation); |
---|
| 344 | |
---|
| 345 | float yRotation = this->mouseY_ / minDimension; |
---|
| 346 | yRotation = yRotation*yRotation * sgn(yRotation); |
---|
| 347 | yRotation *= this->rotationAcceleration_; |
---|
| 348 | if (yRotation > this->maxRotation_) |
---|
| 349 | yRotation = this->maxRotation_; |
---|
| 350 | if (yRotation < -this->maxRotation_) |
---|
| 351 | yRotation = -this->maxRotation_; |
---|
| 352 | this->mouseYRotation_ = Radian(yRotation); |
---|
| 353 | } |
---|
[608] | 354 | } |
---|
| 355 | |
---|
[1340] | 356 | void SpaceShip::mouseButtonPressed(MouseButton::Enum id) |
---|
[643] | 357 | { |
---|
[1293] | 358 | if (id == MouseButton::Left) |
---|
[644] | 359 | this->bLMousePressed_ = true; |
---|
[1293] | 360 | else if (id == MouseButton::Right) |
---|
[644] | 361 | this->bRMousePressed_ = true; |
---|
[643] | 362 | } |
---|
| 363 | |
---|
[1340] | 364 | void SpaceShip::mouseButtonReleased(MouseButton::Enum id) |
---|
[643] | 365 | { |
---|
[1293] | 366 | if (id == MouseButton::Left) |
---|
[644] | 367 | this->bLMousePressed_ = false; |
---|
[1293] | 368 | else if (id == MouseButton::Right) |
---|
[644] | 369 | { |
---|
| 370 | this->bRMousePressed_ = false; |
---|
| 371 | this->camNode_->resetOrientation(); |
---|
| 372 | } |
---|
[643] | 373 | } |
---|
| 374 | |
---|
[608] | 375 | void SpaceShip::tick(float dt) |
---|
| 376 | { |
---|
[1293] | 377 | if (this->cam_) |
---|
| 378 | this->cam_->tick(dt); |
---|
[608] | 379 | |
---|
[633] | 380 | if (this->redNode_ && this->greenNode_) |
---|
| 381 | { |
---|
| 382 | this->blinkTime_ += dt; |
---|
| 383 | float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0); |
---|
| 384 | float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0); |
---|
| 385 | this->redNode_->setScale(redScale, redScale, redScale); |
---|
| 386 | this->greenNode_->setScale(greenScale, greenScale, greenScale); |
---|
| 387 | } |
---|
| 388 | |
---|
[643] | 389 | if (this->timeToReload_ > 0) |
---|
| 390 | this->timeToReload_ -= dt; |
---|
| 391 | else |
---|
| 392 | this->timeToReload_ = 0; |
---|
| 393 | |
---|
[644] | 394 | if (this->bLMousePressed_ && this->timeToReload_ <= 0) |
---|
[643] | 395 | { |
---|
[1293] | 396 | Projectile *p = new Projectile(this); |
---|
| 397 | p->setBacksync(true); |
---|
[643] | 398 | this->timeToReload_ = this->reloadTime_; |
---|
| 399 | } |
---|
| 400 | |
---|
[608] | 401 | |
---|
[647] | 402 | // ##################################### |
---|
| 403 | // ############# STEERING ############## |
---|
| 404 | // ##################################### |
---|
| 405 | |
---|
| 406 | if (this->velocity_.x > this->maxSpeed_) |
---|
| 407 | this->velocity_.x = this->maxSpeed_; |
---|
| 408 | if (this->velocity_.x < -this->maxSideAndBackSpeed_) |
---|
| 409 | this->velocity_.x = -this->maxSideAndBackSpeed_; |
---|
| 410 | if (this->velocity_.y > this->maxSideAndBackSpeed_) |
---|
| 411 | this->velocity_.y = this->maxSideAndBackSpeed_; |
---|
| 412 | if (this->velocity_.y < -this->maxSideAndBackSpeed_) |
---|
| 413 | this->velocity_.y = -this->maxSideAndBackSpeed_; |
---|
| 414 | if (this->rotationRate_ > this->maxRotationRadian_) |
---|
| 415 | this->rotationRate_ = this->maxRotationRadian_; |
---|
| 416 | if (this->rotationRate_ < -this->maxRotationRadian_) |
---|
| 417 | this->rotationRate_ = -this->maxRotationRadian_; |
---|
| 418 | |
---|
| 419 | if (this->acceleration_.x == 0) |
---|
| 420 | { |
---|
| 421 | if (this->velocity_.x > 0) |
---|
| 422 | { |
---|
| 423 | this->velocity_.x -= (this->translationDamping_ * dt); |
---|
| 424 | if (this->velocity_.x < 0) |
---|
| 425 | this->velocity_.x = 0; |
---|
| 426 | } |
---|
| 427 | else if (this->velocity_.x < 0) |
---|
| 428 | { |
---|
| 429 | this->velocity_.x += (this->translationDamping_ * dt); |
---|
| 430 | if (this->velocity_.x > 0) |
---|
| 431 | this->velocity_.x = 0; |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | if (this->acceleration_.y == 0) |
---|
| 436 | { |
---|
| 437 | if (this->velocity_.y > 0) |
---|
| 438 | { |
---|
| 439 | this->velocity_.y -= (this->translationDamping_ * dt); |
---|
| 440 | if (this->velocity_.y < 0) |
---|
| 441 | this->velocity_.y = 0; |
---|
| 442 | } |
---|
| 443 | else if (this->velocity_.y < 0) |
---|
| 444 | { |
---|
| 445 | this->velocity_.y += (this->translationDamping_ * dt); |
---|
| 446 | if (this->velocity_.y > 0) |
---|
| 447 | this->velocity_.y = 0; |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | if (this->momentum_ == this->zeroRadian_) |
---|
| 452 | { |
---|
| 453 | if (this->rotationRate_ > this->zeroRadian_) |
---|
| 454 | { |
---|
| 455 | this->rotationRate_ -= (this->rotationDampingRadian_ * dt); |
---|
| 456 | if (this->rotationRate_ < this->zeroRadian_) |
---|
| 457 | this->rotationRate_ = 0; |
---|
| 458 | } |
---|
| 459 | else if (this->rotationRate_ < this->zeroRadian_) |
---|
| 460 | { |
---|
| 461 | this->rotationRate_ += (this->rotationDampingRadian_ * dt); |
---|
| 462 | if (this->rotationRate_ > this->zeroRadian_) |
---|
| 463 | this->rotationRate_ = 0; |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | |
---|
[1293] | 467 | if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ ) |
---|
| 468 | { |
---|
| 469 | COUT(4) << "steering our ship: " << objectID << std::endl; |
---|
| 470 | if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W)) |
---|
[647] | 471 | this->acceleration_.x = this->translationAcceleration_; |
---|
[1293] | 472 | else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S)) |
---|
[647] | 473 | this->acceleration_.x = -this->translationAcceleration_; |
---|
[1293] | 474 | else |
---|
[647] | 475 | this->acceleration_.x = 0; |
---|
| 476 | |
---|
[1293] | 477 | if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D)) |
---|
[647] | 478 | this->acceleration_.y = -this->translationAcceleration_; |
---|
[1293] | 479 | else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A)) |
---|
[647] | 480 | this->acceleration_.y = this->translationAcceleration_; |
---|
[1293] | 481 | else |
---|
[647] | 482 | this->acceleration_.y = 0; |
---|
| 483 | |
---|
[1293] | 484 | if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q)) |
---|
[647] | 485 | this->momentum_ = Radian(-this->rotationAccelerationRadian_); |
---|
[1293] | 486 | else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E)) |
---|
[647] | 487 | this->momentum_ = Radian(this->rotationAccelerationRadian_); |
---|
[1293] | 488 | else |
---|
[647] | 489 | this->momentum_ = 0; |
---|
[1293] | 490 | }/*else |
---|
| 491 | COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ |
---|
[647] | 492 | |
---|
| 493 | WorldEntity::tick(dt); |
---|
| 494 | |
---|
| 495 | this->roll(this->mouseXRotation_ * dt); |
---|
| 496 | if (this->bInvertYAxis_) |
---|
| 497 | this->yaw(Radian(-this->mouseYRotation_ * dt)); |
---|
| 498 | else |
---|
| 499 | this->yaw(Radian(this->mouseYRotation_ * dt)); |
---|
| 500 | |
---|
| 501 | if (this->acceleration_.x > 0) |
---|
| 502 | this->tt_->setRate(emitterRate_); |
---|
| 503 | else |
---|
| 504 | this->tt_->setRate(0); |
---|
[608] | 505 | } |
---|
| 506 | |
---|
| 507 | } |
---|