[Orxonox-commit 576] r3108 - in trunk/src/orxonox: objects/worldentities sound
erwin at orxonox.net
erwin at orxonox.net
Fri May 29 00:46:24 CEST 2009
Author: erwin
Date: 2009-05-29 00:46:24 +0200 (Fri, 29 May 2009)
New Revision: 3108
Modified:
trunk/src/orxonox/objects/worldentities/PongBall.cc
trunk/src/orxonox/objects/worldentities/PongBall.h
trunk/src/orxonox/sound/SoundBase.cc
trunk/src/orxonox/sound/SoundManager.cc
Log:
first attempt to implement sounds for pong, only score sound is working here
Modified: trunk/src/orxonox/objects/worldentities/PongBall.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/PongBall.cc 2009-05-28 21:47:22 UTC (rev 3107)
+++ trunk/src/orxonox/objects/worldentities/PongBall.cc 2009-05-28 22:46:24 UTC (rev 3108)
@@ -32,6 +32,7 @@
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
#include "objects/gametypes/Gametype.h"
+#include "sound/SoundBase.h"
namespace orxonox
{
@@ -49,10 +50,19 @@
this->batID_[0] = OBJECTID_UNKNOWN;
this->batID_[1] = OBJECTID_UNKNOWN;
this->relMercyOffset_ = 0.05;
-
+
this->registerVariables();
+
+ this->sidesound_ = new SoundBase(this);
+ this->sidesound_->loadFile("sounds/pong_side.wav");
+
+ this->batsound_ = new SoundBase(this);
+ this->batsound_->loadFile("sounds/pong_bat.wav");
+
+ this->scoresound_ = new SoundBase(this);
+ this->scoresound_->loadFile("sounds/pong_score.wav");
}
-
+
void PongBall::registerVariables()
{
registerVariable( this->fieldWidth_ );
@@ -76,6 +86,7 @@
if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
{
velocity.z = -velocity.z;
+ this->sidesound_->play();
if (position.z > this->fieldHeight_ / 2)
position.z = this->fieldHeight_ / 2;
@@ -97,12 +108,14 @@
position.x = this->fieldWidth_ / 2;
velocity.x = -velocity.x;
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
+ this->batsound_->play();
}
else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
{
if (this->getGametype() && this->bat_[0])
{
this->getGametype()->playerScored(this->bat_[0]->getPlayer());
+ this->scoresound_->play();
return;
}
}
@@ -115,11 +128,13 @@
position.x = -this->fieldWidth_ / 2;
velocity.x = -velocity.x;
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
+ this->batsound_->play();
}
else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
{
if (this->getGametype() && this->bat_[1])
{
+ this->scoresound_->play();
this->getGametype()->playerScored(this->bat_[1]->getPlayer());
return;
}
@@ -141,6 +156,7 @@
if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
{
velocity.z = -velocity.z;
+ this->sidesound_->play();
if (position.z > this->fieldHeight_ / 2)
position.z = this->fieldHeight_ / 2;
@@ -161,6 +177,7 @@
{
position.x = this->fieldWidth_ / 2;
velocity.x = -velocity.x;
+ this->batsound_->play();
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
}
}
@@ -171,6 +188,7 @@
{
position.x = -this->fieldWidth_ / 2;
velocity.x = -velocity.x;
+ this->batsound_->play();
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
}
}
Modified: trunk/src/orxonox/objects/worldentities/PongBall.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/PongBall.h 2009-05-28 21:47:22 UTC (rev 3107)
+++ trunk/src/orxonox/objects/worldentities/PongBall.h 2009-05-28 22:46:24 UTC (rev 3108)
@@ -43,7 +43,7 @@
virtual ~PongBall() {}
virtual void tick(float dt);
-
+
void registerVariables();
void setFieldDimension(float width, float height)
@@ -64,7 +64,7 @@
void setBats(PongBat** bats)
{ this->bat_ = bats; this->batID_[0] = this->bat_[0]->getObjectID(); this->batID_[1] = this->bat_[1]->getObjectID(); }
-
+
void applyBats()
{ if(!this->bat_) this->bat_ = new PongBat*[2]; if(this->batID_[0] != OBJECTID_UNKNOWN) this->bat_[0] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0])); if(this->batID_[1] != OBJECTID_UNKNOWN) this->bat_[1] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1])); }
@@ -78,6 +78,10 @@
PongBat** bat_;
unsigned int* batID_;
float relMercyOffset_;
+
+ SoundBase* sidesound_;
+ SoundBase* batsound_;
+ SoundBase* scoresound_;
};
}
Modified: trunk/src/orxonox/sound/SoundBase.cc
===================================================================
--- trunk/src/orxonox/sound/SoundBase.cc 2009-05-28 21:47:22 UTC (rev 3107)
+++ trunk/src/orxonox/sound/SoundBase.cc 2009-05-28 22:46:24 UTC (rev 3108)
@@ -96,6 +96,11 @@
else
alSourcei(this->source_, AL_LOOPING, AL_FALSE);
alSourcePlay(this->source_);
+
+ if(alGetError() != AL_NO_ERROR)
+ {
+ COUT(2) << "Sound: OpenAL: Error playin sound " << this->source_ << std::endl;
+ }
}
}
@@ -160,7 +165,6 @@
alGenSources(1, &this->source_);
alSourcei(this->source_, AL_BUFFER, this->buffer_);
-// ALenum
if(alGetError() != AL_NO_ERROR) {
COUT(2) << "Sound: OpenAL: Error loading sample file: " << filename << std::endl;
return false;
Modified: trunk/src/orxonox/sound/SoundManager.cc
===================================================================
--- trunk/src/orxonox/sound/SoundManager.cc 2009-05-28 21:47:22 UTC (rev 3107)
+++ trunk/src/orxonox/sound/SoundManager.cc 2009-05-28 22:46:24 UTC (rev 3108)
@@ -51,12 +51,6 @@
}
else
{
- COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
- const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
- if (str == NULL)
- COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
- else
- COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
if(SoundManager::device_s == NULL)
{
COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
@@ -81,6 +75,13 @@
{
if(alcMakeContextCurrent(this->context_) == AL_TRUE)
COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl;
+
+ COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
+ const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
+ if (str == NULL)
+ COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
+ else
+ COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
}
}
}
More information about the Orxonox-commit
mailing list