Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 29, 2009, 12:46:24 AM (16 years ago)
Author:
erwin
Message:

first attempt to implement sounds for pong, only score sound is working here

Location:
code/trunk/src/orxonox/objects/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/worldentities/PongBall.cc

    r3084 r3108  
    3333#include "core/GameMode.h"
    3434#include "objects/gametypes/Gametype.h"
     35#include "sound/SoundBase.h"
    3536
    3637namespace orxonox
     
    5051        this->batID_[1] = OBJECTID_UNKNOWN;
    5152        this->relMercyOffset_ = 0.05;
    52        
     53
    5354        this->registerVariables();
    54     }
    55    
     55
     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");
     64    }
     65
    5666    void PongBall::registerVariables()
    5767    {
     
    7787            {
    7888                velocity.z = -velocity.z;
     89                this->sidesound_->play();
    7990
    8091                if (position.z > this->fieldHeight_ / 2)
     
    98109                            velocity.x = -velocity.x;
    99110                            velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     111                            this->batsound_->play();
    100112                        }
    101113                        else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     
    104116                            {
    105117                                this->getGametype()->playerScored(this->bat_[0]->getPlayer());
     118                                this->scoresound_->play();
    106119                                return;
    107120                            }
     
    116129                            velocity.x = -velocity.x;
    117130                            velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     131                            this->batsound_->play();
    118132                        }
    119133                        else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     
    121135                            if (this->getGametype() && this->bat_[1])
    122136                            {
     137                                this->scoresound_->play();
    123138                                this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    124139                                return;
     
    142157          {
    143158            velocity.z = -velocity.z;
     159            this->sidesound_->play();
    144160
    145161            if (position.z > this->fieldHeight_ / 2)
     
    162178                  position.x = this->fieldWidth_ / 2;
    163179                  velocity.x = -velocity.x;
     180                  this->batsound_->play();
    164181                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    165182                }
     
    172189                  position.x = -this->fieldWidth_ / 2;
    173190                  velocity.x = -velocity.x;
     191                  this->batsound_->play();
    174192                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    175193                }
  • code/trunk/src/orxonox/objects/worldentities/PongBall.h

    r3084 r3108  
    4444
    4545            virtual void tick(float dt);
    46            
     46
    4747            void registerVariables();
    4848
     
    6565            void setBats(PongBat** bats)
    6666            { this->bat_ = bats; this->batID_[0] = this->bat_[0]->getObjectID(); this->batID_[1] = this->bat_[1]->getObjectID(); }
    67            
     67
    6868            void applyBats()
    6969            { 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])); }
     
    7979            unsigned int* batID_;
    8080            float relMercyOffset_;
     81
     82            SoundBase* sidesound_;
     83            SoundBase* batsound_;
     84            SoundBase* scoresound_;
    8185    };
    8286}
Note: See TracChangeset for help on using the changeset viewer.