Changeset 8855 for code/trunk/src/modules/weapons/projectiles/Rocket.cc
- Timestamp:
- Aug 22, 2011, 3:05:26 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/weapons/projectiles/Rocket.cc
r8738 r8855 27 27 */ 28 28 29 /** 30 @file Rocket.h 31 @brief Implementation of the Rocket class. 32 */ 33 29 34 #include "Rocket.h" 30 35 … … 33 38 #include "core/CoreIncludes.h" 34 39 #include "core/XMLPort.h" 40 41 #include "Scene.h" 42 #include "controllers/Controller.h" 43 #include "graphics/Model.h" 44 #include "graphics/ParticleSpawner.h" 45 #include "infos/PlayerInfo.h" 46 #include "objects/collisionshapes/ConeCollisionShape.h" 47 #include "sound/WorldSound.h" 35 48 #include "worldentities/CameraPosition.h" 36 49 #include "worldentities/pawns/Pawn.h" 37 #include "graphics/ParticleSpawner.h"38 #include "graphics/Model.h"39 #include "objects/collisionshapes/ConeCollisionShape.h"40 #include "infos/PlayerInfo.h"41 #include "controllers/Controller.h"42 #include "sound/WorldSound.h"43 #include "Scene.h"44 50 45 51 namespace orxonox 46 52 { 47 53 CreateFactory(Rocket); 48 // create the factory for the Rocket49 54 50 55 /** … … 57 62 , RadarViewable(creator, static_cast<WorldEntity*>(this)) 58 63 { 59 RegisterObject(Rocket);// - register the Rocket class to the core64 RegisterObject(Rocket);// Register the Rocket class to the core 60 65 61 66 this->localAngularVelocity_ = 0; 62 this->lifetime_ = 100 ;67 this->lifetime_ = 100.0f; 63 68 64 69 if (GameMode::isMaster()) … … 67 72 this->setVelocity(0,0,-100); 68 73 74 // Create rocket model 69 75 Model* model = new Model(this); 70 76 model->setMeshSource("rocket.mesh"); 71 77 model->scale(0.7f); 72 78 this->attach(model); 79 80 // Add effects. 73 81 ParticleEmitter* fire = new ParticleEmitter(this); 74 82 this->attach(fire); … … 80 88 this->setCollisionType(Kinematic); 81 89 90 // Add collision shape 82 91 ConeCollisionShape* collisionShape = new ConeCollisionShape(this); 83 92 collisionShape->setRadius(3); … … 85 94 this->attachCollisionShape(collisionShape); 86 95 87 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this))); 88 96 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this))); 97 98 // Add sound 89 99 this->defSndWpnEngine_ = new WorldSound(this); 90 100 this->defSndWpnEngine_->setLooping(true); … … 105 115 } 106 116 117 // Add camera 107 118 CameraPosition* camPosition = new CameraPosition(this); 108 119 camPosition->setPosition(0,4,15); … … 141 152 /** 142 153 @brief 143 Method for creating a Rocket through XML. 144 */ 145 void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) 146 { 147 // this calls the XMLPort function of the parent class 148 SUPER(Rocket, XMLPort, xmlelement, mode); 149 } 150 151 void Rocket::setOwner(Pawn* owner) 152 { 153 this->owner_ = owner; 154 this->player_ = this->getOwner()->getPlayer(); 155 this->getOwner()->getPlayer()->startTemporaryControl(this); 154 Sets the entity that fired the Rocket. 155 @param shooter 156 A pointer to the Pawn that fired the Rocket. 157 */ 158 void Rocket::setShooter(Pawn* shooter) 159 { 160 this->BasicProjectile::setShooter(shooter); 161 162 this->player_ = this->getShooter()->getPlayer(); 163 this->getShooter()->getPlayer()->startTemporaryControl(this); 156 164 157 165 if( GameMode::isMaster() ) … … 179 187 } 180 188 181 if( GameMode::isMaster() ) 182 { 183 if( this->getBDestroy() ) 184 this->destroy(); 185 186 } 187 } 188 189 /* Calls the collidesAgainst function of BasicProjectile 190 */ 189 this->destroyCheck(); 190 } 191 191 192 bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 192 193 { 193 return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this); 194 } 195 196 void Rocket::destroyObject() 197 { 198 if (GameMode::isMaster()) 199 { 200 if(this->defSndWpnEngine_->isPlaying()) 201 { 202 this->defSndWpnEngine_->stop(); 203 } 204 this->destroy(); 205 } 206 } 207 194 return this->processCollision(otherObject, contactPoint); 195 } 196 197 /** 198 @brief 199 Destroys the Rocket and stops the sound, 200 */ 201 void Rocket::destroyObject(void) 202 { 203 if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying()) 204 this->defSndWpnEngine_->stop(); 205 206 this->BasicProjectile::destroyObject(); 207 } 208 209 /** 210 @brief 211 Destroys the Rocket upon pressing "fire". 212 */ 208 213 void Rocket::fired(unsigned int firemode) 209 214 { 210 this->destroy(); 211 } 212 215 this->destroyObject(); 216 } 217 218 /** 219 @brief 220 The effects that are displayed, when the Rocket is destroyed. 221 */ 213 222 void Rocket::destructionEffect() 214 223 { 215 224 ParticleSpawner *effect1, *effect2; 216 if( this->getOwner())217 { 218 effect1 = new ParticleSpawner(this->get Owner()->getCreator());219 effect2 = new ParticleSpawner(this->get Owner()->getCreator());225 if(this->getShooter()) 226 { 227 effect1 = new ParticleSpawner(this->getShooter()->getCreator()); 228 effect2 = new ParticleSpawner(this->getShooter()->getCreator()); 220 229 } 221 230 else
Note: See TracChangeset
for help on using the changeset viewer.