Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 21, 2013, 11:16:54 PM (10 years ago)
Author:
jo
Message:

presentationHS13 branch merged into trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pong/PongBall.cc

    r9667 r9939  
    4040
    4141#include "PongBat.h"
     42
     43#include "sound/WorldSound.h"
     44#include "core/XMLPort.h"
    4245
    4346namespace orxonox
     
    6669
    6770        this->registerVariables();
     71
     72        //initialize sound
     73        if (GameMode::isMaster())
     74             {
     75                 this->defScoreSound_ = new WorldSound(this->getContext());
     76                 this->defScoreSound_->setVolume(1.0f);
     77                 this->defBatSound_ = new WorldSound(this->getContext());
     78                 this->defBatSound_->setVolume(0.4f);
     79                 this->defBoundarySound_ = new WorldSound(this->getContext());
     80                 this->defBoundarySound_->setVolume(0.5f);
     81             }
     82             else
     83             {
     84                 this->defScoreSound_ = 0;
     85                 this->defBatSound_ = 0;
     86                 this->defBoundarySound_ = 0;
     87             }
    6888    }
    6989
     
    81101            delete[] this->batID_;
    82102        }
     103    }
     104
     105    //xml port for loading sounds
     106    void PongBall::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     107    {
     108        SUPER(PongBall, XMLPort, xmlelement, mode);
     109        XMLPortParam(PongBall, "defScoreSound",  setDefScoreSound,  getDefScoreSound,  xmlelement, mode);
     110        XMLPortParam(PongBall, "defBatSound",  setDefBatSound,  getDefBatSound,  xmlelement, mode);
     111        XMLPortParam(PongBall, "defBoundarySound",  setDefBoundarySound,  getDefBoundarySound,  xmlelement, mode);
    83112    }
    84113
     
    117146        if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
    118147        {
    119             // Its velocity in z-direction is inverted (i.e. it bounces off).
     148            defBoundarySound_->play(); //play boundary sound
     149                // Its velocity in z-direction is inverted (i.e. it bounces off).
    120150            velocity.z = -velocity.z;
    121151            // And its position is set as to not overstep the boundary it has just crossed.
     
    142172                    if (fabs(distance) <= 1) // If the bat is there to parry.
    143173                    {
    144                         // Set the ball to be exactly at the boundary.
     174                        defBatSound_->play(); //play bat sound
     175                        // Set the ball to be exactly at the boundary.
    145176                        position.x = this->fieldWidth_ / 2;
    146177                        // Invert its velocity in x-direction (i.e. it bounces off).
     
    155186                    else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    156187                    {
     188                        defScoreSound_->play();//play score sound
    157189                        if (this->getGametype() && this->bat_[0])
    158190                        {
     
    169201                    if (fabs(distance) <= 1) // If the bat is there to parry.
    170202                    {
    171                         // Set the ball to be exactly at the boundary.
     203                        defBatSound_->play(); //play bat sound
     204                        // Set the ball to be exactly at the boundary.
    172205                        position.x = -this->fieldWidth_ / 2;
    173206                        // Invert its velocity in x-direction (i.e. it bounces off).
     
    182215                    else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    183216                    {
     217                        defScoreSound_->play();//play score sound
    184218                        if (this->getGametype() && this->bat_[1])
    185219                        {
     
    262296            this->bat_[1] = orxonox_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1]));
    263297    }
     298
     299    void PongBall::setDefScoreSound(const std::string &pongSound)
     300    {
     301        if( defScoreSound_ )
     302            defScoreSound_->setSource(pongSound);
     303        else
     304            assert(0); // This should never happen, because soundpointer is only available on master
     305    }
     306
     307    const std::string& PongBall::getDefScoreSound()
     308    {
     309        if( defScoreSound_ )
     310            return defScoreSound_->getSource();
     311        else
     312            assert(0);
     313        return BLANKSTRING;
     314    }
     315
     316    void PongBall::setDefBatSound(const std::string &pongSound)
     317    {
     318        if( defBatSound_ )
     319            defBatSound_->setSource(pongSound);
     320        else
     321            assert(0); // This should never happen, because soundpointer is only available on master
     322    }
     323
     324    const std::string& PongBall::getDefBatSound()
     325    {
     326        if( defBatSound_ )
     327            return defBatSound_->getSource();
     328        else
     329            assert(0);
     330        return BLANKSTRING;
     331    }
     332
     333    void PongBall::setDefBoundarySound(const std::string &pongSound)
     334    {
     335        if( defBoundarySound_ )
     336            defBoundarySound_->setSource(pongSound);
     337        else
     338            assert(0); // This should never happen, because soundpointer is only available on master
     339    }
     340
     341    const std::string& PongBall::getDefBoundarySound()
     342    {
     343        if( defBoundarySound_ )
     344            return defBoundarySound_->getSource();
     345        else
     346            assert(0);
     347        return BLANKSTRING;
     348    }
    264349}
Note: See TracChangeset for help on using the changeset viewer.