Permalink
Browse files

[SOUND] Sound reinitialization on each level.

  • Loading branch information...
1 parent d87718f commit cef5ec256f39ab8ebb61250fb1ea446f1df20516 @Mandarancio committed Jun 26, 2012
Showing with 54 additions and 40 deletions.
  1. +9 −9 dynamicgoo.cpp
  2. +22 −12 goo.cpp
  3. +4 −1 introduction.cpp
  4. +5 −5 joint.cpp
  5. +6 −3 level.cpp
  6. +4 −6 level.h
  7. +1 −1 main.cpp
  8. +1 −1 publicclass.cpp
  9. +1 −2 publicclass.h
  10. +1 −0 soundsystem.cpp
View
@@ -42,8 +42,8 @@ DynamicGoo::DynamicGoo(b2World *world, QPoint p, int radius, QObject *parent):
fixDef.userData=this; //assign a copy of the object at the body so during the contact is possible to know the info of the goo
body->CreateFixture(&fixDef); //create the fixture
- body->SetLinearDamping(0.11);//Not sure about this parameter
- body->SetAngularDamping(0.05);
+ body->SetLinearDamping(0.21);//Not sure about this parameter
+ body->SetAngularDamping(0.1);
//set mass
b2MassData mass;
mass.center.SetZero();
@@ -354,8 +354,8 @@ void DynamicGoo::neighborsFound(){
void DynamicGoo::update(){
QList <int > toRemove;
for (int i=0;i<sources.length();i++){
- if (!soundSystem.sourceStatus(sources[i].first)){
- soundSystem.deleteSource(sources[i]);
+ if (!sSystem->sourceStatus(sources[i].first)){
+ sSystem->deleteSource(sources[i]);
toRemove.push_back(i);
}
}
@@ -391,11 +391,11 @@ void DynamicGoo::contactGround(){
if ( !isSleeping() && qAbs(body->GetAngularVelocity())<body->GetLinearVelocity().Length() && prevTarget==NULL&& (target==NULL ||(target!=NULL && (target->getVPosition()-body->GetPosition()).Length()<radius/10 ))){
ALbyte name[100]="resources/sounds/boing.wav";
- QPair<unsigned int,unsigned int> source =soundSystem.createSource(name);
- soundSystem.setPitch(source.first,24.0/float(radius)*60.0/body->GetLinearVelocity().Length());
- soundSystem.setVolume(source.first,body->GetLinearVelocity().Length()/80.0*radius/24.0);
- soundSystem.setPosition(source.first,getPPosition());
- soundSystem.playSource(source.first);
+ QPair<unsigned int,unsigned int> source =sSystem->createSource(name);
+ sSystem->setPitch(source.first,24.0/float(radius)*60.0/body->GetLinearVelocity().Length());
+ sSystem->setVolume(source.first,body->GetLinearVelocity().Length()/80.0*radius/24.0);
+ sSystem->setPosition(source.first,getPPosition());
+ sSystem->playSource(source.first);
sources.push_back(source);
}
onGround=true;
View
34 goo.cpp
@@ -41,7 +41,7 @@ Goo::Goo( int radius, QObject *parent) :
type=NONE;
ALbyte name[100]="resources/sounds/scream.wav";
- scream=soundSystem.createSource(name);
+ scream=sSystem->createSource(name);
}
//Check if is on ground
@@ -102,6 +102,15 @@ void Goo::move(QPoint p){
void Goo::jumpTo(QPoint p){
stopFollow();
+ if (!falling){
+ ALbyte name[100]="resources/sounds/drag.wav";
+ QPair<unsigned int,unsigned int> source =sSystem->createSource(name);
+ sSystem->setPitch(source.first,float(radius)/20.0);
+ sSystem->setVolume(source.first,radius/24.0);
+ sSystem->setPosition(source.first,getPPosition());
+ sSystem->playSource(source.first);
+ sSystem->addSource(source);
+ }
this->dragable=false;
this->moovable=false;
this->falling=true;
@@ -111,6 +120,7 @@ void Goo::jumpTo(QPoint p){
v.y*=25/v.Length();
body->SetAngularVelocity(0);
body->SetLinearVelocity(v);
+
}
@@ -208,12 +218,12 @@ void Goo::drag(){
if (!hasJoint()) {
if (!dragging){
ALbyte name[100]="resources/sounds/drag.wav";
- QPair<unsigned int,unsigned int> source =soundSystem.createSource(name);
- soundSystem.setPitch(source.first,float(radius)/20.0);
- soundSystem.setVolume(source.first,radius/24.0);
- soundSystem.setPosition(source.first,getPPosition());
- soundSystem.playSource(source.first);
- soundSystem.addSource(source);
+ QPair<unsigned int,unsigned int> source =sSystem->createSource(name);
+ sSystem->setPitch(source.first,float(radius)/20.0);
+ sSystem->setVolume(source.first,radius/24.0);
+ sSystem->setPosition(source.first,getPPosition());
+ sSystem->playSource(source.first);
+ sSystem->addSource(source);
}
body->SetActive(false);
}
@@ -272,11 +282,11 @@ void Goo::checkForConnection(Goo *goo){
void Goo::fallDown(){
if (!falling){
-// if (soundSystem.sourceStatus(scream.first)) soundSystem.stopSource(scream.first);
-// soundSystem.setPitch(scream.first,float(radius)/20.0);
-// soundSystem.setVolume(scream.first,radius/24.0);
-// soundSystem.setPosition(scream.first,getPPosition());
-// soundSystem.playSource(scream.first);
+// if (sSystem->sourceStatus(scream.first)) sSystem->stopSource(scream.first);
+// sSystem->setPitch(scream.first,float(radius)/20.0);
+// sSystem->setVolume(scream.first,radius/24.0);
+// sSystem->setPosition(scream.first,getPPosition());
+// sSystem->playSource(scream.first);
}
onGround=false;
falling=true;
View
@@ -19,6 +19,8 @@
Introduction::Introduction(QWidget *parent) :
QWidget(parent),time(0),scale(1.0), translation(QPoint(0,0)),step(1.0/40.0)
{
+ sSystem=new SoundSystem;
+ sSystem->initialize();
if (flag & ONLYTEXT || flag & DEBUG){
qWarning()<<"Loading intro";
}
@@ -46,6 +48,7 @@ Introduction::Introduction(QWidget *parent) :
}
Introduction::~Introduction(){
+ delete sSystem;
delete loader;
for (int i=0;i<goos.length();i++){
delete goos[i];
@@ -124,7 +127,7 @@ void Introduction::resizeEvent(QResizeEvent *e){
rW=e->size().width()/1280.0;
rH=e->size().height()/1024.0;
scale=(rW<rH? rW : rH);
- soundSystem.setCenter(QPoint(e->size().width()*scale/2,e->size().height()*scale/2));
+ sSystem->setCenter(QPoint(e->size().width()*scale/2,e->size().height()*scale/2));
}
void Introduction::keyPressEvent(QKeyEvent *e){
View
@@ -101,12 +101,12 @@ void Joint::status(){
Goo* d=(a->isDragging()? a : b);
ALbyte name[100]="resources/sounds/pop.wav";
- QPair<unsigned int,unsigned int> source =soundSystem.createSource(name);
+ QPair<unsigned int,unsigned int> source =sSystem->createSource(name);
// soundSystem.setPitch(source.first,float(d->getRadius())/24.0);
- soundSystem.setVolume(source.first,0.3*float(d->getRadius())/24.0);
- soundSystem.setPosition(source.first,d->getPPosition());
- soundSystem.addSource(source);
- soundSystem.playSource(source.first);
+ sSystem->setVolume(source.first,0.3*float(d->getRadius())/24.0);
+ sSystem->setPosition(source.first,d->getPPosition());
+ sSystem->addSource(source);
+ sSystem->playSource(source.first);
}
emit destroyJoint(this);
View
@@ -13,7 +13,6 @@
#include "stickygoo.h"
#include "thorn.h"
#include "stickylink.h"
-#include "soundsystem.h"
#include "balloongoo.h"
#include "ropejoint.h"
@@ -32,6 +31,7 @@
QTime itime;
int fps=0;
+
Level::Level(QString level,BackGroundWidget *bg,QWidget *parent) :
QWidget(parent), backGroundWidget(bg)
{
@@ -136,7 +136,9 @@ void Level::initialize()
this->time=0;
-
+ soundSystem=new SoundSystem();
+ soundSystem->initialize();
+ sSystem=soundSystem;
dir.left=false;
dir.right=false;
@@ -192,6 +194,7 @@ void Level::initialize()
}
//Clean function
void Level::clean(){
+ delete soundSystem;
//clear object bodies
backGroundWidget->clear();
for (int i=0;i<objects.length();i++){
@@ -908,7 +911,7 @@ void Level::wheelEvent(QWheelEvent *e){
void Level::resizeEvent(QResizeEvent *e){
menu->setGeometry(QRect(0,0,e->size().width(),e->size().height()));
- soundSystem.setCenter(QPoint(e->size().width()/2,e->size().height()/2));
+ soundSystem->setCenter(QPoint(e->size().width()/2,e->size().height()/2));
}
void Level::destroyJoint(Joint *joint){
View
10 level.h
@@ -27,7 +27,7 @@
#include "svglevelloader.h"
#include "qb2draw.h"
-
+#include "soundsystem.h"
#include "backgroundwidget.h"
@@ -118,15 +118,13 @@ class Level : public QWidget
QB2Draw * debugPainter;
+ //SOUND
+ SoundSystem *soundSystem;
- //METHOD
- //Level
-// void readLevel(QString path); //Function to load the level from file
-// bool parseString(QString string); //Split a line of the file in the two component the tag and the real information
-// bool parseInfo(QString tag,QString info); //Recognize the tag and use the info
+ //METHOD
BackGroundWidget * backGroundWidget; //This is a widget to draw the semi-static ground and background.
//INITIALIZE FUNCTION
View
@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
}
else if (flag & DEBUG) qWarning() << "Game dir exist!";
- soundSystem.initialize();
+ //soundSystem.initialize();
MainWidget w(QRect(50, 50, 1024,800));
w.show();
View
@@ -1,4 +1,4 @@
#include "publicclass.h"
-SoundSystem soundSystem;
float realStep;
+SoundSystem * sSystem;
View
@@ -3,8 +3,7 @@
#include "soundsystem.h"
-extern SoundSystem soundSystem;
extern float realStep;
-
+extern SoundSystem * sSystem;
#endif // PUBLICCLASS_H
View
@@ -58,6 +58,7 @@ QPair<unsigned int,unsigned int> SoundSystem::createSource(ALbyte fileName[]){
alutLoadWAVFile(fileName,&alFormatBuffer, (void **) &alBuffer,(ALsizei *)&alBufferLen, &alFreqBuffer, &alLoop);
alGenSources(1, &alSource);
+
//create buffer
alGenBuffers(1, &alSampleSet);

0 comments on commit cef5ec2

Please sign in to comment.