Changeset 6202 for code/branches/presentation2/src/orxonox/items
- Timestamp:
- Dec 2, 2009, 4:52:42 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/items
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
r6187 r6202 41 41 #include "worldentities/EffectContainer.h" 42 42 #include "worldentities/pawns/SpaceShip.h" 43 #include "sound/WorldSound.h" 43 44 44 45 namespace orxonox 45 46 { 46 47 static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20; 48 static const float MAX_VELOCITY_NORMAL = 111; 49 static const float MAX_VELOCITY_BOOST = 221; 47 50 48 51 CreateFactory(MultiStateEngine); … … 51 54 { 52 55 RegisterObject(MultiStateEngine); 56 57 defEngineSndNormal_ = new WorldSound(this); 58 defEngineSndNormal_->setLooping(true); 53 59 54 60 this->lua_ = new LuaState(); … … 66 72 for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2) 67 73 (*it2)->destroy(); 74 delete this->defEngineSndNormal_; 68 75 delete this->lua_; 69 76 } … … 74 81 SUPER(MultiStateEngine, XMLPort, xmlelement, mode); 75 82 XMLPortObject(MultiStateEngine, EffectContainer, "", addEffectContainer, getEffectContainer, xmlelement, mode); 83 XMLPortParam(MultiStateEngine, "defEngineSndNormal", setDefEngSndNormal, getDefEngSndNormal, xmlelement, mode); 76 84 } 77 85 … … 92 100 const Vector3& velocity = this->getShip()->getLocalVelocity(); 93 101 102 float pitch = velocity.length(); 94 103 bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD); 95 104 96 105 int newState = 0; 97 106 if (this->getShip()->getBoost() && forward) 107 { 98 108 newState = Boost; 109 pitch = pitch/MAX_VELOCITY_BOOST + 1; 110 pitch = pitch > 2 ? 2 : pitch; 111 pitch = pitch < 0.5 ? 0.5 : pitch; 112 defEngineSndNormal_->setPitch(pitch); 113 } 99 114 else if (forward && !newState) // newState == Boost 115 { 100 116 newState = Normal; 117 pitch = pitch/MAX_VELOCITY_NORMAL + 1; 118 pitch = pitch > 2 ? 2 : pitch; 119 pitch = pitch < 0.5 ? 0.5 : pitch; 120 defEngineSndNormal_->setPitch(pitch); 121 } 101 122 else if (direction.z > 0 && velocity.z < 0) 102 123 newState = Brake; … … 116 137 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal); 117 138 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 139 if(newState & Normal) 140 { 141 defEngineSndNormal_->play(); 142 } 143 else 144 { 145 defEngineSndNormal_->stop(); 146 } 118 147 } 119 148 if (changes & Brake) … … 150 179 if (!ship) 151 180 return; 181 182 this->getShip()->attach(defEngineSndNormal_); 152 183 153 184 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) … … 179 210 return NULL; 180 211 } 212 213 void MultiStateEngine::setDefEngSndNormal(const std::string &engineSound) 214 { 215 defEngineSndNormal_->setSource(engineSound); 216 } 217 218 const std::string& MultiStateEngine::getDefEngSndNormal() 219 { 220 return defEngineSndNormal_->getSource(); 221 } 181 222 } -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
r6187 r6202 64 64 void addEffectContainer(EffectContainer* effect); 65 65 EffectContainer* getEffectContainer(unsigned int index) const; 66 void setDefEngSndNormal(const std::string& engineSound); 67 const std::string& getDefEngSndNormal(); 66 68 67 69 private: … … 69 71 LuaState* lua_; 70 72 std::vector<EffectContainer*> effectContainers_; 73 WorldSound* defEngineSndNormal_; 71 74 }; 72 75 }
Note: See TracChangeset
for help on using the changeset viewer.