Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/particleEffectsHS15/src/modules/weapons/projectiles/MineProjectile2.cc @ 10901

Last change on this file since 10901 was 10901, checked in by holzerj, 8 years ago

Added explosions effects when the mine explodes.

File size: 7.1 KB
Line 
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 MineProjectile.h
31    @brief Implementation of the MineProjectile class.
32*/
33
34#include "MineProjectile.h"
35
36#include "core/CoreIncludes.h"
37#include "graphics/Model.h"
38#include "core/command/Executor.h"
39#include "graphics/ParticleSpawner.h"
40#include "worldentities/pawns/Pawn.h"
41
42namespace orxonox
43{
44    RegisterClass(MineProjectile);
45
46    MineProjectile::MineProjectile(Context* context) : MovableEntity(context), BasicProjectile()
47    {
48        RegisterObject(MineProjectile);
49
50        this->bActive_ = false;
51        this->maxTimeUntilExplosion_ = 10.0f;
52        this->timeUntilActivation_ = 1.0f;
53
54        rings1_ = new MovableEntity(this->getContext());
55        this->attach(rings1_);
56        rings1_->setPosition(Vector3(0.0,0.0,0.0));
57        rings1_->setAngularVelocity(Vector3(0.0,5.0,0.0));
58
59        rings2_ = new MovableEntity(this->getContext());
60        this->attach(rings2_);
61        rings2_->setPosition(Vector3(0.0,0.0,0.0));
62        rings2_->setAngularVelocity(Vector3(0.0,0.0,5.0));
63
64        core_ = new MovableEntity(this->getContext());
65        this->attach(core_);
66        core_->setPosition(Vector3(0.0,0.0,0.0));
67        core_->setAngularVelocity(Vector3(2.5,2.5,0.0));
68
69
70    //MODELS
71        //Core
72        modelCore_ = new Model(this->getContext());
73        modelCore_->setMeshSource("Mine_Core.mesh");
74        modelCore_->setScale(15.0);
75        core_->attach(modelCore_);
76        modelCore_->setPosition(Vector3(0,0,0));
77
78        //1
79        modelRing1_ = new Model(this->getContext());
80        modelRing1_->setMeshSource("Mine_Ring.mesh");
81        modelRing1_->setScale(15.0);
82        rings1_->attach(modelRing1_);
83        modelRing1_->setPosition(Vector3(0,0,0));
84        modelRing1_->yaw(Degree(0));
85        //2
86        modelRing2_ = new Model(this->getContext());
87        modelRing2_->setMeshSource("Mine_Ring.mesh");
88        modelRing2_->setScale(15.0);
89        rings1_->attach(modelRing2_);
90        modelRing2_->setPosition(Vector3(0,0,0));
91        modelRing2_->yaw(Degree(180));
92        //3
93        modelRing3_ = new Model(this->getContext());
94        modelRing3_->setMeshSource("Mine_Ring.mesh");
95        modelRing3_->setScale(15.0);
96        rings2_->attach(modelRing3_);
97        modelRing3_->setPosition(Vector3(0,0,0));
98        modelRing3_->yaw(Degree(90));
99        //4
100        modelRing4_ = new Model(this->getContext());
101        modelRing4_->setMeshSource("Mine_Ring.mesh");
102        modelRing4_->setScale(15.0);
103        rings2_->attach(modelRing4_);
104        modelRing4_->setPosition(Vector3(0,0,0));
105        modelRing4_->yaw(Degree(270));
106
107        // Add effect.
108        emitter_ = new ParticleEmitter(this->getContext());
109        this->attach(emitter_);
110        emitter_->setOrientation(this->getOrientation());
111        emitter_->setSource("Orxonox/mineparticle"); 
112
113        if (GameMode::isMaster())
114        {
115            this->setMass(10.0f);
116            this->setFriction(100.0f);
117            this->enableCollisionCallback();
118            this->setCollisionResponse(false);
119            this->setCollisionType(Dynamic);
120
121            // Create a sphere collision shape and attach it to the projectile.
122            collisionShape_ = new SphereCollisionShape(this->getContext());
123            collisionShape_->setRadius(10.0f);
124            this->attachCollisionShape(collisionShape_);
125
126            // Create a distance trigger and attach it to the projectile.
127            distanceTrigger_ = new DistanceTrigger(this->getContext());
128            this->attach(distanceTrigger_);
129            distanceTrigger_->setPosition(Vector3(0,0,0));
130            distanceTrigger_->setDistance(40.0f);
131            distanceTrigger_->addTarget("Pawn");
132            distanceTrigger_->setStayActive(true);
133        }
134    }
135
136    MineProjectile::~MineProjectile()
137    {
138        /*if (modelCore_ != NULL)
139        {
140            modelCore_->destroy();
141        }*/
142        /*if (distanceTrigger_ != NULL)
143        {
144            distanceTrigger_->destroy();
145        }*/
146    }
147
148    /**
149    @brief
150        TODO
151    */
152    void MineProjectile::setMaxTimeUntilExplosion(float maxTimeUntilExplosion)
153    {
154        if (maxTimeUntilExplosion >= 0)
155        {
156            this->maxTimeUntilExplosion_ = maxTimeUntilExplosion;
157            if (GameMode::isMaster())
158            {
159                this->explodeTimer_.setTimer(this->maxTimeUntilExplosion_, false, createExecutor(createFunctor(&MineProjectile::Explode, this)));
160            }
161        }
162        else
163        {
164            this->maxTimeUntilExplosion_ = 0;
165        }
166    }
167
168    /**
169    @brief
170        TODO
171    */
172    void MineProjectile::setTimeUntilActivation(float timeUntilActivation)
173    {
174        timeUntilActivation_ = timeUntilActivation;
175
176        if (GameMode::isMaster())
177        {
178            this->activationTimer_.setTimer(this->timeUntilActivation_, false, createExecutor(createFunctor(&MineProjectile::Activate, this)));
179        }
180    }
181
182    /**
183    @brief
184        TODO
185    */
186    void MineProjectile::Explode()
187    {
188        orxout() << "MineProjectile::Explode" << endl;
189        destructionEffect();
190
191        this->destroyLater();
192
193
194    }
195
196    /**
197    @brief
198        TODO
199    */
200    void MineProjectile::Activate()
201    {
202        orxout() << "MineProjectile::Activate" << endl;
203
204        bActive_ = true;
205    }
206
207
208    void MineProjectile::destructionEffect()
209    {
210        ParticleSpawner *effect1, *effect2, *effect3;
211       
212            effect1 = new ParticleSpawner(this->getContext());
213            effect2 = new ParticleSpawner(this->getContext());
214            effect3 = new ParticleSpawner(this->getContext());
215
216        effect1->setPosition(this->getPosition());
217        effect1->setOrientation(this->getOrientation());
218        effect1->setDestroyAfterLife(true);
219        effect1->setSource("Orxonox/MineExpl");
220        effect1->setLifetime(2.5f);
221
222        effect2->setPosition(this->getPosition());
223        effect2->setOrientation(this->getOrientation());
224        effect2->setDestroyAfterLife(true);
225        effect2->setSource("Orxonox/MineExpl1");
226        effect2->setLifetime(2.5f);
227
228        effect3->setPosition(this->getPosition());
229        effect3->setOrientation(this->getOrientation());
230        effect3->setDestroyAfterLife(true);
231        effect3->setSource("Orxonox/MineExpl2");
232        effect3->setLifetime(2.5f);
233    }
234}
Note: See TracBrowser for help on using the repository browser.