Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5881


Ignore:
Timestamp:
Oct 5, 2009, 6:28:21 PM (15 years ago)
Author:
rgrieder
Message:

Fixed sound problem in Pong by correcting the assumptions that you will always have sound.

Location:
code/branches/core5/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/modules/pong/PongBall.cc

    r5738 r5881  
    4141    const float PongBall::MAX_REL_Z_VELOCITY = 1.5;
    4242
    43     PongBall::PongBall(BaseObject* creator) : MovableEntity(creator)
     43    PongBall::PongBall(BaseObject* creator)
     44        : MovableEntity(creator)
     45        , sidesound_(NULL)
     46        , batsound_(NULL)
     47        , scoresound_(NULL)
    4448    {
    4549        RegisterObject(PongBall);
     
    5458        this->registerVariables();
    5559
    56         this->sidesound_ = new SoundBase(this);
    57         this->sidesound_->loadFile("sounds/pong_side.wav");
    58 
    59         this->batsound_ = new SoundBase(this);
    60         this->batsound_->loadFile("sounds/pong_bat.wav");
    61 
    62         this->scoresound_ = new SoundBase(this);
    63         this->scoresound_->loadFile("sounds/pong_score.wav");
     60        if (GameMode::playsSound())
     61        {
     62            this->sidesound_ = new SoundBase(this);
     63            this->sidesound_->loadFile("sounds/pong_side.wav");
     64
     65            this->batsound_ = new SoundBase(this);
     66            this->batsound_->loadFile("sounds/pong_bat.wav");
     67
     68            this->scoresound_ = new SoundBase(this);
     69            this->scoresound_->loadFile("sounds/pong_score.wav");
     70        }
     71    }
     72
     73    PongBall::~PongBall()
     74    {
     75        if (this->sidesound_)
     76            delete this->sidesound_;
     77        if (this->batsound_)
     78            delete this->batsound_;
     79        if (this->scoresound_)
     80            delete this->scoresound_;
    6481    }
    6582
     
    87104            {
    88105                velocity.z = -velocity.z;
    89                 this->sidesound_->play();
     106                if (GameMode::playsSound())
     107                    this->sidesound_->play();
    90108
    91109                if (position.z > this->fieldHeight_ / 2)
     
    109127                            velocity.x = -velocity.x;
    110128                            velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    111                             this->batsound_->play();
     129                            if (GameMode::playsSound())
     130                                this->batsound_->play();
    112131                        }
    113132                        else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     
    116135                            {
    117136                                this->getGametype()->playerScored(this->bat_[0]->getPlayer());
    118                                 this->scoresound_->play();
     137                                if (GameMode::playsSound())
     138                                    this->scoresound_->play();
    119139                                return;
    120140                            }
     
    129149                            velocity.x = -velocity.x;
    130150                            velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    131                             this->batsound_->play();
     151                            if (GameMode::playsSound())
     152                                this->batsound_->play();
    132153                        }
    133154                        else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     
    135156                            if (this->getGametype() && this->bat_[1])
    136157                            {
    137                                 this->scoresound_->play();
     158                                if (GameMode::playsSound())
     159                                    this->scoresound_->play();
    138160                                this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    139161                                return;
     
    157179          {
    158180            velocity.z = -velocity.z;
    159             this->sidesound_->play();
     181            if (GameMode::playsSound())
     182                this->sidesound_->play();
    160183
    161184            if (position.z > this->fieldHeight_ / 2)
     
    178201                  position.x = this->fieldWidth_ / 2;
    179202                  velocity.x = -velocity.x;
    180                   this->batsound_->play();
     203                  if (GameMode::playsSound())
     204                    this->batsound_->play();
    181205                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    182206                }
     
    189213                  position.x = -this->fieldWidth_ / 2;
    190214                  velocity.x = -velocity.x;
    191                   this->batsound_->play();
     215                  if (GameMode::playsSound())
     216                    this->batsound_->play();
    192217                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    193218                }
  • code/branches/core5/src/modules/pong/PongBall.h

    r5738 r5881  
    4141        public:
    4242            PongBall(BaseObject* creator);
    43             virtual ~PongBall() {}
     43            virtual ~PongBall();
    4444
    4545            virtual void tick(float dt);
  • code/branches/core5/src/orxonox/sound/SoundManager.cc

    r5878 r5881  
    7373        else
    7474            COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
    75         ThrowException(InitialisationFailed, "Just testing");
    7675
    7776        GameMode::setPlaysSound(true);
Note: See TracChangeset for help on using the changeset viewer.