[Orxonox-commit 4768] r9437 - code/branches/soundEffects/src/modules/portals
jo at orxonox.net
jo at orxonox.net
Thu Nov 8 22:58:11 CET 2012
Author: jo
Date: 2012-11-08 22:58:11 +0100 (Thu, 08 Nov 2012)
New Revision: 9437
Modified:
code/branches/soundEffects/src/modules/portals/PortalEndPoint.cc
code/branches/soundEffects/src/modules/portals/PortalEndPoint.h
Log:
Rough example on how to add sound to existing orxonox objects. A Worldsound (sound with phydical location in the level) is played when the player is using a portal. The sound file path has to be adjusted. The current behaviour is that only that portal which is ejecting objects is playing a sound.
Modified: code/branches/soundEffects/src/modules/portals/PortalEndPoint.cc
===================================================================
--- code/branches/soundEffects/src/modules/portals/PortalEndPoint.cc 2012-11-05 15:21:40 UTC (rev 9436)
+++ code/branches/soundEffects/src/modules/portals/PortalEndPoint.cc 2012-11-08 21:58:11 UTC (rev 9437)
@@ -27,6 +27,7 @@
*/
#include "PortalEndPoint.h"
+#include "portals/PortalLink.h"
#include <ctime>
@@ -34,10 +35,9 @@
#include "core/XMLPort.h"
#include "worldentities/MobileEntity.h"
-
#include "objects/triggers/MultiTriggerContainer.h"
-#include "portals/PortalLink.h"
+#include "sound/WorldSound.h"
namespace orxonox
{
@@ -58,12 +58,25 @@
this->setRadarObjectColour(ColourValue::White);
this->setRadarObjectShape(RadarViewable::Dot);
this->setRadarVisibility(true);
+ if( GameMode::isMaster() )
+ {
+ this->portalSound_ = new WorldSound(this);
+ this->portalSound_->setLooping(false);
+ this->attach(this->portalSound_);
+ this->portalSound_->setSource("sounds/Weapon_HsW01.ogg"); //TODO: change sound file
+ }
}
PortalEndPoint::~PortalEndPoint()
{
- if(this->isInitialized() && this->trigger_ != NULL)
- delete this->trigger_;
+ if (this->isInitialized())
+ {
+ if (this->portalSound_ != NULL)
+ this->portalSound_->destroy();
+
+ if (this->trigger_ != NULL)
+ delete this->trigger_;
+ }
}
void PortalEndPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -157,6 +170,11 @@
entity->setPosition(this->getWorldPosition());
entity->rotate(this->getWorldOrientation());
entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
+ //play Sound
+ if( this->portalSound_ && !(this->portalSound_->isPlaying()))
+ {
+ this->portalSound_->play();
+ }
}
}
Modified: code/branches/soundEffects/src/modules/portals/PortalEndPoint.h
===================================================================
--- code/branches/soundEffects/src/modules/portals/PortalEndPoint.h 2012-11-05 15:21:40 UTC (rev 9436)
+++ code/branches/soundEffects/src/modules/portals/PortalEndPoint.h 2012-11-08 21:58:11 UTC (rev 9437)
@@ -114,6 +114,8 @@
int reenterDelay_;
std::map<MobileEntity *, time_t> jumpOutTimes_; //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint
std::set<MobileEntity *> recentlyJumpedOut_; //!< Stores the entities witch recently jumped out of this PortalEndPoint and haven't left the activation radius yet. This is needed in order to prevent them from beeing pulled into the PortalEndPoint they have just come out of.
+
+ WorldSound* portalSound_;
};
}
More information about the Orxonox-commit
mailing list