Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 17, 2005, 4:02:36 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/weaponSystem: connecting sounds to the weapon works fine now

Location:
orxonox/branches/weaponSystem/src/world_entities/weapons
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc

    r4882 r4883  
    9696  this->weaponSource->setRolloffFactor(.1);*/
    9797  Projectile* p = new TestBullet(this);
    98 //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
     98
     99  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
    99100  //ObjectManager::getInstance()->debug();
    100101
    101   this->setStateDuration(WS_SHOOTING, 2);
     102  this->setStateDuration(WS_SHOOTING, .2);
    102103
    103104  this->energy = 100;
    104105  this->minCharge = 2;
     106
     107  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
    105108}
    106109
     
    150153{
    151154  this->energyLoaded -= this->minCharge;
     155  if (this->soundBuffers[WA_SHOOT] != NULL)
     156    this->soundSource->play(this->soundBuffers[WA_SHOOT]);
     157
    152158
    153159  Projectile* pj =  new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc

    r4882 r4883  
    5353  for (int i = 0; i < WA_ACTION_COUNT; i++)
    5454    if (this->soundBuffers[i])
    55       delete this->soundBuffers[i];
     55      ResourceManager::getInstance()->unload(this->soundBuffers[i]);
    5656}
    5757
     
    7373
    7474  this->requestedAction = WA_NONE;
    75   this->weaponSource = NULL;
     75  this->soundSource = new SoundSource(this);
    7676
    7777  this->active = true;
     
    8686}
    8787
    88 /**
    89  * sets a new projectile to the weapon
    90  * @param new projectile for this weapon
     88
     89void Weapon::setActionSound(WeaponAction action, const char* soundFile)
     90{
     91  if (action >= WA_ACTION_COUNT)
     92    return;
     93  else
     94  {
     95    this->soundBuffers[action] = (SoundBuffer*)ResourceManager::getInstance()->load(soundFile, WAV);
     96    if (this->soundBuffers[action] != NULL)
     97    {
     98      PRINTF(4)("Loaded sound %s to action %s\n", soundFile, actionToChar(action));
     99    }
     100    else
     101    {
     102      PRINTF(4)("failed to load sound %s to %s\n", soundFile, actionToChar(action));
     103    }
     104
     105  }
     106}
     107
     108/**
     109 * request an action that should be executed,
     110 * @param action the next action to take
    91111 *
    92  * weapon an projectile are independent, so you can combine them as you want
    93 */
    94 void Weapon::setProjectile(Projectile* projectile)
    95 {
    96   this->projectile = projectile;
    97 }
    98 
    99 
    100 /**
    101  * sets a new projectile to the weapon
    102  * @returns the current projectile of this weapon
    103  *
    104  * weapon an projectile are independent, so you can combine them as you want
    105 */
    106 Projectile* Weapon::getProjectile()
    107 {
    108   return this->projectile;
    109 }
    110 
    111 
     112 * This function must be called instead of the actions (like fire/reload...)
     113 * to make all the checks needed to have a usefull WeaponSystem.
     114 */
    112115void Weapon::requestAction(WeaponAction action)
    113116{
     
    187190{
    188191  PRINTF(4)("Activating the Weapon %s\n", this->getName());
     192
     193  if (this->soundBuffers[WA_ACTIVATE] != NULL)
     194    this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
    189195}
    190196
     
    196202{
    197203  PRINTF(4)("Deactivating the Weapon %s\n", this->getName());
     204
     205  if (this->soundBuffers[WA_DEACTIVATE] != NULL)
     206    this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
    198207}
    199208
     
    201210{
    202211  this->energyLoaded -= this->minCharge;
     212
     213  if (this->soundBuffers[WA_SHOOT] != NULL)
     214    this->soundSource->play(this->soundBuffers[WA_SHOOT]);
    203215}
    204216
     
    226238    this->energy -= chargeSize;
    227239  }
     240  if (this->soundBuffers[WA_RELOAD] != NULL)
     241    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
     242
    228243}
    229244
    230245void Weapon::charge()
    231246{
     247  if (this->soundBuffers[WA_CHARGE] != NULL)
     248    this->soundSource->play(this->soundBuffers[WA_CHARGE]);
     249
    232250}
    233251
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h

    r4882 r4883  
    8585
    8686    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
    87     void setProjectile(Projectile* projectile);
    88     Projectile* getProjectile();
     87    /** @param projectile a projectile for this weapon */
     88    void setProjectile(Projectile* projectile) { this->projectile = projectile; };
     89    /** @returns The projectile if availiable */
     90    Projectile* getProjectile() { return this->projectile; };
    8991
    9092    /** @param state the State to time @param duration the duration of the State */
     
    98100    /** @returns the current State of the Weapon */
    99101    inline WeaponState getCurrentState() const { return this->currentState; };
     102    /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
     103    inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
    100104
    101     inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
     105    void setActionSound(WeaponAction action, const char* soundFile);
     106    /** @see void setActionSound(WeaponAction action, const char* soundFile); */
     107    void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); };
    102108
    103109    virtual void destroy();
     
    129135
    130136  protected:
    131     SoundSource*         weaponSource;
     137    SoundSource*         soundSource;
    132138    // it is all about energy
    133139    float                energy;
     
    145151    float                stateDuration;                    //!< how long the state has taken until now.
    146152    float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
     153    Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
    147154    SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
    148     Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
    149155
    150156
Note: See TracChangeset for help on using the changeset viewer.