Changeset 10487 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jan 29, 2007, 11:51:25 PM (18 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/creatures/fps_player.cc
r10452 r10487 73 73 FPSPlayer::FPSPlayer(const TiXmlElement* root) 74 74 { 75 this->init();76 77 75 if (root != NULL) 78 76 this->loadParams(root); 79 77 78 this->updateNode(0.001); 79 this->init(); 80 80 } 81 81 -
trunk/src/world_entities/npcs/mover.cc
r10423 r10487 13 13 co-programmer: 14 14 */ 15 16 #include "sound/resource_sound_buffer.h" 15 17 #include "util/loading/load_param.h" 16 18 #include "util/loading/factory.h" … … 28 30 Mover::Mover(const TiXmlElement* root) 29 31 { 30 this->registerObject(this, Mover::_objectList); 31 this->toList(OM_GROUP_00); 32 33 this->targetCoordinates = Vector(0, 0, 0); 34 this->originCoordinates = Vector(0, 87, -256); 35 this->actionRadius = 40.0; 36 this->actionTime = 1.0; 37 38 if (root != NULL) 39 this->loadParams(root); 40 41 this->updateNode(0.001); 42 this->originCoordinates = this->getAbsCoor(); 43 this->state = Closed; 32 this->registerObject(this, Mover::_objectList); 33 this->toList(OM_COMMON); 34 35 this->targetCoordinates = Vector(0, 0, 0); 36 this->originCoordinates = Vector(0, 87, -256); 37 this->actionRadius = 40.0; 38 this->actionTime = 1.0; 39 40 if (root != NULL) 41 this->loadParams(root); 42 43 this->updateNode(0.001); 44 this->originCoordinates = this->getAbsCoor(); 45 this->state = Closed; 46 47 this->soundSource_starting.setSourceNode(this); 48 this->soundSource_moving.setSourceNode(this); 49 this->soundSource_ending.setSourceNode(this); 50 51 // this->soundSource_starting.setRolloffFactor(0.0); 52 // this->soundSource_moving.setRolloffFactor(0.0); 53 // this->soundSource_ending.setRolloffFactor(0.0); 44 54 } 45 55 46 56 Mover::~Mover() 47 57 { 58 if (this->soundSource_starting.isPlaying()) 59 this->soundSource_starting.stop(); 60 if (this->soundSource_moving.isPlaying()) 61 this->soundSource_moving.stop(); 62 if (this->soundSource_ending.isPlaying()) 63 this->soundSource_ending.stop(); 48 64 } 49 65 … … 54 70 void Mover::loadParams(const TiXmlElement* root) 55 71 { 56 WorldEntity::loadParams(root); 57 58 LoadParam(root, "rel-target-coor", this, Mover, setTargetCoordinates) 59 .describe("sets the relative target coordinates of the door"); 60 LoadParam(root, "action-radius", this, Mover, setActionRadius) 61 .describe("sets the action radius of the door") 62 .defaultValues(40.0); 63 LoadParam(root, "action-time", this, Mover, setActionTime) 64 .describe("sets the action time of the door") 65 .defaultValues(1.0); 72 WorldEntity::loadParams(root); 73 74 LoadParam(root, "rel-target-coor", this, Mover, setTargetCoordinates) 75 .describe("sets the relative target coordinates of the door"); 76 LoadParam(root, "action-radius", this, Mover, setActionRadius) 77 .describe("sets the action radius of the door") 78 .defaultValues(40.0); 79 LoadParam(root, "action-time", this, Mover, setActionTime) 80 .describe("sets the action time of the door") 81 .defaultValues(1.0); 82 LoadParam(root, "opening-sound", this, Mover, setOpeningSoundFile) 83 .describe("Sets the file of the opening sound source"); 84 LoadParam(root, "opened-sound", this, Mover, setOpenedSoundFile) 85 .describe("Sets the file of the opened sound source"); 86 LoadParam(root, "moving-sound", this, Mover, setMovingSoundFile) 87 .describe("Sets the file of the moving sound source"); 88 LoadParam(root, "closing-sound", this, Mover, setClosingSoundFile) 89 .describe("Sets the file of the closing sound source"); 90 LoadParam(root, "closed-sound", this, Mover, setClosedSoundFile) 91 .describe("Sets the file of the closed sound source"); 92 } 93 94 void Mover::setOpeningSoundFile(const std::string& fileName) 95 { 96 this->soundBuffer_opening = OrxSound::ResourceSoundBuffer(fileName); 97 } 98 99 void Mover::setOpenedSoundFile(const std::string& fileName) 100 { 101 this->soundBuffer_opened = OrxSound::ResourceSoundBuffer(fileName); 102 } 103 104 void Mover::setMovingSoundFile(const std::string& fileName) 105 { 106 this->soundBuffer_moving = OrxSound::ResourceSoundBuffer(fileName); 107 } 108 109 void Mover::setClosingSoundFile(const std::string& fileName) 110 { 111 this->soundBuffer_closing = OrxSound::ResourceSoundBuffer(fileName); 112 } 113 114 void Mover::setClosedSoundFile(const std::string& fileName) 115 { 116 this->soundBuffer_closed = OrxSound::ResourceSoundBuffer(fileName); 66 117 } 67 118 … … 76 127 { 77 128 this->state = Opening; 129 if (this->soundBuffer_opening.loaded()) 130 this->soundSource_starting.play(this->soundBuffer_opening); 131 if (this->soundBuffer_moving.loaded()) 132 this->soundSource_moving.play(this->soundBuffer_moving, 1.0, true); 78 133 } 79 134 } … … 84 139 this->state = Open; 85 140 this->setAbsCoor(this->originCoordinates + this->targetCoordinates); 141 if (this->soundBuffer_opened.loaded()) 142 this->soundSource_ending.play(this->soundBuffer_opened); 143 if (this->soundBuffer_moving.loaded()) 144 this->soundSource_moving.stop(); 86 145 } 87 146 } … … 91 150 { 92 151 this->state = Closing; 152 if (this->soundBuffer_closing.loaded()) 153 this->soundSource_starting.play(this->soundBuffer_closing); 154 if (this->soundBuffer_moving.loaded()) 155 this->soundSource_moving.play(this->soundBuffer_moving, 1.0, true); 93 156 } 94 157 } … … 99 162 this->state = Closed; 100 163 this->setAbsCoor(this->originCoordinates); 164 if (this->soundBuffer_closed.loaded()) 165 this->soundSource_ending.play(this->soundBuffer_closed); 166 if (this->soundBuffer_moving.loaded()) 167 this->soundSource_moving.stop(); 101 168 } 102 169 if (this->checkPlayerInActionRadius()) … … 145 212 bool Mover::checkPlayerInActionRadius() 146 213 { 147 148 WorldEntity* entity; 149 Vector vDistance; 150 float powerDistance; 151 152 for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin(); 153 it != Playable::objectList().end(); 154 ++it) 155 // for all players 156 { 157 entity = (*it); 158 159 vDistance = this->originCoordinates - entity->getAbsCoor(); 160 powerDistance = vDistance.x * vDistance.x + vDistance.z * vDistance.z; 161 162 if( powerDistance < (this->actionRadius * this->actionRadius)) 163 return true; 164 } 165 166 167 168 for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin(); 169 it != GenericNPC::objectList().end(); 170 ++it) 171 { 172 entity = (*it); 173 174 vDistance = this->originCoordinates - entity->getAbsCoor(); 175 powerDistance = vDistance.x * vDistance.x + vDistance.z * vDistance.z; 176 177 if( powerDistance < (this->actionRadius * this->actionRadius)) 178 return true; 179 } 180 181 return false; 182 } 214 WorldEntity* entity; 215 float distance; 216 217 for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin(); 218 it != Playable::objectList().end(); 219 ++it) 220 // for all players 221 { 222 entity = (*it); 223 distance = (this->originCoordinates - entity->getAbsCoor()).len(); 224 if (distance < this->actionRadius) 225 { 226 this->soundSource_starting.setSourceNode(entity); // bad hack! 227 this->soundSource_moving.setSourceNode(entity); // TODO: make the sound louder without 228 this->soundSource_ending.setSourceNode(entity); // attaching him to the player 229 return true; 230 } 231 } 232 233 for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin(); 234 it != GenericNPC::objectList().end(); 235 ++it) 236 { 237 entity = (*it); 238 distance = (this->originCoordinates - entity->getAbsCoor()).len(); 239 if (distance < this->actionRadius) 240 return true; 241 } 242 243 return false; 244 } -
trunk/src/world_entities/npcs/mover.h
r10423 r10487 11 11 #include "world_entity.h" 12 12 13 #include "sound_buffer.h" 14 #include "sound_source.h" 15 13 16 //! A Class to handle a Mover 14 17 class Mover : public WorldEntity 15 18 { 16 ObjectListDeclaration(Mover);17 public:18 typedef enum MoverState {19 Closed = 0,20 Opening = 1,21 Open = 2,22 Closing = 3,23 Locked = 424 };19 ObjectListDeclaration(Mover); 20 public: 21 typedef enum MoverState { 22 Closed = 0, 23 Opening = 1, 24 Open = 2, 25 Closing = 3, 26 Locked = 4 27 }; 25 28 26 Mover(const TiXmlElement* root = NULL);27 virtual ~Mover();29 Mover(const TiXmlElement* root = NULL); 30 virtual ~Mover(); 28 31 29 virtual void loadParams(const TiXmlElement* root);32 virtual void loadParams(const TiXmlElement* root); 30 33 31 void setTargetCoordinates(float x, float y, float z) { this->targetCoordinates = Vector(x,y,z); } 32 void setActionRadius(float radius) { this->actionRadius = radius; } 33 void setActionTime(float time) { this->actionTime = time; } 34 void setTargetCoordinates(float x, float y, float z) { this->targetCoordinates = Vector(x,y,z); } 35 void setActionRadius(float radius) { this->actionRadius = radius; } 36 void setActionTime(float time) { this->actionTime = time; } 37 void setOpeningSoundFile(const std::string& fileName); 38 void setOpenedSoundFile(const std::string& fileName); 39 void setMovingSoundFile(const std::string& fileName); 40 void setClosingSoundFile(const std::string& fileName); 41 void setClosedSoundFile(const std::string& fileName); 34 42 35 virtual void tick(float dt);43 virtual void tick(float dt); 36 44 37 private: 38 bool checkOpen(float dt); 39 bool checkClosed(float dt); 40 bool checkPlayerInActionRadius(); 45 private: 46 bool checkOpen(float dt); 47 bool checkClosed(float dt); 48 bool checkPlayerInActionRadius(); 49 50 OrxSound::SoundSource soundSource_starting; 51 OrxSound::SoundSource soundSource_moving; 52 OrxSound::SoundSource soundSource_ending; 53 OrxSound::SoundBuffer soundBuffer_opening; 54 OrxSound::SoundBuffer soundBuffer_opened; 55 OrxSound::SoundBuffer soundBuffer_moving; 56 OrxSound::SoundBuffer soundBuffer_closing; 57 OrxSound::SoundBuffer soundBuffer_closed; 41 58 42 private: 43 Vector targetCoordinates; //!< the target coordinates 44 Vector originCoordinates; //!< the origin coordinates 45 float actionRadius; //!< the action-radius 46 float actionTime; //!< the action-time 47 int state; //!< the state of the mover 59 Vector targetCoordinates; //!< the target coordinates 60 Vector originCoordinates; //!< the origin coordinates 61 float actionRadius; //!< the action-radius 62 float actionTime; //!< the action-time 63 int state; //!< the state of the mover 48 64 }; 49 65
Note: See TracChangeset
for help on using the changeset viewer.