Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 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                }
Note: See TracChangeset for help on using the changeset viewer.