- Timestamp:
- May 7, 2015, 5:43:36 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.cc
r10409 r10435 15 15 const float GravityBombField::FORCE_SPHERE_START_RADIUS = 250; 16 16 const float GravityBombField::FORCE_SPHERE_START_STRENGTH = -500; 17 const float GravityBombField::PEAK_EXPLOSION_FORCE = 1e6; 18 const float GravityBombField::FORCE_FIELD_EXPLOSION_DAMMAGE = 100; 19 const float GravityBombField::EXPLOSION_DURATION = 1; 20 const float GravityBombField::EXPLOSION_RADIUS = 400; 21 const float GravityBombField::PEAK_ANGULAR_VELOCITY = 20; 17 22 18 23 GravityBombField::GravityBombField(Context* context) : ForceField(context),RadarViewable(this, static_cast<WorldEntity*>(this)) … … 33 38 this->setRadarObjectScale(0.5f); 34 39 35 //Attach Demo Model for debuging. 36 Model* model = new Model(this->getContext()); 37 model->setMeshSource("rocket.mesh"); //Demo Model from SimpleRocket 38 model->scale(0.7f); 39 this->attach(model); 40 //Attach Model 41 Model* model = new Model(this->getContext()); 42 model->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket 43 model->scale(3.0f); 44 bombModel_ = new MovableEntity(context); 45 bombModel_->attach(model); 46 this->attach(bombModel_); 47 48 Backlight* centreLight = new Backlight(context); 49 centreLight->setColour(ColourValue(0.9,0.5,0.5,1)); 50 centreLight->setScale(1.0); 51 centreLight->setTrailMaterial("Trail/backlighttrail"); 52 centreLight->setMaterial("Examples/Flare"); 53 centreLight->setLifetime(20); 54 bombModel_->attach(centreLight); 55 56 Vector3 randomRotation; 57 srand(time(NULL)); 58 randomRotation.x = rand(); 59 randomRotation.y = rand(); 60 randomRotation.y = rand(); 61 randomRotation.normalise(); 62 bombModel_->setAngularAcceleration(randomRotation*(PEAK_ANGULAR_VELOCITY/FORCE_FIELD_LIFETIME)); 63 64 //Add Collision Shape 65 SphereCollisionShape* collisionShape = new SphereCollisionShape(context); 66 collisionShape->setRadius(3.0); 67 this->attachCollisionShape(collisionShape); 40 68 41 69 this->particleSphere_ = new ParticleEmitter(this->getContext()); 42 70 this->attach(this->particleSphere_); 43 44 71 particleSphere_->setSource("Orxonox/GravityBombField"); 45 72 } … … 51 78 SUPER(GravityBombField,tick,dt); 52 79 lifetime_-=dt; 53 forceStrength_ *= (1+dt/10); 54 if(lifetime_ < 0.2 && !fieldExploded_)80 81 if(lifetime_ > EXPLOSION_DURATION) 55 82 { 56 forceStrength_ *= -2; 57 forceSphereRadius_ *= 2; 58 fieldExploded_ = true; 59 orxout(debug_output) << "Field exploded. Inverting Force." << endl; 83 forceStrength_ *= (1+dt/10); 84 forceSphereRadius_ = FORCE_SPHERE_START_RADIUS*(1-((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)*((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)*((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)); 85 } 86 else if(lifetime_ > 0) 87 { 88 if (!fieldExploded_) 89 { 90 forceStrength_ = PEAK_EXPLOSION_FORCE; 91 fieldExploded_ = true; 92 93 explosionCross_ = new ParticleEmitter(this->getContext()); 94 this->attach(explosionCross_); 95 explosionCross_->setSource("Orxonox/FieldExplosion"); 96 } 97 98 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 99 { 100 Vector3 distanceVector = it->getWorldPosition()-this->getWorldPosition(); 101 orxout(debug_output) << "Found Pawn:" << it->getWorldPosition() << endl; 102 if(distanceVector.length()< forceSphereRadius_) 103 { 104 orxout(debug_output) << "Force sphere radius is: " << forceSphereRadius_ << " Distance to Pawn is: " << distanceVector.length(); 105 if (std::find(victimsAlreadyDamaged_.begin(),victimsAlreadyDamaged_.end(),*it) == victimsAlreadyDamaged_.end()) 106 { 107 orxout(debug_output) << "Found Pawn to damage: " << it->getWorldPosition() << endl; 108 float damage = FORCE_FIELD_EXPLOSION_DAMMAGE*(1-distanceVector.length()/EXPLOSION_RADIUS); 109 orxout(debug_output) << "Damage: " << damage << endl; 110 it->hit(shooter_, it->getWorldPosition(), NULL, damage, 0,0); 111 // it->removeHealth(damage); 112 victimsAlreadyDamaged_.push_back(*it); 113 } 114 } 115 } 116 117 forceSphereRadius_ = EXPLOSION_RADIUS*(1-lifetime_/EXPLOSION_DURATION); 118 explosionCross_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS); 119 } 120 else if (lifetime_ > -4) 121 { 122 bombModel_->setVisible(false); 123 this->setRadarVisibility(false); 124 forceStrength_ = 0; 125 forceSphereRadius_ = 0.00001; 126 particleSphere_->getParticleInterface()->removeAllEmitters(); 127 explosionCross_->getParticleInterface()->removeAllEmitters(); 60 128 } 61 129 62 130 setDiameter(forceSphereRadius_*2); 63 131 setVelocity(forceStrength_); 132 particleSphere_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS); 64 133 65 if (lifetime_ < 0)134 if (lifetime_ <= -4) 66 135 { 67 136 orxout(debug_output) << "Timeout. Destroying field." << endl;
Note: See TracChangeset
for help on using the changeset viewer.