Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.