1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
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: |
---|
23 | * Fabien Vultier |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file IceGunProjectile.cc |
---|
31 | @brief Implementation of the IceGunProjectile class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "IceGunProjectile.h" |
---|
35 | |
---|
36 | #include <OgreSceneManager.h> |
---|
37 | #include <OgreSceneNode.h> |
---|
38 | |
---|
39 | #include "core/CoreIncludes.h" |
---|
40 | #include "graphics/Model.h" |
---|
41 | #include "graphics/ParticleSpawner.h" |
---|
42 | #include "Scene.h" |
---|
43 | #include "core/command/Executor.h" |
---|
44 | #include "tools/ParticleInterface.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | RegisterClass(IceGunProjectile); |
---|
49 | |
---|
50 | const float IceGunProjectile::particleDestructionDelay_ = 15.0f; |
---|
51 | |
---|
52 | IceGunProjectile::IceGunProjectile(Context* context) : Projectile(context) |
---|
53 | { |
---|
54 | RegisterObject(IceGunProjectile); |
---|
55 | |
---|
56 | this->setCollisionShapeRadius(8.0f); |
---|
57 | |
---|
58 | this->setFreezeTime(3.0); |
---|
59 | this->setFreezeFactor(0.5); |
---|
60 | |
---|
61 | Model* model = new Model(this->getContext()); |
---|
62 | model->setMeshSource("IceBolt.mesh"); |
---|
63 | model->setScale(15.0); |
---|
64 | this->attach(model); |
---|
65 | model->setPosition(Vector3(0,0,0)); |
---|
66 | |
---|
67 | // Add effect. |
---|
68 | spawner_ = new ParticleSpawner(this->getContext()); |
---|
69 | this->attach(spawner_); |
---|
70 | spawner_->setOrientation(this->getOrientation()); |
---|
71 | spawner_->setSource("Orxonox/ice"); |
---|
72 | spawner_->setDeleteWithParent(false); |
---|
73 | spawner_->setDestroydelay(particleDestructionDelay_); |
---|
74 | } |
---|
75 | |
---|
76 | IceGunProjectile::~IceGunProjectile() |
---|
77 | { |
---|
78 | if (this->isInitialized()) |
---|
79 | { |
---|
80 | const Vector3& pos = spawner_->getWorldPosition(); |
---|
81 | const Quaternion& rot = spawner_->getWorldOrientation(); |
---|
82 | this->detach(spawner_); |
---|
83 | spawner_->setPosition(pos); |
---|
84 | spawner_->setOrientation(rot); |
---|
85 | this->getScene()->getRootSceneNode()->addChild(const_cast<Ogre::SceneNode*>(spawner_->getNode())); |
---|
86 | this->spawner_->stop(true); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | @brief |
---|
92 | Sets the freeze time variable to the passed value. |
---|
93 | */ |
---|
94 | void IceGunProjectile::setFreezeTime(float freezeTime) |
---|
95 | { |
---|
96 | freezeTime_ = freezeTime; |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | @brief |
---|
101 | Sets the freeze factor variable to the passed value. |
---|
102 | */ |
---|
103 | void IceGunProjectile::setFreezeFactor(float freezeFactor) |
---|
104 | { |
---|
105 | freezeFactor_ = freezeFactor; |
---|
106 | } |
---|
107 | |
---|
108 | bool IceGunProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
109 | { |
---|
110 | bool bCollision = Projectile::collidesAgainst(otherObject, cs, contactPoint); |
---|
111 | |
---|
112 | if (bCollision) |
---|
113 | { |
---|
114 | // If there was a collision, attach a IceGunFreezer to the hit object. |
---|
115 | IceGunFreezer* freezer = new IceGunFreezer(this->getContext()); |
---|
116 | freezer->setFreezeTime(freezeTime_); |
---|
117 | freezer->setFreezeFactor(freezeFactor_); |
---|
118 | otherObject->attach(freezer); |
---|
119 | |
---|
120 | Vector3 offset = this->getWorldPosition() - otherObject->getWorldPosition(); |
---|
121 | freezer->setPosition(Vector3(0,0,0)); |
---|
122 | freezer->translate(offset, WorldEntity::TransformSpace::World); |
---|
123 | // Start the freezing effect. |
---|
124 | freezer->startFreezing(); |
---|
125 | } |
---|
126 | |
---|
127 | return bCollision; |
---|
128 | } |
---|
129 | } |
---|