Changeset 10435 for code/branches/weaponFS15/src/modules/weapons
- Timestamp:
- May 7, 2015, 5:43:36 PM (10 years ago)
- Location:
- code/branches/weaponFS15/src/modules/weapons
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBomb.cc
r10391 r10435 12 12 RegisterClass(GravityBomb); 13 13 14 const float GravityBomb::LIFETIME = 5; 15 14 16 GravityBomb::GravityBomb(Context* context): 15 17 BasicProjectile(), … … 24 26 { 25 27 //Define CollisionType of the bomb 26 this->timeToLife_= 5;28 this->timeToLife_= LIFETIME; 27 29 this->setCollisionResponse(false); 28 30 this->setCollisionType(WorldEntity::Dynamic); … … 35 37 36 38 //Create Bomb Model 37 Model* model = new Model(this->getContext()); 38 model->setMeshSource("rocket.mesh"); //Demo Model from SimpleRocket 39 model->scale(0.7f); 40 this->attach(model); 39 Model* rocketModel = new Model(this->getContext()); 40 rocketModel->setMeshSource("GravityBombRocket.mesh"); //Demo Model from SimpleRocket 41 rocketModel->scale(3.0f); 42 this->attach(rocketModel); 43 44 Model* bombModel = new Model(this->getContext()); 45 bombModel->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket 46 bombModel->scale(3.0f); 47 this->attach(bombModel); 41 48 42 49 } … … 82 89 { 83 90 GravityBombField* field = new GravityBombField(this->getContext()); 91 field->setShooter(this->getShooter()); 84 92 field->setPosition(getPosition()); 85 93 orxout(debug_output) << "detonating. Creating GravityBombField." <<endl; -
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBomb.h
r10391 r10435 65 65 void detonate(); 66 66 private: 67 static const float LIFETIME; 68 67 69 bool isDetonated_; //Used to check whether the Bomb has to be destroyed during next tick. 68 70 float timeToLife_; //Time the bomb flies before it explodes. -
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; -
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.h
r10409 r10435 17 17 #include "GravityBomb.h" 18 18 #include "graphics/ParticleSpawner.h" 19 19 #include "tools/ParticleInterface.h" 20 #include <stdlib.h> 21 #include <time.h> 22 #include "graphics/Backlight.h" 20 23 21 24 namespace orxonox { … … 26 29 virtual void tick(float dt); 27 30 virtual void destroy(); 31 32 void setShooter(Pawn* shooter) 33 { this->shooter_ = shooter; } 34 35 Pawn* getShooter() 36 { return this->shooter_; } 37 28 38 private: 29 39 static const float FORCE_FIELD_LIFETIME; 30 40 static const float FORCE_SPHERE_START_RADIUS; 31 41 static const float FORCE_SPHERE_START_STRENGTH; 42 static const float FORCE_FIELD_EXPLOSION_DAMMAGE; 43 static const float EXPLOSION_DURATION; 44 static const float EXPLOSION_RADIUS; 45 static const float PEAK_ANGULAR_VELOCITY; 46 static const float PEAK_EXPLOSION_FORCE; 32 47 33 48 float forceSphereRadius_; 34 49 float forceStrength_; 35 50 float lifetime_; 51 Vector3 rotationVector_; 36 52 bool fieldExploded_; 37 53 ParticleEmitter * particleSphere_; 38 54 ParticleEmitter * explosionCross_; 55 std::vector<Pawn*> victimsAlreadyDamaged_; 56 MovableEntity * bombModel_; 57 Pawn* shooter_; 39 58 }; 40 59 -
code/branches/weaponFS15/src/modules/weapons/weaponmodes/GravityBombFire.cc
r10391 r10435 19 19 RegisterClass(GravityBombFire); 20 20 21 const float GravityBombFire::BOMB_VELOCITY = 400.0; 22 21 23 GravityBombFire::GravityBombFire(Context* context) : WeaponMode(context) 22 24 { … … 26 28 this->bParallelReload_ = false; 27 29 this->damage_ = 0.0f; 28 this->speed_ = 100.0f;30 this->speed_ = BOMB_VELOCITY; 29 31 30 32 this->setMunitionName("GravityBombMunition"); -
code/branches/weaponFS15/src/modules/weapons/weaponmodes/GravityBombFire.h
r10391 r10435 58 58 private: 59 59 float speed_; //!< The initial speed of the bomb when it is launched. 60 static const float BOMB_VELOCITY; 60 61 }; 61 62 }
Note: See TracChangeset
for help on using the changeset viewer.